Dialogue Listeners
Dialogue Listeners can be used to easily add your own components and scripts which listen and respond to dialogue events as they are processed by your Dialogue Controllers.
For example, if you want to implement your own dialogue UI from scratch, but not worry about the underlying logic of the dialogue flow and nodes, you can just extend the DialogueListener class and override the relevant methods, then add it as a listener on the Dialogue Controller(s) you're using. As the DialogueController processes your Dialogue asset, it will automatically call the methods of your Dialogue Listener when appropriate to do so.
Of course, you can use Dialogue Listeners for all sorts of other creative uses, it's really only limited by your imagination! 😄
Example​
In the example below, we create new class called CharacterNameDisplay which overrides the OnDisplayLine() method of the DialogueListener class to set the text of a Unity Text UI component to the translated name of the character who is currently speaking.
using EasyTalk.Controller;
using UnityEngine.UI;
//Text UI component to display a character name on
[SerializeField] private Text text;
public class CharacterNameDisplay : DialogueListener
{
public override void OnDisplayLine(ConversationLine line)
{
//Set the text to the translated character name
text.text = line.TranslatedCharacterName;
}
}
Defined / Overridable Methods​
Method Name | Description |
---|---|
OnContinue() | Called whenever the dialogue continues on to the next line. |
OnDisplayOptions(List<DialogueOption> options) | Called whenever dialogue options are to be presented. |
OnOptionChosen(DialogueOption option) | Called whenever an option is chosen from the currently presented list of options. |
OnDisplayLine(ConversationLine conversationLine) | Called when a line of dialogue is to be presented. |
OnDialogueEntered(string entryPointName) | Called whenever a dialogue is entered (when playback begins). |
OnDialogueExited(string exitPointName) | Called whenever a dialogue is exited (when playback ends). |
OnExitCompleted() | Called at least one frame after a dialogue is exited. |
OnStory(string storyText) | Called whenever a story node is encountered. |
OnVariableUpdated(string variableName, object value) | Called whenever a dialogue variable value is updated. |
OnCharacterChanged(string oldCharacterName, string newCharacterName) | Called whenever a character change is detected. |
OnAudioStarted(ConversationLine line) | Called whenever audio starts playing for a line of dialogue. |
OnAudioCompleted(ConversationLine line, bool forceStopped) | Called whenever audio stops playing for a line of dialogue. |
OnActivateKey(string key) | Called whenever a key tag is present in a line of dialogue. |
Wait(float timeInSeconds) | Called whenever the dialogue encounters a wait node. |
OnConversationEnding(ConversationLine line, Node nextNode) | Called whenever the last line of dialogue in a conversation node is reached. |
OnNodeChanged(Node node) | Called whenever dialogue playback moves to the next node. |
OnPause(string signal) | Called whenever a pause node is reached during dialogue playback. |