Unity 场景和UGUI raycast 分离

之前没写过场景拖拽 点击的操作,遇到了,记一下。
参考 http://www.xuanyusong.com/archives/3327?tdsourcetag=s_pctim_aiomsg

 public bool IsPointerOverUIObject()
 {
	if (EventSystem.current == null)
	    return false;
	// Referencing this code for GraphicRaycaster https://gist.github.com/stramit/ead7ca1f432f3c0f181f
	// the ray cast appears to require only eventData.position.
	PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
	eventDataCurrentPosition.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
	
	List<RaycastResult> results = new List<RaycastResult>();
	EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
	
	return results.Count > 0;
}

// 写在场景的输入检测里
// ------
if (UIBattleHelp.Instance.IsPointerOverUIObject())
{
    return;
}

你可能感兴趣的:(unity3d)