문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top