private void CheckInput() { if (Input.touchCount > 0 && AbleToInput) { Touch touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { TouchStartEvent?.Invoke(touch.position); _inputSession = true; } if (_inputSession) { if (touch.phase == TouchPhase.Moved) { TouchMoveEvent?.Invoke(touch.position); } if (touch.phase == TouchPhase.Ended) { AbleToInput = false; TouchEndEvent?.Invoke(); _inputSession = false; } } } }
/// <summary> /// Обновление всех касаний. /// </summary> private static void StaticUpdate() { #if UNITY_EDITOR if (Input.GetMouseButtonDown(0)) { Touch simTouch = GetTouchFromMouse(); simTouch.phase = TouchPhase.Began; var wrapper = new TouchWrapper(simTouch); touchWrappers.Add(simTouch.fingerId, wrapper); TouchStartEvent?.Invoke(wrapper, EventSystem.current.IsPointerOverGameObject()); } if (Input.GetMouseButton(0)) { Touch simTouch = GetTouchFromMouse(); simTouch.phase = TouchPhase.Moved; touchWrappers[0].UpdateTouch(simTouch); } if (Input.GetMouseButtonUp(0)) { Touch simTouch = GetTouchFromMouse(); simTouch.phase = TouchPhase.Ended; touchWrappers[0].UpdateTouch(simTouch); TouchEndEvent?.Invoke( touchWrappers[0], EventSystem.current.IsPointerOverGameObject() ); touchWrappers.Clear(); } lastMousePos = Input.mousePosition; #endif #if UNITY_ANDROID Touch touch; for (int i = 0; i < Input.touchCount; i++) { touch = Input.GetTouch(i); if (touch.phase == TouchPhase.Began) { var wrapper = new TouchWrapper(touch); touchWrappers.Add(touch.fingerId, wrapper); TouchStartEvent?.Invoke( wrapper, EventSystem.current.IsPointerOverGameObject(touch.fingerId) ); } else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) { touchWrappers[touch.fingerId].UpdateTouch(touch); TouchEndEvent?.Invoke( touchWrappers[touch.fingerId], EventSystem.current.IsPointerOverGameObject(touch.fingerId) ); touchWrappers.Remove(touch.fingerId); } else { touchWrappers[touch.fingerId].UpdateTouch(touch); } } #endif }
public void TouchEnded(Touch touch) { TouchEndEvent?.Invoke(touch); TouchEndEvent = null; TouchStartEvent = null; TouchMoveEvent = null; TouchMoveEvent = null; }