Support => NGUI 3 Support => Topic started by: Kerozard on August 07, 2014, 02:54:52 AM
Title: [Solved] How to catch a click outside of a collider?
Post by: Kerozard on August 07, 2014, 02:54:52 AM
I am trying to create some kind of a tabbed display (the filter window in the screenshot). I want to hide it if the user clicks somewhere outside the filter window so i tried using
void OnSelect(bool isSelected)
{
if(!isSelected)
{
Manager.View.FadeOut(this.gameObject, 0.2f);
}
}
The problem are the child elements that also have colliders. clicking on one of them sends an OnSelect(false) to the window itself and it gets hidden. I don't really want to go down the route of keeping track of all the window states and comparing them to mouse positions. there has to be an easier way. I was thinking about using UICamera.fallThrough but that way I could only hide it when the click event is not caught by any other object.
Any ideas how to get the desired functionality?
(http://i.imgur.com/ptmp5hx.png)
Title: Re: How to catch a click outside of a collider?
Post by: ArenMook on August 07, 2014, 04:09:40 AM
Set a UICamera.genericEventHandler. When you click on something, check -- is it still a part of your window's hierarchy? If so, do nothing. If no, hide it.
Title: Re: How to catch a click outside of a collider?
Post by: Kerozard on August 07, 2014, 04:27:28 AM
I was just composing a reply that this was the solution I came up with by scouring your forum. ;)
But thank you for your timely response. The only thing I don't like about it is, that I set the EventListener when the user clicks on the filter button. But since the button itself is not part of the filter window hierarchy, it gets hidden again right away. I am now invoking the listener with a 0.1 second delay and I don't feel that is a very elegant solution.