Author Topic: UIToggle groups - add feature to only notify when value is 1?  (Read 5683 times)

tr4np

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 17
    • View Profile
I just spent some time troubleshooting a group of UIToggles.  It turns out that every UIToggle widget was calling my notification script during initialization.  I'm using these as a list box, so I'm only interested in the one that's currently selected (why doesn't NGUI have a list box widget, anyway?).  Anyway, I realized that my method was being notified for every UIToggle in my panel, even when they were all unselected initially.

I ended up having to add an int parameter to my methods, and have the notification pass in the UIToggle's value.  My methods were modified to ignore the notification if the value was 0.  It was tedious to have to do this for every single UIToggle in my GUI, though.

Is it possible to add a UIToggle option to only notify when the value is changed to 1?  Or perhaps have a UIGroup script that will notify when a UIToggle in its group is selected.  That is, the UIGroup would have a list of UIToggles, and notify an object with the index/name/gameobject of the selected UIToggle.  Or is there already a way to determine which UIToggle in a group is currently selected?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIToggle groups - add feature to only notify when value is 1?
« Reply #1 on: April 10, 2014, 06:45:57 AM »
For anything custom like that you should write a script. Note that the callback being called on initialization is intentional, so that the callback is in the same state as the toggle on init.

tr4np

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: UIToggle groups - add feature to only notify when value is 1?
« Reply #2 on: April 10, 2014, 02:06:47 PM »
For anything custom like that you should write a script. Note that the callback being called on initialization is intentional, so that the callback is in the same state as the toggle on init.

That's fine, I can just write a script.  I was just thinking that perhaps this was a common-enough request that a new widget script could be provided for everyone to use.  Controls like list boxes and radio button groups are common enough that most GUI systems have a dedicated widget type for them.  No need to make every developer re-invent the wheel, right?

Anyway, thank you for the clarification.