Author Topic: UICheckbox event reciever function no reference to the checkbox  (Read 7523 times)

lime-green.at

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 60
    • View Profile
UICheckbox event reciever function no reference to the checkbox
« on: February 04, 2013, 08:20:22 AM »
Hey,

im currently implementing a scene with about 30 checkboxes, all checkboxes are managed by the same controller. Is there any way to send the name of the checkbox or some other reference with the method call at the event reciver? Its also kinda annoying the checkbox set's itself at Start with calling the controller method...

Regards

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICheckbox event reciever function no reference to the checkbox
« Reply #1 on: February 04, 2013, 09:19:35 AM »
UICheckbox.current

lime-green.at

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 60
    • View Profile
Re: UICheckbox event reciever function no reference to the checkbox
« Reply #2 on: February 04, 2013, 11:35:23 AM »
And how to send that information to the controller when calling the event function on the event handler?

Regards

lime-green.at

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 60
    • View Profile
Re: UICheckbox event reciever function no reference to the checkbox
« Reply #3 on: February 04, 2013, 12:04:17 PM »
Got it, i guess it would be cool if you would implement something like that in the next version of ngui :)


Event Reciver Class
  1.     public void OnStateChange(string[] info)
  2.     {
  3.         Debug.Log(info[0]);
  4.         Debug.Log(info[1]);
  5.     }

UICheckbox
  1.                         // Send out the event notification
  2.                         if (eventReceiver != null && !string.IsNullOrEmpty(functionName))
  3.                         {
  4.                                 current = this;
  5.                 string[] temp = new string[2];
  6.                 temp[0] = "" + mChecked;
  7.                 temp[1] = current.gameObject.name;
  8.  
  9.                 eventReceiver.SendMessage(functionName, temp, SendMessageOptions.DontRequireReceiver);
  10.                         }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICheckbox event reciever function no reference to the checkbox
« Reply #4 on: February 04, 2013, 07:36:19 PM »
Huh? Why are you doing that?

In your callback function, UIChecked.current tells you the checkbox that triggered it (the checked one), which lets you do UIChecked.curent.name. There is no need to modify NGUI for this.

lime-green.at

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 60
    • View Profile
Re: UICheckbox event reciever function no reference to the checkbox
« Reply #5 on: February 05, 2013, 03:15:38 AM »
Ah cool, thanks. Didn't notice that's static :)

Regards