Author Topic: Cleanly filter input events for all but one panel?  (Read 4602 times)

drjeats

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 13
    • View Profile
Cleanly filter input events for all but one panel?
« on: July 09, 2014, 05:32:59 PM »
I'm making a MessageBox type thing that I can toss up at the user at any time, so I'm looking for a way to have it consume all input events until dismissed.

Giving it a giant collider to cover all the other UI seemed like a solid bet:

http://www.tasharen.com/forum/index.php?topic=894.0

But that doesn't quite work since UICamera selects only the first visible hit (UICamera.cs:651 in the 3.6.7 asset store release), and this is supposed to be a little message box appearing over a larger panel.

If it were a matter of life and death, I could go and collect every other UI collider and temporarily disable them, but it seems like it would be easier to hack a DontCheckIfVisible flag into UICamera rather than try to manage an ever-changing list of UI colliders.

Is there a nicer way to get this done?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Cleanly filter input events for all but one panel?
« Reply #1 on: July 09, 2014, 05:47:32 PM »
Create a new panel, add a big widget with a collider to it, then add your message dialog on top so that it's in front of the background widget.

drjeats

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Cleanly filter input events for all but one panel?
« Reply #2 on: July 09, 2014, 06:13:30 PM »
If I've understood you correctly, that's what's not working for me. MessageBox is its own UIPanel. I tried a few other combinations as well to no avail:

  1. My first attempt:
  2. > UIRoot
  3.     > UICamera
  4.         > GameUIHierarchyInHere
  5.         > MessageBox (UIPanel)
  6.             > MessageBoxWidgets
  7.             > BigCollider(UIWidget, BoxCollider)
  8.  
  9.  
  10. Tried these after your reply:
  11.  
  12. > UIRoot
  13.     > UICamera
  14.         > GameUIHierarchyInHere
  15.         > MessageBox (UIPanel)
  16.             > MessageBoxWidgets
  17.             > UIPanel
  18.                 > BigCollider(UIWidget, BoxCollider)
  19.  
  20. > UIRoot
  21.     > UICamera
  22.         > GameUIHierarchyInHere
  23.         > MessageBox (UIPanel)
  24.             > BigCollider(UIWidget, BoxCollider)
  25.             > UIPanel
  26.                 > MessageBoxWidgets


It specifically seems to fail this check in UIPanel.IsVisible(Vector3 worldPos): if (pos.x < mMin.x) return false; (line 774)

I also made sure to adjust both the depth and the Z so BigCollider was clear out in front of the game UI.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Cleanly filter input events for all but one panel?
« Reply #3 on: July 10, 2014, 08:09:03 PM »
UIRoot (panel depth 0)
- UICamera
- GameUI
- MessageBox panel (panel depth 1)
-- Big widget with a collider (widget depth 0)
-- Message box widgets (widget depth 1+)

drjeats

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Cleanly filter input events for all but one panel?
« Reply #4 on: July 17, 2014, 04:35:04 PM »
That's the same as my first attempt. Have you tried this recently? (or was this fixed in the latest 3.6.8?)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Cleanly filter input events for all but one panel?
« Reply #5 on: July 18, 2014, 05:13:58 AM »
Yes, it works fine. This functionality hasn't changed in a while. Note that Z should not be modified. Only depth.

drjeats

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Cleanly filter input events for all but one panel?
« Reply #6 on: November 12, 2014, 11:57:41 AM »
I kinda just let this sit for a few months since I had other things to work on, but I stumbled onto the solution today.

I changed the clipping at random and suddenly the big collider widget started blocking correctly. For reasons unknown, the UIPanel on my message box had a serialized mClipping value of 2, and I see that you've since taken 2 out of the UIDrawCall.Clipping enum.

This project has been through a few NGUI upgrades, so I imagine this isn't a common problem, but if other people have encountered a similar bug, check your UIPanel's clipping setting.

[EDIT] To clarify, explicitly re-setting the clipping to None (0) in the panel made it all work.

[EDIT2] I notice that I have to make the alpha of this mega-sprite at least 1 though, it can't be zero. Is there something I can do to make the UICamera not discard 0-alpha sprites for hit testing?

This is NGUI 3.7.6, Unity 4.5.
« Last Edit: November 12, 2014, 12:17:30 PM by drjeats »