Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: docgonzzo on July 16, 2015, 12:48:37 PM

Title: Input Detection on Other NGUI Elements
Post by: docgonzzo on July 16, 2015, 12:48:37 PM
Hi guys,

This should be an easy question to answer..

I have an NGUI button with a custom script attached to it. This script needs to know if the user has clicked on any OTHER NGUI element in the scene with a box collider (i.e. other buttons etc besides itself).

I would like to be able to accomplish this without requiring references to all the other NGUI elements - only the UICamera. There should be a way to do this by having my script attached to the button detect input via the UICamera - input on other NGUI elements.

Basically when I click on this button with my custom script attached, it enters into targeting mode where the next left-click in the 3D world is evaluated for a valid target. I want to cancel this targeting mode if the user clicks on an NGUI element (with box collider) instead of the 3D world.


Cheers!

Title: Re: Input Detection on Other NGUI Elements
Post by: ArenMook on July 16, 2015, 11:00:04 PM
Your button gains focus as soon as you click on it: OnSelect(true).

It will get OnSelect(false) if you click anywhere else afterwards.
Title: Re: Input Detection on Other NGUI Elements
Post by: docgonzzo on July 17, 2015, 05:39:18 PM
YES! That's exactly what I needed. I can't believe I missed that.

Thanks!
Title: Re: Input Detection on Other NGUI Elements
Post by: docgonzzo on July 17, 2015, 07:51:11 PM
I needed to distinguish between the button unselecting due to clicking another button, vs due to clicking the background. My 3D world input is handled as NGUI fallthrough input.

Clicking the background de-selects the button but should not disable that buttons's targeting mode.

I have implemented this on my button script:

  1. void OnSelect(bool sel)
  2. {              
  3.    if (sel == false)
  4.    {
  5.        if(UICamera.hoveredObject.tag == "Untagged")
  6.               return;
  7.        targetingMode = false;
  8.  
  9.    }
  10. }

The hoveredObject.tag is always "Untagged" if you're not clicking on an NGUI button that has been assigned a tag.  Basically means I need to tag all my buttons now, which is not a big deal.
Title: Re: Input Detection on Other NGUI Elements
Post by: ArenMook on July 21, 2015, 10:59:20 AM
Clicking on the background sets the hoveredObject to be UICamera.fallThrough. If it's not set, it will be UICamera.list[0].gameObject.