Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Patrax on March 20, 2015, 06:40:16 PM

Title: UIButton OnClick Subscribe Method + Arguments
Post by: Patrax on March 20, 2015, 06:40:16 PM
Much like this thread: http://www.tasharen.com/forum/index.php?topic=7552.0 (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.
Title: Re: UIButton OnClick Subscribe Method + Arguments
Post by: devomage on March 21, 2015, 03:19:36 PM
Much like this thread: http://www.tasharen.com/forum/index.php?topic=7552.0 (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.  
Title: Re: UIButton OnClick Subscribe Method + Arguments
Post by: Patrax on March 21, 2015, 03:55:48 PM
Thank you! I really was so close :) haha.