Author Topic: UIEventTrigger access  (Read 12937 times)

fghjru

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
UIEventTrigger access
« on: March 28, 2014, 03:17:59 AM »
How should i set from the script?:
onHoverOut
onPress
onRelease
in UIEventTrigger added to the UIButton

UncleAcid

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
Re: UIEventTrigger access
« Reply #1 on: March 28, 2014, 08:38:44 AM »
  1. UIEventTrigger trigger;
  2.  
  3. trigger.onPress.Add(new EventDelegate(MethodYouWantCalled));
  4.  

Just follow the same pattern replacing onPress with whatever callback you want.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIEventTrigger access
« Reply #2 on: March 28, 2014, 09:10:07 AM »
In most cases you'd actually use:
  1. EventDelegate.Add(trigger.onPress, MethodYouWantCalled);

UncleAcid

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
Re: UIEventTrigger access
« Reply #3 on: March 28, 2014, 12:36:12 PM »
That actually makes a lot more sense. Thanks.

netlander

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 11
    • View Profile
Re: UIEventTrigger access
« Reply #4 on: June 14, 2014, 12:30:45 PM »
What parameters, if any, are passed to the delegate method that's being called by the event trigger?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIEventTrigger access
« Reply #5 on: June 15, 2014, 05:27:14 AM »
The parameters you'd specify. It's up to you to specify eventDelegate.parameters = new EventDelegate.Parameter[] { ... };.

Carbonite

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UIEventTrigger access
« Reply #6 on: June 19, 2014, 05:12:15 AM »
The parameters you'd specify. It's up to you to specify eventDelegate.parameters = new EventDelegate.Parameter[] { ... };.

eventDelegate.parameters is read only. So how can we assign anything to it during runtime? Am I missing something here?

Carbonite

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UIEventTrigger access
« Reply #7 on: June 19, 2014, 06:00:03 AM »
Figured it out I think. Something like this looks like it's working...

  1. EventDelegate myDelegate = new EventDelegate();
  2.  
  3. ...
  4.  
  5. EventDelegate.Parameter a = new EventDelegate.Parameter();
  6. a.obj = myComponent.gameObject;
  7. myDelegate.Set( this, "myFunction");
  8. myDelegate.parameters.SetValue (a, 0);
  9. myComponent.gameObject.AddComponent<UIEventTrigger> ();
  10. myComponent.gameObject.GetComponent<UIEventTrigger> ().onClick.Add (myDelegate);

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIEventTrigger access
« Reply #8 on: June 19, 2014, 06:15:27 PM »
AddComponent<UIEventTrigger>() will already return an instance of the script, so you can do it all in one line:
  1. myComponent.gameObject.AddComponent<UIEventTrigger>().onClick.Add (myDelegate);

Carbonite

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UIEventTrigger access
« Reply #9 on: June 21, 2014, 03:57:45 AM »
Ahh, yes. Thank you. But for parameters, you have set it up to use
  1. myDelegate.parameters.SetValue (a, 0);
correct?

because i couldn't get
  1. eventDelegate.parameters = new EventDelegate.Parameter[] { ... };
to work for the life of me. With it being read only.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIEventTrigger access
« Reply #10 on: June 21, 2014, 03:39:43 PM »
Yup, you were right.