Author Topic: UIButton OnClick Subscribe Method + Arguments  (Read 4980 times)

Patrax

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
UIButton OnClick Subscribe Method + Arguments
« on: March 20, 2015, 06:40:16 PM »
Much like this thread: http://www.tasharen.com/forum/index.php?topic=7552.0
But, need to subscribe the function plus the argument at runtime. How?

Currently setting it up this way:
  1. EventDelegate ed = new EventDelegate ();
  2. ed.Set (this,"NameOfFunction");
  3. go.GetComponentInChildren<UIButton> ().onClick.Add (ed);

This works, but I still haven't found the way to attach parameters.
« Last Edit: March 20, 2015, 07:10:54 PM by Patrax »

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: UIButton OnClick Subscribe Method + Arguments
« Reply #1 on: March 21, 2015, 03:19:36 PM »
Much like this thread: http://www.tasharen.com/forum/index.php?topic=7552.0
But, need to subscribe the function plus the argument at runtime. How?

Currently setting it up this way:
  1. EventDelegate ed = new EventDelegate ();
  2. ed.Set (this,"NameOfFunction");
  3. go.GetComponentInChildren<UIButton> ().onClick.Add (ed);

This works, but I still haven't found the way to attach parameters.

  1. UIButton button = go.GetComponent<UIButton> ();
  2.  
  3. EventDelegate ed = new EventDelegate ();
  4. ed.parameters[0].value = button;
  5. ed.Set (this,"NameOfFunction");
  6.  
  7. void NameOfFunction(UIButton button)
  8. {
  9.  
  10. }
  11.  

Patrax

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: UIButton OnClick Subscribe Method + Arguments
« Reply #2 on: March 21, 2015, 03:55:48 PM »
Thank you! I really was so close :) haha.