Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: hvilela on October 02, 2012, 04:07:33 PM

Title: UIEventListener extra parameter
Post by: hvilela on October 02, 2012, 04:07:33 PM
I'm creating a few buttons with a for, and adding colliders and event listeners to each one. All this buttons call the same function when OnClick is dispatched.
I can receive the button itself as parameter in the called function, but I would like to receive the button index.

Is it possible to pass a second parameter to it, to any other workaround?
Title: Re: UIEventListener extra parameter
Post by: PapaWhiskey on January 11, 2013, 08:39:13 AM
i added a variable "userData" to UIButtonColor (the parent of UIButton) and in the callback I do a getComponent<UIButton> and then query the userData variable...would like to make that variable generic, but for my purposes I only needed an int button index
Title: Re: UIEventListener extra parameter
Post by: ArenMook on January 11, 2013, 01:27:00 PM
For anything that requires a parameter, create a custom script instead of using UIEventListener. Attach this custom script to your buttons, and implement the OnClick function.
Title: Re: UIEventListener extra parameter
Post by: PapaWhiskey on January 11, 2013, 06:35:57 PM
well he said he wanted to know the index of the buttons he was creating and they all call the same onClick routine...you either figure out which button via name or you do something like i did and extend the button class to have a generic userData variable...when you create the buttons in code (as he indicated he is), its much easier to just set the userData variable to the index of the for loop, and then when onClick is called (or whatever function you add to the UIEventListener queue) you can then query what the userData value is...