Changing Dialogue UI on runtime

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Changing Dialogue UI on runtime

Post by fkkcloud »

Hello,

Would switching Dialogue UI an "okay" thing to do?

My plan is to have 2 Dialogue UI under my DialogueManager Prefab.
1st one is the default one with my preferred dialogue Ui.
2nd one is a chat UI - modified version of SMS prefab example.
Then, basically, switch its field on runtime via C#.

Expected player experience:
The Player will get an "SMS" during the conversation and focus on the SMS. Then he might get back to regular dialogue.

Another following up question is: should I create 2 separate conversations for regular conversation vs SMS?
Or can I just create some type of Sequencer or LuaScript to send a signal to switch the dialogue UI within a single conversation?

Just want to check above before I jump in and go expand further..!

Thank you in advance.
User avatar
Tony Li
Posts: 22050
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing Dialogue UI on runtime

Post by Tony Li »

This is one way to do it:

1. Add both dialogue UIs to the Dialogue Manager. They can be in the same Canvas or different Canvases. (Different Canvases are more efficient.)

2. Assign the default UI to the Dialogue Manager's Dialogue UI field. Regular conversations will use this UI.

3. Create a GameObject named "SMS". Add a Dialogue Actor component, and assign the SMS actor. (Create an SMS actor in the Dialogue Editor.) Add an Override Dialogue UI component, and assign the SMS dialogue UI. Conversations that use the SMS actor will use this UI.

4. Inspect the Dialogue Manager Object. Tick Other Settings >Allow Simultaneous Conversations. This will allow the regular conversation and SMS conversation to run at the same time.
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Changing Dialogue UI on runtime

Post by fkkcloud »

Amazing!

Would "Input focus" will naturally move onto SMS from default and default from SMS if I don't want to use "Simultaneous"?

I would do like below in one single conversation.

Actor A : hello
Actor B : hey there
-- default UI fade out and SMS UI fade in
Actor C SMS : hey where are you?
Actor A SMS : Im with Actor B.
-- SMS UI fade out and default UI fade in
Actor B : who is it?

Thank you!
User avatar
Tony Li
Posts: 22050
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing Dialogue UI on runtime

Post by Tony Li »

It would not automatically change focus. It might be better to record the position in the regular conversation, stop it, and start the SMS conversation. When the SMS conversation is done, resume the regular conversation at the recorded position.

This will require a little scripting. To record the regular conversation's position, record the current dialogue entry:

Code: Select all

var currentEntry = DialogueManager.currentConversationState.subtitle.dialogueEntry;
Then start the new conversation:

Code: Select all

DialogueManager.StartConversation("SMS Conversation", playerTransform, SMSActorTransform);
When it's done (you can check in an OnConversationEnd event or method), resume the regular conversation:

Code: Select all

var regularConversation = DialogueManager.masterDatabase.GetConversation(currentEntry.conversationID);
DialogueManager.StartConversation(regularConversation, playerTransform, npcTransform, currentEntry.id);
fkkcloud
Posts: 298
Joined: Mon Oct 05, 2020 6:00 am

Re: Changing Dialogue UI on runtime

Post by fkkcloud »

When I put currentEntry.id to StartConversation(..) method,

Can I just do

Code: Select all

DialogueManager.StartConversation(regularConversation, null, null, currentEntry.id);
Since I already have set necessary actors via the "Dialogue Actor" component for all?

Basically, my custom Sequencer Command look like this

Code: Select all

    public class SequencerCommandStartSMSConversation : SequencerCommand
    {
        private void Awake() {
            GameManager.Instance.dialogueEntry = DialogueManager.currentConversationState.subtitle.dialogueEntry;

            string smsConveration = GetParameter(0); //Gets the i-th parameter as string
            DialogueManager.StartConversation(smsConveration);

            Stop();
        }
    }

    public class SequencerCommandEndSMSConversation : SequencerCommand
    {
        private void Awake() {
            Conversation regularConversation = DialogueManager.masterDatabase.GetConversation(GameManager.Instance.dialogueEntry.conversationID);      
            DialogueManager.StartConversation(regularConversation.Name, null, null, GameManager.Instance.dialogueEntry.id);
            Stop();
        }
    }
Last edited by fkkcloud on Sun Nov 22, 2020 10:18 am, edited 1 time in total.
User avatar
Tony Li
Posts: 22050
Joined: Thu Jul 18, 2013 1:27 pm

Re: Changing Dialogue UI on runtime

Post by Tony Li »

Yes. If they're null, the conversation will find them by their Dialogue Actor components.
Post Reply