Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Markov on October 15, 2013, 05:33:59 AM

Title: UIButton.isEnabled strage behaviour
Post by: Markov on October 15, 2013, 05:33:59 AM
How do disable and enable UIButtons now? I need btn color to be disabled color, but now it's still normal.
I'm used to disabling them like this(in 2.7x):
nextButton.GetComponent<UIButton>().isEnabled = false;

And what I see now:
(https://pp.vk.me/c312825/v312825274/4444/a5g_3EfqqmI.jpg)

Button switched off, but button's color still normal(not grey)
Title: Re: UIButton.isEnabled strage behaviour
Post by: macy on October 15, 2013, 06:44:14 PM
Try:

UIButton button = nextButton.GetComponent<UIButton>();
button.isEnabled = false;
button.UpdateColor(false, true);
Title: Re: UIButton.isEnabled strage behaviour
Post by: Markov on October 15, 2013, 07:27:41 PM
Same effect  :-[
Title: Re: UIButton.isEnabled strage behaviour
Post by: ArenMook on October 16, 2013, 02:23:10 AM
Disable its collider instead. There's a typo in isEnabled. It should be:
  1.         public bool isEnabled
  2.         {
  3.                 get
  4.                 {
  5.                         if (!enabled) return false;
  6.                         Collider col = collider;
  7.                         return col && col.enabled;
  8.                 }
  9.                 set
  10.                 {
  11.                         Collider col = collider;
  12.                         if (col != null) col.enabled = value;
  13.                         else enabled = value;
  14.                 }
  15.         }
Title: Re: UIButton.isEnabled strage behaviour
Post by: Markov on October 16, 2013, 10:20:07 AM
Thanks. It works.
But if I want to enable and disable buttons dynamicly it works only with UpdateColor(val, true)
It will be very handy if you return back enable/disable behaviour as it was in 2.7x versions.
Title: Re: UIButton.isEnabled strage behaviour
Post by: ArenMook on October 16, 2013, 01:02:58 PM
I just had a second look at this, and I retract my previous statement. There is no typo, and how it is is intentional. Furthermore, it works perfectly fine with the following test script:
  1. using UnityEngine;
  2.  
  3. public class Test : MonoBehaviour
  4. {
  5.         void Update ()
  6.         {
  7.                 if (Input.GetKeyDown(KeyCode.G))
  8.                 {
  9.                         GetComponent<UIButton>().isEnabled = !GetComponent<UIButton>().isEnabled;
  10.                 }
  11.         }
  12. }