Page 1 of 1

instantiatedButtons return 0

Posted: Mon Jul 13, 2015 10:14 am
by alfonso
Hi i have a little problem with this code and the dialogue.responseMenu.instantiatedButtons variable.

here the code:

Code: Select all

public override void ShowResponses (Subtitle subtitle, Response[] responses, float timeout) {
			base.ShowResponses(subtitle, responses, timeout);
			SetButtonsNav();
			if (autoFocus) dialogue.responseMenu.AutoFocus(); 
		}
		void SetButtonsNav()
		{
			List<GameObject> buttons = dialogue.responseMenu.instantiatedButtons;
			Debug.Log (buttons.Count);
			int totals = buttons.Count;
			for(int i = 0; i < totals; i++)
			{
				Navigation current = buttons[i].GetComponent<Button>().navigation;
				current.selectOnUp = (i == 0)? buttons[totals-1].GetComponent<Button>(): buttons[i-1].GetComponent<Button>();
				current.selectOnDown = (i == totals)? buttons[0].GetComponent<Button>(): buttons[i+1].GetComponent<Button>();
			}
		}
NOTE: the buttons are in explicit mode
the main idea is setup the nav of the response buttons like doc recomend becouse the automatic one is little crazy and in the game when i talk with a NPC who has various responses show me the corrects number of buttons but the dialogue.responseMenu.instantiatedButtons give a value of 0 buttons and dont enter in the loop :(

and other rare thing is the showResponse is called twice (the same number of buttons of the npc im using to) this is normal?

im using the new unity ui and the canvas is on world space

Thank you so much for the help

Re: instantiatedButtons return 0

Posted: Mon Jul 13, 2015 1:56 pm
by Tony Li
Hi,

When using explicit buttons (defined in Dialogue > Response Menu > Buttons), the dialogue UI will not instantiate any other buttons, so instantiatedButtons will be empty. You can loop through dialogue.responseMenu.buttons instead. Unused buttons will be disabled.

ShowResponses() shouldn't be called twice. Please feel free to email an example project to tony (at) pixelcrushers.com. I'll be happy to take a look.

Tony