Page 1 of 1

Changing Dialogue UI on runtime

Posted: Sat Nov 21, 2020 4:36 pm
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.

Re: Changing Dialogue UI on runtime

Posted: Sat Nov 21, 2020 5:12 pm
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.

Re: Changing Dialogue UI on runtime

Posted: Sat Nov 21, 2020 5:26 pm
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!

Re: Changing Dialogue UI on runtime

Posted: Sat Nov 21, 2020 5:48 pm
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);

Re: Changing Dialogue UI on runtime

Posted: Sun Nov 22, 2020 10:14 am
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();
        }
    }

Re: Changing Dialogue UI on runtime

Posted: Sun Nov 22, 2020 10:16 am
by Tony Li
Yes. If they're null, the conversation will find them by their Dialogue Actor components.