Support => NGUI 3 Support => Topic started by: Shifty Geezer on January 09, 2014, 06:56:34 AM
Title: Best way to disable a widget?
Post by: Shifty Geezer on January 09, 2014, 06:56:34 AM
I have a UIToggle script to show/hide a widget that's working fine. However, the controls within that widget are still active even when hidden. I guess disabling the boxcollider is the easiest way to deactivate it, but how does one connect that behaviour in with the Toggle script?
Title: Re: Best way to disable a widget?
Post by: Shifty Geezer on January 09, 2014, 09:00:09 AM
I've found UIWidget.SetActive to en/disable child objects. I've also found UIToggledObjects which en/disables based on toggle, but that does it immediately without waiting for the transitions.
Title: Re: Best way to disable a widget?
Post by: ArenMook on January 09, 2014, 06:55:25 PM
Controls within widgets? Eh? Not sure what you mean there.
NGUITools.SetActive is what should be used to enable/disable objects. Check the "Tabs" example. It enables and disables entire pages of widgets via UIToggles to create a tabbed window.
Title: Re: Best way to disable a widget?
Post by: Shifty Geezer on January 10, 2014, 04:44:44 AM
Yeah, I got SetActive working, but that immediately disables the controls before they can fade.
I have a slider and a scrollview, and only one is active at a time. Pressing a button on one control panel disables the slider and enables the scrollview. These currently fade in/out nicely using UIToggle and smooth transition. I need to apply the NGUITools.SetActive method on completion of the automatically generated fade. That might require a manual fade tween, but I still don't understand how to use the Notify option. Dragging objects only presents a limited set of methods that can be called and I cannot call my own custom methods.
Title: Re: Best way to disable a widget?
Post by: ArenMook on January 10, 2014, 05:38:54 PM
All tweens have an onFinished delegate you can set to your custom function that will do whatever you wish inside, including calling SetActive(false). UIPlayTween also has this option built-in.
Title: Re: Best way to disable a widget?
Post by: Shifty Geezer on January 11, 2014, 12:10:57 PM
How do I get my custom function to appear in the Notify selection box? I've gone over C# and Unity tutes on delegates and looked through the UI code and can't work this out. When I drag a sprite object onto the Notify box, I don't see what makes UISprite.resizeCollider appear as an option but not other functions or custom functions.
Title: Re: Best way to disable a widget?
Post by: ArenMook on January 11, 2014, 05:44:07 PM
NGUI's EventDelegate expects a public void FuncName () signature for it to show up in the Notify list. Note the "public", void return type, and no parameters.
Title: Re: Best way to disable a widget?
Post by: Shifty Geezer on January 12, 2014, 04:51:54 AM
Yeah, I noticed that. So I added a method in the UISprite.cs script...
publicvoid TryThis(){
// an attempt at a delegate function
print ("Delegated!");
}
...but it isn't listed.
Hey, it's working!! Do I have to restart Unity or something for it to appear?? Maybe I just didn't notice it in the list? ??? Anyway, all's good now. Thanks.
Title: Re: Best way to disable a widget?
Post by: ArenMook on January 12, 2014, 05:45:09 PM
You just need to wait for the scripts to re-compile, and it will show up.