Page 1 of 1
How do response buttons work?
Posted: Fri Mar 18, 2016 12:48 pm
by Nonlin
I'm trying to figure out how to get the buttons assigned as Response buttons to perform actions?
I've been looking through the source and I see that there is an OnClick but its sent where? What does it call and how can I get the button to perform events of my own using System Dialogue?
Re: How do response buttons work?
Posted: Fri Mar 18, 2016 2:48 pm
by Tony Li
Hi,
Would you please remind me which GUI system you're using?
If you're using Unity UI now, each response button's OnClick() event should be configured to invoke the OnClick method of its UnityUIResponseButton component. (If your response button doesn't have a UnityUIReponseButton component, inspect it and then select menu item
Component > Dialogue System > UI > Unity UI > Dialogue > Response Button.)
You can add other methods to the button's OnClick() event. Just click the "+" at the lower right of the OnClick() event block to create an empty slot, then assign your script and select the method. For example, you could assign an AudioSource and select its Play method to play a sound when the button is clicked.
If you want to access the response data associated with the button, use GetComponent<
UnityUIResponseButton>() and read the
response property.
Re: How do response buttons work?
Posted: Fri Mar 18, 2016 2:56 pm
by Nonlin
Didn't realize it was just calling the OnClick from Unity's UI. I just created an Add-listener.
In the previous NGUI there was still OnClick but I didn't see anything defined for the OnClick there so wasn't sure how it was done there.
Any idea how a new response gets made/shown?
After picking a response how does SD proceed to select and return new responses from the DB?
Re: How do response buttons work?
Posted: Fri Mar 18, 2016 8:00 pm
by Tony Li
NGUI sends an "OnClick" message to all scripts on the button in addition to calling any methods that you've explicitly added to the click event. As long as the method is actually named "OnClick", it'll get called even if it hasn't been explicitly added.
Dialogue UIs use this process to set up response buttons:
1. If any buttons are assigned to the Response Menu > Buttons list, it'll try to use those first. If a dialogue entry has a
[position #] markup tag, it'll use the button at that index in the Buttons list.
2. If there aren't any available buttons in the Buttons list, it'll instantiate a copy of the Button Template and add it as a child of the Button Template Holder.
3. In either case, it'll find the UnityUIResponseButton script (or equivalent for each GUI system) on the button and set the response property.
4. When the UnityUIResponseButton gets clicked, it calls the dialogue UI's OnClick(Response) method. So if you want to fake a response you can directly call the dialogue UI's OnClick(Response) method.
5. Behind the dialogue UI, the Dialogue System uses a Model-View-Controller architecture:
- The dialogue UI's OnClick(Response) method tells the ConversationView that a response was selected.
- The ConversationView passes this to the ConversationController.
- The ConversationController tells the ConversationModel to advance to the response's dialogue entry.
- The ConversationModel evaluates all of that dialogue entry's links. It has to evaluate them at this point (and not later) because the ConversationView may need to know if it should show a continue button.
- Then the ConversationModel sends the new current dialogue entry back to the controller, the controller updates the view, and the view displays the next response menu or subtitle, whichever is appropriate.