Author Topic: NGUI3.0 EventDelegate with Parameters  (Read 3457 times)

lzt120

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 68
    • View Profile
NGUI3.0 EventDelegate with Parameters
« 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 ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI3.0 EventDelegate with Parameters
« Reply #1 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.

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: NGUI3.0 EventDelegate with Parameters
« Reply #2 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...

  1.         public void SetCurrentPercent ()
  2.         {
  3.                 if (UIProgressBar.current != null)
  4.                 {
  5.                         text = Mathf.RoundToInt(UIProgressBar.current.value * 100f) + "%";
  6.                 }
  7.         }
  8.  

  1.         public void SetCurrentSelection ()
  2.         {
  3.                 if (UIPopupList.current != null)
  4.                 {
  5.                         text = UIPopupList.current.isLocalized ?
  6.                                 Localization.Localize(UIPopupList.current.value) :
  7.                                 UIPopupList.current.value;
  8.                 }
  9.         }
  10.  
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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI3.0 EventDelegate with Parameters
« Reply #3 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.

lzt120

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 68
    • View Profile
Re: NGUI3.0 EventDelegate with Parameters
« Reply #4 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 ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI3.0 EventDelegate with Parameters
« Reply #5 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.