/// <summary> /// UIをタッチしているかを返す /// </summary> /// <param name="touchID"></param> /// <returns></returns> public bool IsUITouch(int touchID) { PointerEventData pointer = new PointerEventData(EventSystem.current); #if UNITY_IOS || UNITY_ANDROID Touch touch = new Touch(); for (int i = 0; i < Input.touches.Length; i++) { if (Input.touches[i].fingerId == touchID) { touch = Input.touches[i]; pointer.position = touch.position; List <RaycastResult> result = new List <RaycastResult>(); EventSystem.current.RaycastAll(pointer, result); //レイヤーでUIかを判定して整理する for (int j = 0; j < result.Count; j++) { if (SlasheonUtility.IsAnyLayerNameMatch(result[i].gameObject, SlasheonUtility.UILayer)) { //Debug.Log("UITouch:True id : " + touchID); return(true); } } } } //Debug.Log("IsUITouch:False :: id : " + touchID); return(false); #else pointer.position = Input.mousePosition; List <RaycastResult> result = new List <RaycastResult>(); EventSystem.current.RaycastAll(pointer, result); //レイヤーでUIかを判定して整理する for (int i = 0; i < result.Count; i++) { //一致していなければリストから除く if (SlasheonUtility.IsAnyLayerNameMatch(result[i].gameObject, SlasheonUtility.UILayer)) { return(true); } } return(false); #endif }
/// <summary> /// Raycastで取得したUIを返す /// </summary> /// <returns></returns> public RaycastResult GetRaycastResult(int touchID) { PointerEventData pointer = new PointerEventData(EventSystem.current); #if UNITY_IOS || UNITY_ANDROID Touch touch = new Touch(); for (int i = 0; i < Input.touches.Length; i++) { if (Input.touches[i].fingerId == touchID) { touch = Input.touches[i]; pointer.position = touch.position; List <RaycastResult> result = new List <RaycastResult>(); EventSystem.current.RaycastAll(pointer, result); List <int> removeNums = new List <int>(); //レイヤーでUIかを判定して整理する for (int j = 0; j < result.Count; j++) { //一致していなければリストから除く if (SlasheonUtility.IsAnyLayerNameMatch(result[j].gameObject, SlasheonUtility.UILayer)) { removeNums.Add(i); } } for (int k = removeNums.Count - 1; k > 0; k--) { result.RemoveAt(k); } if (result.Count > 0) { return(result[0]); } else { return(new RaycastResult()); } } } return(new RaycastResult()); #else pointer.position = Input.mousePosition; List <RaycastResult> result = new List <RaycastResult>(); EventSystem.current.RaycastAll(pointer, result); List <int> removeNums = new List <int>(); //レイヤーでUIかを判定して整理する for (int i = 0; i < result.Count; i++) { //一致していなければリストから除く if (SlasheonUtility.IsAnyLayerNameMatch(result[i].gameObject, SlasheonUtility.UILayer)) { removeNums.Add(i); } } for (int i = removeNums.Count - 1; i > 0; i--) { //Debug.Log("取り除きます " + i); result.RemoveAt(i); } if (result.Count > 0) { return(result[0]); } else { return(new RaycastResult()); } #endif }