Page 1 of 1

[HOWTO] How To: Manually Process Conversation UIs

Posted: Fri May 15, 2020 10:21 pm
by Tony Li
Below are three ways to handle conversations outside of the regular Dialogue System process. I'll include rough code samples for each.

1. Read dialogue entries directly from the dialogue database:

Code: Select all

Conversation conversation = DialogueManager.masterDatabase.GetConversation("My Conversation");
foreach (DialogueEntry entry in conversation.dialogueEntries)
{
    Debug.Log(entry.DialogueText);
}
In #1, the Dialogue System isn't running a conversation. It's just pulling data directly from the database.

2. Or start a ConversationModel. When the Dialogue System runs a conversation, it uses a Model-View-Controller (MVC) architecture. The model holds the data, including the current state of the conversation. The view manages the UI. The controller is the intermediary between the model and view.

Code: Select all

ConversationModel model = new ConversationModel(DialogueManager.masterDatabase, conversation, null, null, false, null);
ConversationState state = model.firstState;
do
{
    Debug.Log(state.subtitle.dialogueEntry.id + ": " + state.subtitle.formattedText.text);
    if (state.hasNPCResponse)
    {
        state = model.GetState(state.firstNPCResponse.destinationEntry, true);
    } 
    else if (state.HasPCResponses)
    {
        state = model.GetState(state.pcResponses[0].destinationEntry, true);
    }
    else
    {
        state = null;
    }
} while (state != null);
#2 runs the model part of a conversation, manually advancing through NPC lines.

3. Or run a full fledged conversation, but provide your own UI implementation. In #2, I mentioned that conversations use an MVC architecture. The view consists of two parts: a dialogue UI (subtitles, response menus, etc.) and a cutscene sequencer. The view will work happily with any dialogue UI script that implements the IDialogueUI C# interface. The Templates folder has a starter script for custom implementations of IDialogueUI. Simply assign your dialogue UI GameObject to the Dialogue Manager's Dialogue UI field. Devs have created IDialogueUI implementations for all kinds of interfaces, such as virtual room installations, audio-only smart speakers, etc.

#3 allows the Dialogue System to run its complete MVC architecture.