Tuesday, December 10, 2013

Unity3D 2D UI Click-Through Issues

I have message box and dialog box classes for use in Unity3D that need to act 'modally' (but not truly modal) at times, and one of the problems I've had was preventing the mouse-clicks/touches from hitting controls under the controls in the message/dialog boxes.

You'd think that the Unity3D system would already take care of this, but apparently there is some behind the scenes issue that is non-trivial to resolve (otherwise the Unity3D devs would have knocked this out a looooong time ago.)

Anyhow, I found a simple solution today that works for me (until I find it fails on iOS - fingers crossed that it doesn't!)

When my OnGUI call gets to my message/dialog box, the message/dialog box simple creates TWO full screen transparent GUI.Window objects.  The first one calls an empty method, the second one calls the method that draws the controls of the message/dialog box.

I'd tried this previously, but only created one GUI.Window - hoping (vainly) that having the window under the message/dialog box would prevent clicks from making it through.  Oddly enough, it sort of worked, it prevented clicks that were on the message/dialog box controls from going through, but you could still click anywhere on the rest of the screen and cause havoc...

Anywho - I'll have to test have badly this affects performance (it shouldn't really as the both windows entire areas have an alpha of 0.0.)

No comments:

Post a Comment