Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: JasonABentley on May 14, 2013, 09:47:44 AM

Title: UIButtonTween and IsEnabled
Post by: JasonABentley on May 14, 2013, 09:47:44 AM
Situation:
I have a button that I want to enable/disable often. I was using UIButton to do this and it functions correctly.
The 'button' has multiple labels/sprites/sliced sprites, but UIButton only darkens the first in the hierarchy (usually the background).

What I want:
I would like ALL the parts to darken/lighten.

What I tried:
I switched to an UIButtonTween and put TweenColor on all the elements.  I got this to function fine OnHover and OnPress, but I only want this to happen when I set the IsEnabled flag.

Maybe I'm just missing something simpler? Any suggestions?
Title: Re: UIButtonTween and IsEnabled
Post by: ArenMook on May 14, 2013, 12:05:18 PM
Just attach multiple UIButton components.
Title: Re: UIButtonTween and IsEnabled
Post by: JasonABentley on May 14, 2013, 01:07:43 PM
I do use multiple UIButtonTweens to get it to go back and forth.

What I do not know how to do is: I only want this to happen when I set IsEnabled to true/false.

IT gives me options for Activated but I have no idea what that is or how to use it.
Title: Re: UIButtonTween and IsEnabled
Post by: wizardsmoke on May 14, 2013, 01:17:09 PM
Don't use UIButtonTween.  Just use UIButton.  You can have multiple instances of UIButton on the same game object (your button with the collider).  Then just set the Tween Target for each of the UIButton instances each of the elements that you want to change. (See attached screenshot)

Hope this helps.
Title: Re: UIButtonTween and IsEnabled
Post by: JasonABentley on May 14, 2013, 01:57:25 PM
AHHHH!


Excellent, thank you.
Title: Re: UIButtonTween and IsEnabled
Post by: JasonABentley on May 14, 2013, 02:58:52 PM
So I tried this in the same way I saw in your picture (attached a screen shot).

In my code I do this and it says that each UIButton is being disabled, but still only the first image is being tween-ed.

  1. foreach( UIButton button in ButtonObject.GetComponentsInChildren<UIButton>() )
  2. {
  3.         print ( "Button fade color: " + button.disabledColor );
  4.         button.isEnabled = false;
  5. }

Which ever UIButton is first on the object is the one that gets run, the other two don't seem to run.


NOTE: This seems to work fine on Hover and Click for all 3 UIButtons, but IsDisabled doesn't seem to be working correctly
Title: Re: UIButtonTween and IsEnabled
Post by: wizardsmoke on May 14, 2013, 03:12:14 PM
It looks like you'll need to add
  1. button.UpdateColor(false, false);
to that foreach because
  1. button.isEnabled = false;
only triggers the tween if the collider is currently enabled and the first one will disable the collider.

By the way, I found this information by simply opening the UIButton script and seeing exactly what it does.  I find it useful to open NGUI scripts (or those of other plugins) that I am having problems with.
Title: Re: UIButtonTween and IsEnabled
Post by: JasonABentley on May 14, 2013, 03:24:28 PM
Unfortunately, I was already looking at UpdateColor and had skipped the more important IsEnabled colider check.