Author Topic: Checbkox usage confusion  (Read 3161 times)

oxyscythe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Checbkox usage confusion
« on: July 16, 2014, 05:00:58 PM »
Hello!

I am trying to understand how I am meant to use the checkbox script.

I've got a "UIInteractionManager" script that's meant to handle events from my UI elements and it exposes some public fields so I can attach relevant widgets to that script in the editor.

So I've got a checkbox control that I am passing to this script in this manner and then in Start() I do this:

        DebugOptionsCheckbox.onChange.Add(new EventDelegate(HandleDebugOptionsCheckboxOnChange));

However my handler doesn't get called when I click on the checkbox.

Debugging the NGUI code I noticed that the code that fires the event (UIToggle.cs line 232) is never called because the check on line 226 (current == null) returns false (I am not copy pasting the code as I am not sure if it's allowed but hopefully this is enough information)

Why is this event not fired? Am I using the control in a way that's not meant to be used?

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Checbkox usage confusion
« Reply #1 on: July 17, 2014, 02:37:02 AM »
EventDelegate.Add(DebugOptionsCheckbox.onChange, HandleDebugOptionsCheckboxOnChange);

Why is the 'current' not null in your case? It will only not be null if you are already inside another callback. What is it set to?

oxyscythe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Checbkox usage confusion
« Reply #2 on: July 19, 2014, 06:14:09 PM »
Hi, sorry for taking a while to get back, I ended up using the UIButton component of the widget and handling the OnClick instead which worked out as a workaround and then I forgot to check back on this thread.

So what's really weird is that I just changed the code back to what it was (so, I am using the UIToggle component and the onChanged event), but now it all works fine! current is indeed null when I step through this code and the delegate is fired properly.

I am sorry, I am not sure what I was doing before to have caused the other behaviour, but I guess all's well that ends well?! I will let you know if I see it happen again!