Dialogue response button binding setup

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
mandi
Posts: 77
Joined: Wed Sep 16, 2015 4:05 am

Dialogue response button binding setup

Post 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!
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue response button binding setup

Post 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.
mandi
Posts: 77
Joined: Wed Sep 16, 2015 4:05 am

Re: Dialogue response button binding setup

Post 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!
mandi
Posts: 77
Joined: Wed Sep 16, 2015 4:05 am

Re: Dialogue response button binding setup

Post 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!
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dialogue response button binding setup

Post 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;
        }
    }
} 
mandi
Posts: 77
Joined: Wed Sep 16, 2015 4:05 am

Re: Dialogue response button binding setup

Post by mandi »

Tony,
thank you very much!
Best
Post Reply