public virtual void TouchRelease(Vector2 _touchScreenLocation) { touchWorldPoint = cameraRef.ScreenToWorldPoint(_touchScreenLocation); touchScreenCoordinate = _touchScreenLocation; endTouchLocation = _touchScreenLocation; deltaRelease = endTouchLocation - startTouchLocation; _axisValue.x = 0; _axisValue.y = 0; touchInfo.touchWorldPoint = touchWorldPoint; touchInfo.touchScreenCoordinate = touchScreenCoordinate; touchInfo.endTouchLocation = endTouchLocation; touchInfo.deltaRelease = deltaRelease; OnTouchRelease?.Invoke(touchInfo); if (touchScreenRatio.x < .5f) { SidePress(EDirections.LEFT); } if (touchScreenRatio.x > .5f) { SidePress(EDirections.RIGHT); } }
private void Update() { #if UNITY_EDITOR if (UInput.GetMouseButtonDown(0)) { _lastMousePosition = UInput.mousePosition; TouchInputEvent tie = new TouchInputEvent() { touchPos = _lastMousePosition, touchDelta = Vector3.zero }; OnTouchStart?.Invoke(tie); } else if (UInput.GetMouseButton(0)) { TouchInputEvent tie = new TouchInputEvent() { touchPos = UInput.mousePosition }; tie.touchDelta = tie.touchPos - _lastMousePosition; _lastMousePosition = tie.touchPos; OnTouchStay?.Invoke(tie); } else if (UInput.GetMouseButtonUp(0)) { TouchInputEvent tie = new TouchInputEvent() { touchPos = UInput.mousePosition, touchDelta = Vector3.zero }; OnTouchRelease?.Invoke(tie); } #elif UNITY_ANDROID if (UInput.touchCount > 0) { // Only polling touch 0 Touch touch = UInput.GetTouch(0); TouchInputEvent tie = new TouchInputEvent() { touchPos = touch.position, touchDelta = touch.deltaPosition }; // Send the respective event depending on touch phase state switch (touch.phase) { case TouchPhase.Began: OnTouchStart?.Invoke(tie); break; case TouchPhase.Moved: case TouchPhase.Stationary: OnTouchStay?.Invoke(tie); break; case TouchPhase.Canceled: case TouchPhase.Ended: OnTouchRelease?.Invoke(tie); break; } } #endif }