Unity uGUI鼠标击穿检测

来源:互联网 发布:淘宝子账号怎么创建 编辑:程序博客网 时间:2024/05/18 03:37

uGUI没有一个标志或接口检测是否点击在了UI上,这点不太友好,不过也有解。

E.g.

Using System.EventSystem;...if (Input.touchCount > 0 || Input.GetMouseButton (0)){Vector2 point = new Vector2(Input.mousePosition.x, Input.mousePosition.y);PointerEventData eventData = new PointerEventData (EventSystem.Current);eventData.position = point;tempRaycastResultList.Clear();EventSystem.current.RaycastAll (eventData, tempRaycastResultList);return tempRaycastResultList.Count > 0;}

不像网上有些人说的,EventSystem.Current.IsPointerOverGameObject (Input.GetTouch(0).fingerId)中iOS上始终返回false,而在PC和Mac上功能都正常,能够识别是否点击在了UI上,姑且认为这是Unity的bug吧(至少Unity5.1.1f上存在)。

0 0
原创粉丝点击