Support => NGUI 3 Support => Topic started by: lzt120 on January 14, 2014, 03:02:14 AM
Title: NGUI3.0 EventDelegate with Parameters
Post by: lzt120 on January 14, 2014, 03:02:14 AM
As we can see, there is no Parameters allowed for event binding. And by using Sendmessage function, there is one parameter allowed and if this can be improved in next release ?
Title: Re: NGUI3.0 EventDelegate with Parameters
Post by: ArenMook on January 14, 2014, 09:51:44 PM
NGUI gets around this limitation by using 'current' static values, such as UIButton.current, UICamera.current, UIToggle.current, etc -- which lets you know who triggered the event.
Data binding won't work with Flash, and likely with Win8 Store / Phone platforms. They don't do reflection well (or in case of Flash -- at all). Flash has been dropped by Unity, but Win8 platforms haven't been.
Title: Re: NGUI3.0 EventDelegate with Parameters
Post by: Shifty Geezer on January 15, 2014, 05:32:00 AM
So to be clear, because this is really very important in scripting with NGUI, within any script one can call UIButton.current or UICamera.current or UIobject_type.current which will point to the object that the user has just interacted with and allow you access to all its properties?
Looking at the text label code, I see these functions...
publicvoid SetCurrentPercent ()
{
if(UIProgressBar.current!=null)
{
text = Mathf.RoundToInt(UIProgressBar.current.value* 100f)+"%";
}
}
publicvoid SetCurrentSelection ()
{
if(UIPopupList.current!=null)
{
text = UIPopupList.current.isLocalized?
Localization.Localize(UIPopupList.current.value):
UIPopupList.current.value;
}
}
So the details of the function call come from the .current object as selected from those available, which will be instantiated (not null) only if the user is interacting with that object type.
Title: Re: NGUI3.0 EventDelegate with Parameters
Post by: ArenMook on January 15, 2014, 09:38:36 PM
Yup. The are only valid if the event was triggered by those types. So if you click a button, inside its On Click notification you can determine what button sent it by checking UIButton.current.
Title: Re: NGUI3.0 EventDelegate with Parameters
Post by: lzt120 on January 16, 2014, 09:27:15 PM
So,if the Object that only with the widget collier, UICamera.current.value is the one that can only be using ?
Title: Re: NGUI3.0 EventDelegate with Parameters
Post by: ArenMook on January 16, 2014, 10:15:14 PM
UICamera.current gives you the UI camera that sent out the event, which may not be very useful in your case. UICamera.currentTouch will give you info on the touch, mouse, or controller event that triggered the action. UICamera.currentTouch.hover tells you the object that's under the mouse for example. UICamera.currentTouch.press gives you the pressed object, etc.
UIButton.current, UIToggle.current, etc are only valid if the event you're inside was triggered by one of them -- ie: On Click of a UIButton, for example.