c# - Handle touches not started on the UI -
i seek way handle touches not start on ui elements in unity engine.
the purpose of rotating, panning , zooming in on "map" (it shall called on). if touch down event on of ui elements shall handled ui element instead of map.
i think 1 such example google's maps android application.
i have tried several solutions:
mouse events - combines of touches single one
input.touches - not know how find out if touch should handled ui element instead (i if possible not use "if"s check if touch on ui element might prove real performance issue)
i seek way handle touches not start on ui elements in unity engine ...but if touch down event on of ui elements shall handled ui element instead of map.
the ispointerovergameobject
function used simplify this. if returns false, panning, rotation. if returns true mouse on ui element. better , easier use use boolean variable modifed every ui element. use onpointerclick
detect events on ui(map). see this more information.
void update() { checktouchonscreen(); } void checktouchonscreen() { #if unity_ios || unity_android || unity_tvos if (input.touchcount > 0 && input.gettouch(0).phase == touchphase.began) { //make sure finger not on ui element if (!eventsystem.current.ispointerovergameobject(input.gettouch(0).fingerid)) { onscreentouched(); } } #else // check if left mouse button clicked if (input.getmousebuttondown(0)) { //make sure finger not on ui element if (!eventsystem.current.ispointerovergameobject()) { onscreentouched(); } } #endif } void onscreentouched() { debug.log("touched on screen there no ui"); //rotate/pan/zoom camera here }
i if possible not use "if"s check if touch on ui element might prove real performance issue
there no other way without if
statement. simple answer above requires it. doesn't affect performance.
Comments
Post a Comment