Author Topic: UIButton script missing update color  (Read 4904 times)

marasto

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
UIButton script missing update color
« on: May 06, 2012, 06:52:05 AM »
Hi

little issue regarding color tween.
I created a panel that contains a button with a UIButton script component. The panel also contains a component that programmatically change the status of the button based on some conditions.
The first time the panel become active all works as expected and the button state is "disabled" (color changed and collider is not active).
However, if I disable the panel and the re-enable it again, the button doesn't change color.

  1. public bool isEnabled
  2.         {
  3.                 get
  4.                 {
  5.                         Collider col = collider;
  6.                         return col && col.enabled;
  7.                 }
  8.                 set
  9.                 {
  10.                         Collider col = collider;
  11.                         if (!col) return;
  12.  
  13.                         [b]if (col.enabled != value)[/b]
  14.                         {
  15.                                 col.enabled = value;
  16.                                 UpdateColor(value, false);
  17.                         }
  18.                 }
  19.         }
  20.  

The condition if (col.enabled != value) always fails because the collider state is not changed (the state still is not enabled after the panel has been activate again) so the color transform is not triggered.

I can change the code and remove that condition but It is not what I would like to do. Alternatively I can change the collider state to enable first and then invoke the isEnabled method. A bit tricky to be honest.

Alternative ?

Thank
Cristian

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton script missing update color
« Reply #1 on: May 06, 2012, 08:55:20 AM »
Why would the button need to change color the second time? It should be already looking disabled.

marasto

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: UIButton script missing update color
« Reply #2 on: May 07, 2012, 12:02:11 PM »
Because it doesn't looking disabled at all.
This is true only the first time the button is created. if at that time the collider is not enable the color is correct.
But if I disable the panel (or the button) and the I re-enable it again the color is wrong. The button is still in "disabled" state (the collider isn't enabled) but no color transform has been applied (or maybe someone else has reset it) and visually it is like an active button.

There is no reason in fact to change the color a second time if the collider state is not changed. However if the color has been changed (due to a bug, of course) but the collider state is not, forcing the current state doesn't change the color (because of the check) 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton script missing update color
« Reply #3 on: May 07, 2012, 02:58:27 PM »
Ah I see. I'll tweak it a bit for you and see if I can make it work for the next update.