Author Topic: EventDelegate Parameter  (Read 14571 times)

slipstream

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
EventDelegate Parameter
« on: June 28, 2014, 09:36:50 PM »
Hi!

First, Thank you for making NGUI, i bought it one month ago and i must say that i love it.

I have a problem when i want to add a parameter by code to a trigger event.

  1. UIEventTrigger trigger = myCustomGameObject.AddComponent<UIEventTrigger>();
  2. EventDelegate.Add(trigger.onPress, OnSelect);
  3.  
  4. public void OnSelect( GameObject go )
  5. {
  6.      Debug.Log(go);
  7. }
  8.  

I can make it work without parameters, but how would i add the game object parameter inside the Event Delegate ?
On the editor, args 0 appear, so i can drag and drop the desired gameobject.

I just would like to do that by code.
Any hint would be very appreciated.

Best regards.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: EventDelegate Parameter
« Reply #1 on: June 29, 2014, 08:52:30 PM »
  1. del.parameters[0] = new EventDelegate.Parameter(targetObject, fieldName);
For example:
  1. del.parameters[0] = new EventDelegate.Parameter(slider, "value");

friderator

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 4
    • View Profile
Re: EventDelegate Parameter
« Reply #2 on: July 23, 2014, 10:10:53 AM »
ArenMook, would you mind giving a code example using an object?

I'm trying to do:
  1. GameObject go = #{some game object};
  2. EventDelegate del = new EventDelegate();
  3. del.methodName = "OnTagClick";
  4. del.parameters[0] = new EventDelegate.Parameter(go, "gameObject");

however del.parameters does not exist

friderator

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 4
    • View Profile
Re: EventDelegate Parameter
« Reply #3 on: July 23, 2014, 10:23:17 AM »
nvmd figured it out:
 
  1. EventDelegate del = new EventDelgate(this, "OnTagClick");
  2. del.parameters[0] = new EventDelegate.Parameter(go, "gameObject");
  3.  

then pass del to the EventDelegate.Add method as the delegate