Author Topic: UIImageButton Disabled Sprite Image?  (Read 10816 times)

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
UIImageButton Disabled Sprite Image?
« on: July 18, 2012, 06:56:20 PM »
Hi,

Is there a way to display an image when the button is in a disabled state? I see:
normalSprite
hoverSprite
pressedSprite

I was hoping for
disabledSprite


Also, did I read correctly that the way to disable a button (still visible but no longer accepting input) is to disable the collider component?

Cheers,

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIImageButton Disabled Sprite Image?
« Reply #1 on: July 18, 2012, 07:12:29 PM »
Standard button has a disabled state. Image button does not. For the image button, simply place a sprite you want the button to look like when it's disabled in the same place as the button, and arrange its depth so that it's behind the button. Then when you "disable" the button, you will disable the game object the button is on, and enable your sprite instead.

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: UIImageButton Disabled Sprite Image?
« Reply #2 on: July 30, 2012, 02:28:46 AM »
Hi Aren,

I found it easier to edit the UIImageButton script ad inspector to add a disabled sprite / behaviour. Would you like it for nGUI?

Implementation details:
  • When disabled is set to true, the disabledSprite is displayed and the hover and click events are ignored.
  • When disabled is set to False, it properly figures out if the hover or normal sprite is initially displayed.
  • The inspector has a "Disabled State" toggle in case the button needs to begin in a disabled state. This updates in Edit mode keeping with nGUI's WYSIWYG

WDYT?

Cheers.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIImageButton Disabled Sprite Image?
« Reply #3 on: July 30, 2012, 06:15:25 AM »
Sure, you can also just attach it here in case someone else has similar desires.

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: UIImageButton Disabled Sprite Image?
« Reply #4 on: July 31, 2012, 02:16:00 AM »
Here is the script and inspector.

It would be cool if your atlas sprite drop-down list would include an empty option, so once I sprite is set, it can be un-set. In the case of this button, you can just set the inactive image to anything if it isn't being used.

Please let me know if you are willing to roll this in to the next release. I know I just posted this in another spot but I really can't change 3rd part imports because doing an upgrade will wipe out custom changes. Our project has too many files to risk it. If this will remain as an attachment example, I need to refactor these to a custom type name so importing future updates won't overwrite.

Thanks again!

daveUnit9

  • Guest
Re: UIImageButton Disabled Sprite Image?
« Reply #5 on: October 04, 2012, 06:39:33 AM »
Hi Rafe,

Did you update this extension for the latest version of NGUI? I would also find it really useful but I get some errors when using it as the SpriteField interface has changed. I managed to fix all compile errors and the button briefly worked, but once I set 'disabled' to true it stopped working and hasn't worked again since! I'm new to NGUI so haven't been able to figure out a fix yet.

Thanks,
Dave

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: UIImageButton Disabled Sprite Image?
« Reply #6 on: October 04, 2012, 09:56:55 AM »
I'll have to update and see how it goes.

invitado123

  • Guest
Re: UIImageButton Disabled Sprite Image?
« Reply #7 on: February 27, 2013, 09:01:42 AM »
Did you ever get to update this?

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: UIImageButton Disabled Sprite Image?
« Reply #8 on: February 27, 2013, 05:00:32 PM »
Hi,

I do have it working. I'll dig it up and post it in the next day or two

Rafe

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 78
    • View Profile
Re: UIImageButton Disabled Sprite Image?
« Reply #9 on: March 07, 2013, 01:11:31 AM »
Hopefully I copy-&-pasted the types correctly when I renamed these files....


BehindTheStone

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 135
    • View Profile
Re: UIImageButton Disabled Sprite Image?
« Reply #10 on: March 07, 2013, 03:20:28 AM »
Do you work with PlayMaker? Even if you don't, you can do that:

You can just disable the UIImageButton-Behaviour in that certain state. I am doing it like this and it works fine.