Author Topic: Best way to disable a widget?  (Read 8186 times)

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Best way to disable a widget?
« 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?

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Best way to disable a widget?
« Reply #1 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Best way to disable a widget?
« Reply #2 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.

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Best way to disable a widget?
« Reply #3 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Best way to disable a widget?
« Reply #4 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.

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Best way to disable a widget?
« Reply #5 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.
« Last Edit: January 11, 2014, 12:19:34 PM by Shifty Geezer »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Best way to disable a widget?
« Reply #6 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.

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Best way to disable a widget?
« Reply #7 on: January 12, 2014, 04:51:54 AM »
Yeah, I noticed that. So I added a method in the UISprite.cs script...

  1. public void TryThis(){
  2.         // an attempt at a delegate function
  3.         print ("Delegated!");
  4. }
...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.
« Last Edit: January 12, 2014, 05:15:38 AM by Shifty Geezer »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Best way to disable a widget?
« Reply #8 on: January 12, 2014, 05:45:09 PM »
You just need to wait for the scripts to re-compile, and it will show up.