private bool CheckSwipe(UTouch touch) { if (_points.Length < 2) { return(false); } float idealDistance = Vector2.Distance(startPoint, endPoint); float idealDistanceCm = idealDistance / _screenPixelPerCm; if (idealDistanceCm < _minDistanceCm) { return(false); } ElpasedTime = Time.time - _startTime; SwipeVelocity = idealDistance / ElpasedTime; Vector2 dir = (endPoint - startPoint).normalized; float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; if (angle < 0) { angle = 360 + angle; } angle = 360 - angle; if (angle >= 225f && angle <= 315f) { Direction = ESwipeDirection.Up; } else if (angle >= 135f && angle <= 225f) { Direction = ESwipeDirection.Left; } else if (angle >= 45f && angle <= 135f) { Direction = ESwipeDirection.Down; } else // angle >= 315f && angle <= 45f { Direction = ESwipeDirection.Right; } return(true); }
internal void Recognize(Array <UTouch> touches) { for (int i = touches.Length - 1; i >= 0; i--) { UTouch touch = touches[i]; switch (touch.phase) { case TouchPhase.Began: if (OnTouchBegan(touches) && this.Order > 0) { int removedTouches = 0; for (int j = touches.Length - 1; j >= 0; j--) { if (touches[j].phase == TouchPhase.Began) { touches.Erase(j); removedTouches++; } } if (removedTouches > 0) { i -= (removedTouches - 1); } } break; case TouchPhase.Moved: OnTouchMoved(touches); break; case TouchPhase.Stationary: OnTouchStay(touches); break; case TouchPhase.Canceled: case TouchPhase.Ended: OnTouchEnded(touches); break; } } }
public override void OnTouchEnded(Array <UTouch> touches) { if (state == EState.Began && Time.realtimeSinceStartup <= _touchBeganTime + _maxDurationForTaps) { ++_prformedTapsCount; if (_prformedTapsCount == numOfTapsRequired) { UTouch primary = PrimaryTouch; if (primary != null) { startPoint = primary.startPosition; endPoint = primary.position; } state = EState.Recognized; } } else { state = EState.FailedOrEnded; } }