Author Topic: [Solved] How to catch a click outside of a collider?  (Read 3804 times)

Kerozard

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 17
    • View Profile
[Solved] How to catch a click outside of a collider?
« 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

  1.    
  2. void OnSelect(bool isSelected)
  3.     {
  4.         if (!isSelected)
  5.         {
  6.             Manager.View.FadeOut(this.gameObject, 0.2f);
  7.         }
  8.     }
  9.  

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?

« Last Edit: August 07, 2014, 04:51:09 AM by Kerozard »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to catch a click outside of a collider?
« Reply #1 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.

Kerozard

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: How to catch a click outside of a collider?
« Reply #2 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.