Author Topic: Toggle state sent at Start  (Read 2480 times)

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Toggle state sent at Start
« on: November 07, 2014, 06:24:08 AM »
Hello!
Long time no see :)

In the UIToggle script, whenever the GameObject containing the UIToggle is activated for the first time, it will directly send the onToggleChange event, even if we did not click on the toggle.
This is great for some purpose, so that you can initialize your UI directly depending on the state etc...

But imagine that you're doing complex operations when you change a toggle, and you do not want anything to be done at Start. You only want to activate something when the user click on a toggle, not when the toggle become visible... there is no way to do that.
Well yes, I could in my own onToggleChange callback, do a boolean check to see if it's the first time it's going in this method, but if I have 50 toggles, I need 50 different booleans to manage that...

The only option I found, is to modify the UIToggle script, just doing this in the Set() method:

  1. if (EventDelegate.IsValid(onChange))
  2. {
  3.    if (!m_isFirstTimeSendingEvent)
  4.    {
  5.       EventDelegate.Execute(onChange);
  6.    }
  7.  
  8.  
  9.    m_isFirstTimeSendingEvent = false;
  10. }

The thing is, next time I update NGUI... my code will be removed.
Do you have a solution for this?


Thanks!

Fireball14

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 23
    • View Profile
Re: Toggle state sent at Start
« Reply #1 on: November 07, 2014, 07:27:52 AM »
Every time when i change something in NGUI, i just make a copy of script i'm changing with different name.
So next time NGUI updates it will only override original.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Toggle state sent at Start
« Reply #2 on: November 07, 2014, 03:07:41 PM »
Use a versioning system like Git, then you can do an automatic merge. Pro licenses already come with Git access, making this even easier.