Author Topic: Allow UIButton and UIInput to receive a click.  (Read 1748 times)

zippo227

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
Allow UIButton and UIInput to receive a click.
« on: September 16, 2016, 09:44:56 AM »
I have a UIButton that interacts with my custom UIInput. When the user clicks outside of the UIInput, I want to hide that UIButton, unless, the click was on the UIButton. It's pretty important for the functionality of my input. I don't want to have all the extra buttons showing unless the user currently is interacting with the input.

protected override void OnSelect(bool isSelected)
{
      base.OnSelect(isSelected);

      extraButton.SetActive(isSelected);
}

The problem is, the UIInput receives the click first, which disables the UIButton and prevents it from ever being able to receive a click. I've tried setting alpha to 0 and scale to 0, and other such tricks, but nothing seems to work. How can I implement this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Allow UIButton and UIInput to receive a click.
« Reply #1 on: September 17, 2016, 12:25:31 AM »
Don't listen to the OnSelect notification. Subscribe to UICamera.onSelect instead. It's a generic delegate that will be called regardless of what's selected, letting you decide what happens.

zippo227

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: Allow UIButton and UIInput to receive a click.
« Reply #2 on: September 21, 2016, 01:46:03 PM »
Thanks for this! It worked great. I set a tag on the game objects that I want to be able to click and check that tag in the OnSelect delegate.

(When I tried to post the code I wrote as an example I got this error. "You don't have permission to access /forum/index.php on this server"
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.)  :o

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Allow UIButton and UIInput to receive a click.
« Reply #3 on: September 23, 2016, 03:45:53 PM »
Yeah the forum here seems to reject some code segments that it believes may be database queries or something...

zippo227

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: Allow UIButton and UIInput to receive a click.
« Reply #4 on: September 23, 2016, 05:28:05 PM »
OK here's a link to a pastebin of it.

http://pastebin.com/cjbJFGg0