How to Make a Custom Dialogue UI

Creating Your Own Dialogue UI

The Dialogue System can work with any component that implements the IDialogueUI interface, such as UnityUIDialogueUI and NGUIDialogueUI. This means that, if you already have an existing GUI component, you can add the IDialogueUI interface methods to it. You don't have to create a separate component.

However, it's very easy to create your own dialogue UI component using the provided template. To create your own dialogue UI component:

  1. Copy the template found in Scripts/Templates/TemplateDialogueUI.cs.
  2. Delete the lines containing the text [REMOVE THIS LINE].
  3. Rename the class from TemplateDialogueUI to the name of your dialogue UI.
  4. Implement the methods as described in the comments for each one.

See Scripts/Supplemental/UI/Dialogue UI/UnityUIDialogueUI.cs for the implementation that uses Unity UI.

See Scripts/Third Party Support/NGUI for an implementation that uses NGUI, or Scripts/Third Party Support/Daikon Forge GUI for one that uses Daikon Forge GUI.

Finally, create a game object with your dialogue UI component and assign that game object (or prefab) as described in How to Set Up the Dialogue Manager.


Subclassing An Existing Dialogue UI System

You may find it more convenient to create a subclass of an existing dialogue UI system. This allows you to inherit all of its functionality and simply add or replace your own customizations on top of it.

For example, DaikonForgeDialogueUI is derived from AbstractDialogueUI. All AbstractDialogueUI methods are virtual.

You can create a subclass of DaikonForgeDialogueUI that overrides the ShowResponses method with your additional code. To use it, on your dialogue UI GameObject, drag the new subclass into the Daikon Forge Dialogue UI component's Script field.

Below is an example that includes stubs for extra processing on subtitles as well as response menus:

using UnityEngine;
 
public class ExtendedDaikonForgeDialogueUI : DaikonForgeDialogueUI {
 
public override void ShowSubtitle(Subtitle subtitle) {
  // (Any extra processing before showing subtitle goes here.)
base.ShowSubtitle(subtitle);
  // (Any extra processing after showing subtitle goes here.)
}
 
public override void HideSubtitle(Subtitle subtitle) {
  // (Any extra processing before hiding subtitle goes here.)
base.HideSubtitle(subtitle);
  // (Any extra processing after hiding subtitle goes here.)
  // (Note: HideSubtitle() is called twice in some cases; be aware of that in your code.)
}
 
public override void ShowResponses(Subtitle subtitle, Response[] responses, float timeout) {
  // (Any extra processing before showing responses goes here.)
base.ShowResponses(subtitle, responses, timeout);
  // (Any extra processing after showing responses goes here.)
}
 
}

<< How to Set Up the Dialogue Manager | How to Override the Dialogue UI >>

PixelCrushers.DialogueSystem.DaikonForgeGUI
Definition: DaikonForgeBarkRoot.cs:4
PixelCrushers.DialogueSystem
Definition: ArticyConverterWindow.cs:8
PixelCrushers
Definition: ArticyConverterWindow.cs:8