Page 1 of 1

[Solved!] How to Manipulate Response Buttons

Posted: Sun Sep 01, 2019 12:04 am
by CodePrincess
Hi, Mr. Li!

I figured out that if you add a checkmark image to the Response button template, every button created gets it's own check mark. Is there a way to single out an individual response button in runtime and change its checkmark's active state?

Thank you very much for your help!

Re: How to Manipulate Response Buttons

Posted: Sun Sep 01, 2019 12:44 am
by Tony Li
Hi,

You can make a subclass of StandardDialogueUI and override the ShowResponses method as in this example:

Code: Select all

public class MyDialogueUI : StandardDialogueUI
{
    public override void ShowResponses(Subtitle subtitle, Response[] responses, float timeout)
    {
        // Set up the response buttons like 
        base.ShowResponses(subtitle, responses, timeout);
        
        // Activate the first button's checkmark image:
        var firstButton = conversationUIElements.defaultMenuPanel.instantiatedButtons[0];
        firstButton.Find("Checkmark").SetActive(true);
    }
}
Or you may find it simpler to add a script to the Dialogue Manager that has an OnConversationResponseMenu method:

Code: Select all

void OnConversationResponseMenu(Response[] responses)
{
    StartCoroutine(DoSomethingAtEndOfFrame()); // Give dialogue UI until end of frame to set up menu buttons.
}

IEnumerator DoSomethingAtEndOfFrame()
{
    // Activate the first button's checkmark image:
    var dialogueUI = DialogueManager.dialogueUI as StandardDialogueUI;
    var firstButton = dialogueUI.conversationUIElements.defaultMenuPanel.instantiatedButtons[0];
    firstButton.Find("Checkmark").SetActive(true);
}

Re: How to Manipulate Response Buttons

Posted: Sun Sep 01, 2019 1:30 am
by CodePrincess
Wow, you are so fast! :-D Thank you!

Re: How to Manipulate Response Buttons

Posted: Sun Sep 01, 2019 10:22 am
by Tony Li
Happy to help! :-)