Hello Guest

Author Topic: Disabling a UIButton  (Read 3842 times)

habitoti

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 82
    • View Profile
    • Rombos Homepage
Disabling a UIButton
« on: January 03, 2014, 12:10:06 pm »
Hi,

I hope this is not a completely stupid question because maybe I just oversaw something obvious (again ;-):
How do I "officially" disable a custom button? I have a button type with my own button behavior (actually mostly copied from the tk2d toggle button). I use the event settings from the tk2dUIItem piece of the button (because I like the inspector), and this always fires that click event, even if I disable that component (from within my button behavior component). Looking into the code, there is no OnDisable implemented in tk2dUIItem to take out the onClick (etc.) events (like it is the case for the behavior components like Toggle Button etc.). So how can I make it ignore clicks for a controlled period?
Another option would be to hanlde the click myself in my behavior component, but I haven't found out how to use your nice SendMessage inspector in editor ;-) Would that be possible at all easily?

Thanks, habitoti
Checkout our homepage or visit the Rombos blog.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Disabling a UIButton
« Reply #1 on: January 03, 2014, 12:17:58 pm »
You can disable it by disabling the collider. Everything revolves around the collider getting hit in the ray cast, so disabling that will mean the button will be unresponsive.

habitoti

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 82
    • View Profile
    • Rombos Homepage
Re: Disabling a UIButton
« Reply #2 on: January 03, 2014, 12:39:51 pm »
That's actually what I did so far, but it felt somehow "inelegant" and I thought I simply missed the right way to do it. Something like a SetEnabled(true/false) that makes any button act accordingly.

Thanks anyway, then I leave it that way.

Regards, habitoti
Checkout our homepage or visit the Rombos blog.