Author Topic: UIButton multiple tween target on Color Change.  (Read 14580 times)

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: UIButton multiple tween target on Color Change.
« Reply #15 on: August 20, 2013, 01:00:50 AM »
I would suggest the following fix for updating other UIButton script color

  1. [AddComponentMenu("NGUI/Interaction/Button")]
  2. public class UIButton : UIButtonColor
  3. {
  4.  
  5.         public bool isEnabled
  6.         {
  7.                 get
  8.                 {
  9.                         Collider col = collider;
  10.                         return col && col.enabled;
  11.                 }
  12.                 set
  13.                 {
  14.                         Collider col = collider;
  15.                         if (!col) return;
  16.                        
  17.                         if (col.enabled != value)
  18.                         {
  19.                                 col.enabled = value;
  20.                                
  21.                                 UIButton[] buttons = this.gameObject.GetComponentsInChildren<UIButton>();
  22.                                 for (int i = 0; i < buttons.Length; ++i)
  23.                         buttons[i].UpdateColor(value, false);
  24.                         }
  25.                 }
  26.         }

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: UIButton multiple tween target on Color Change.
« Reply #16 on: August 20, 2013, 08:59:47 PM »
ArenMook, could you add this to the release

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton multiple tween target on Color Change.
« Reply #17 on: August 21, 2013, 10:20:35 AM »
No I can't. What if you have more than one button script in the hierarchy, and you don't want this behaviour? Forcing it is a bad idea.

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: UIButton multiple tween target on Color Change.
« Reply #18 on: August 21, 2013, 12:57:07 PM »
sorry, it should be in the same level
  1.  
  2.                 UIButton[] buttons = this.gameObject.GetComponents<UIButton>();
  3.                 for (int i = 0; i < buttons.Length; ++i)
  4.                         buttons[i].UpdateColor(value, false);
  5.  


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton multiple tween target on Color Change.
« Reply #19 on: August 22, 2013, 11:33:52 AM »
That's more reasonable, but honestly if you need this kind of functionality you should just create a custom UIButton class for yourself.

imperso

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: UIButton multiple tween target on Color Change.
« Reply #20 on: June 11, 2015, 06:25:49 AM »
Could somebody provide a working setup of such button?
Currently my button contains two overlapping sprites:

- UIButton with Collider
-- UISprite
-- UISprite

TweenTarget was set to the same GameObject with UIButton but is always automatically reset to None.
TweenColor doesn't work at all.

How should I rework my setup to make the button change color of each sprite it consists of?
« Last Edit: June 11, 2015, 06:43:44 AM by imperso »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton multiple tween target on Color Change.
« Reply #21 on: June 11, 2015, 06:46:11 AM »
UIButton's tween target should point to one of the sprites, not itself.

imperso

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: UIButton multiple tween target on Color Change.
« Reply #22 on: June 11, 2015, 08:37:08 AM »
Yes, but my button consists of two overlapping sprites, and I need the button to change hover color of both of them, not just one. Is there any layout to this without creating custom UIButton class?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton multiple tween target on Color Change.
« Reply #23 on: June 11, 2015, 09:18:09 AM »
Just attach two UIButton scripts. One pointing to the first sprite, the other button pointing to the second sprite.

imperso

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: UIButton multiple tween target on Color Change.
« Reply #24 on: June 11, 2015, 10:43:31 AM »
Thanks, I figured it out.
The problem is - my sprites overlap. So if I click the area of overlapping, my button technically fires twice.

EDIT: Overlapping is not the case - it seems that such button always fires twice.

EDIT2: Found some solution by adding UIButtonColor and pointing it to the second sprite (first one is already connected to the main UIButton).
Alas, it seems this component is deprecated (NGUI suggests me "to upgrade to a Button").
« Last Edit: June 11, 2015, 10:56:10 AM by imperso »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton multiple tween target on Color Change.
« Reply #25 on: June 12, 2015, 08:03:25 AM »
Button fires twice? Only one button script should have the event delegates set. Second should be used only for color changes.

imperso

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: UIButton multiple tween target on Color Change.
« Reply #26 on: June 12, 2015, 01:08:11 PM »
Yep, eventually this was my mistake.