1

I've been playing around with UIToolkit, and it's awesome. Though my clicks pass through the buttons, so when clicking the UI my raycast also starts. Is there a way to check if a click/touch is on the GUI?

Edit: I'm using Prime31's UIToolkit

Solved:

foreach (var touchable in _gui.touchableSprites) {
    if ( !touchable.hidden && touchable.hitTest(new Vector2(clickPos.x, Screen.height - clickPos.y)) ) return;
}

Thanks.

Kay
  • 12,918
  • 4
  • 55
  • 77
The Oddler
  • 6,314
  • 7
  • 51
  • 94
  • note that in modern times you just do this http://answers.unity3d.com/questions/784617/how-do-i-block-touch-events-from-propagating-throu.html – Fattie Feb 15 '16 at 17:20

1 Answers1

2

Assuming you're using prime31's UIToolkit, take a look at the UIToolkit.cs(lines 81-95) ) script The author works an example showing how to handle highlighting his TouchableSprites. The same functionality can be adapted to doing a MouseOver event. I'm not sure if the author has added this functionality since 2011, I've not used UIToolkit in awhile.

Alternatively you can modify all of your ray tracing to return if the first layer hit is "UILayer" (UIToolkit's layer).

A third method, one that I use, is to create a global GUI element manager that stores a list of all GUI rects. When I add a new ray tracing function I call my manager class to see if the mouse cursor is contained in any GUI rect (there is a bit more sophistication that merges overlapping rects), if so, the ray trace is skipped.

Jerdak
  • 3,997
  • 1
  • 24
  • 36
  • 1
    Thanks, this pushed me in the right direction! I added the exact code to my main post for anyone else who's looking for the same thing. – The Oddler Nov 26 '12 at 10:27