Page 2 of 2

Re: Getting and sending responses through code

Posted: Fri Feb 07, 2020 2:29 am
by Luke
Thanks so much!

Licensing wise, do you mind if I just copy & paste some of the code from your example into my own code?

Re: Getting and sending responses through code

Posted: Fri Feb 07, 2020 8:57 am
by Tony Li
Sure, have at it!

Re: Getting and sending responses through code

Posted: Tue Feb 18, 2020 2:00 am
by Luke
I have discovered a new problem. There are only ever 3 (invisible) response buttons at a time, even if the number of responses I've written is higher. Is there a way I can have it generate as many buttons as there are responses? I currently have it set to using the Bubble Menu panel for responses like in the example scene you posted.

Also, how do I turn off the fade in/fade out effect on the speech bubbles? I saw in another thread that the answer was to change the show/hide trigger to being blank, but this resulted in the bubble just not becoming visible at all.

Re: Getting and sending responses through code

Posted: Tue Feb 18, 2020 7:57 am
by Tony Li
Hi Luke,

If you're using the bubble UI prefab in the Prefabs folder, or the bubble UI in the Bubble Subtitle Example, they're only designed with 3 buttons. You can configure response menus to use a list of explicitly-placed buttons (like in these bubble UIs) or instantiate as many buttons as needed from a template button and put them into a layout group container (like in most of the other UI prefabs such as Basic Standard Dialogue UI). If you need more than 3 buttons, here are 2 options:

1. Add more explicitly-placed buttons to the StandardUIMenuPanel's Buttons list.

2. Or remove the buttons, keeping just one to use as a template, and assign it to the Button Template field. Set up a container panel that will hold copies of this button, and assign it to the Button Template Holder field. Clear the Buttons list. When setting up the response menu, the Dialogue System will instantiate as many copies of the template button as needed and put them all in the Button Template Holder.


To turn off the fade in/out on the bubbles, remove the Animator from the Bubble Panel child GameObject, and also clear the Show and Hide Trigger fields.

Re: Getting and sending responses through code

Posted: Wed Feb 19, 2020 3:36 am
by Luke
Thanks! I got those things working now, but unfortunately it broke something else. I switched to instantiated buttons since the number of responses will be varying quite a bit, but the StandardUIMenuPanel.buttons that I was iterating through to find a match is now empty. The buttons show up now in StandardUIMenuPanel.instantiatedButtons, but they don't have OnClick() available. Is there another way to access them?
I suppose I could get a reference to the game object that is the parent of the buttons and iterate through its children instead, but it seems like there is probably a better way.

Re: Getting and sending responses through code

Posted: Wed Feb 19, 2020 7:58 am
by Tony Li
Hi,

StandardUIMenuPanel.instantiatedButtons is a list of GameObjects. Each one will have a StandardUIResponseButton component that you can access using GetComponent():

Code: Select all

foreach (var buttonGO in myMenuPanel.instantiatedButtons)
{
    var button = buttonGO.GetComponent<StandardUIResponseButton>();
    Debug.Log("Button is linked to response: " + button.response.formattedText.text);
}
(It's a list of GameObjects instead of a list of StandardUIResponseButtons to make it more concise for StandardUIMenuPanel to manage their instantiation.)

Re: Getting and sending responses through code

Posted: Fri Feb 21, 2020 1:50 am
by Luke
Ok, thanks! I've got it working now.

Re: Getting and sending responses through code

Posted: Fri Feb 21, 2020 8:06 am
by Tony Li
Great! Glad to help.