Author Topic: 3.5.5 Issues with UIButton and UIButtonColor  (Read 1725 times)

AtomicBob

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 69
    • View Profile
3.5.5 Issues with UIButton and UIButtonColor
« on: April 03, 2014, 05:46:43 PM »
Just upgraded to get around a bug with tweening (similar to http://www.tasharen.com/forum/index.php?topic=7392) and now I'm having a problem with UIButtons.

UIButtons have a nasty habit changing the sprite in unexpected ways. If you set the sprite.spriteName from code, it doesn't always take effect and sometimes it changes back and forth between sprites on mouseover. If you set button.normalSprite similar things happen. If you set both, it seems to work ok.

It should be pretty easy to reproduce, but if not I'll email a text case.

Also, it'd be nice to be able to use UIButton for the color and OnClick delegate without using 'image button' functionality at all. I know I could use EventTrigger and UIButtonColor separately, but it's nice to have it all on once script and EventTriggers are kinda large visually for just OnClick.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 3.5.5 Issues with UIButton and UIButtonColor
« Reply #1 on: April 03, 2014, 08:35:35 PM »
Try changing UIButton.normalSprite to this:
  1.         public string normalSprite
  2.         {
  3.                 get
  4.                 {
  5.                         if (!mInitDone) OnInit();
  6.                         return mNormalSprite;
  7.                 }
  8.                 set
  9.                 {
  10.                         if (mSprite != null && !string.IsNullOrEmpty(mNormalSprite) && mNormalSprite == mSprite.spriteName)
  11.                         {
  12.                                 mNormalSprite = value;
  13.                                 SetSprite(value);
  14.                         }
  15.                         else
  16.                         {
  17.                                 mNormalSprite = value;
  18.                                 if (mState == State.Normal) SetSprite(value);
  19.                         }
  20.                 }
  21.         }
I'm guessing you never set the hover sprite, and it's currently in a hover state, so although you changed the normal sprite, it believes it's in the hover state so it doesn't change anything.

AtomicBob

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 69
    • View Profile
Re: 3.5.5 Issues with UIButton and UIButtonColor
« Reply #2 on: April 04, 2014, 09:58:57 AM »
You are correct, the hover sprite was never set because I'm not using the 'image button' functionality. It wasn't in the hover state, just normal.

In any case, is seems to have worked. Thanks.

You still can't set the sprite directly, since the button will override it. I'm guessing we're stuck with that?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 3.5.5 Issues with UIButton and UIButtonColor
« Reply #3 on: April 04, 2014, 10:27:38 PM »
The button keeps a cached value, so when you want to change the sprite do it via UIButton.normalSprite rather than changing the sprite directly.