Page 1 of 1

Dialogue response button binding setup

Posted: Sat Nov 07, 2015 12:10 pm
by mandi
Hello,
how do I bind a keystroke to a response buttons? I mean I would like to have bound numbers from 1-9 to each of my responses, and in case there is only one response available, also Space to trigger the lone response. Is ther an event for that?

Best!

Re: Dialogue response button binding setup

Posted: Sat Nov 07, 2015 7:38 pm
by Tony Li
Hi,

Add a UI Button Key Trigger component to the button.

If you tick Auto Focus, it will highlight the first response. If you press the spacebar, it will trigger the highlighted response.

If you're using a response button template that instantiates buttons at runtime, you'll have to assign the right key at runtime. The next release of the Dialogue System will have an option to do this automatically for you. In the meantime, if you need to set this up, let me know and I can provide more details.

Re: Dialogue response button binding setup

Posted: Tue Nov 10, 2015 6:43 am
by mandi
Hi Tony,
splendid! I'm using a button's template, though I will write a script for runtime assignment by myself. Should I have any problems, I will let you know.
Best!

Re: Dialogue response button binding setup

Posted: Tue Nov 10, 2015 7:04 am
by mandi
Hi Tony,
from what I see my best option is to add UI Button Key Trigger component to each of the clones of response buttons residing under Scroll Content, probably when ShowResponses is called. The references to the clones are under buttonTemplateHolder at UnityUIResponseMenuControls, am I right?
Best!

Re: Dialogue response button binding setup

Posted: Tue Nov 10, 2015 10:21 am
by Tony Li
Hi,

EDIT: I forgot there's already a script and example on the Extras page. It's the second download button in the UIs section.

That's just about right. If you add a UIButtonKeyTrigger to the template button, all instantiated versions will have it, too. The instantiated buttons are in the instantiatedButtons property. You can set them like this:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class MyDialogueUI : UnityUIDialogueUI {

    public override void ShowResponses(Subtitle subtitle, Response[] responses, float timeout) {
        // Set up the buttons as normal:
        base.ShowResponses(subtitle, responses, timeout);
        
        // Then set the number keys:
        foreach (int i = 0; i < dialogue.responseMenu.instantiatedButtons.Count; i++) {
            var key = (KeyCode) ((int)KeyCode.Alpha0 + i);
            var button = dialogue.responseMenu.instantiatedButtons[i];
            button.GetComponent<UIButtonKeyTrigger>().key = key;
        }
    }
} 

Re: Dialogue response button binding setup

Posted: Tue Nov 10, 2015 11:51 am
by mandi
Tony,
thank you very much!
Best