private bool CheckForSwipeStart(TouchEvent touchEvent) { if (touchEvent.GetCurrentState() != TouchPhase.Moved && touchEvent.GetCurrentState() != TouchPhase.Ended) { return(false); } Vector2 totalDistance = touchEvent.GetTouchEventPositionDelta(); return(totalDistance.magnitude >= minSwipeDistance); }
private bool CheckForSwipeEnd(TouchEvent touchEvent) { float totalDistance = touchEvent.GetTouchEventPositionDelta().magnitude; if (totalDistance >= minSwipeDistance) { Vector2 startPosition = touchEvent.GetStartPosition(); Vector2 endPosition = touchEvent.GetEndPosition(); float minLengthAllowed = totalDistance - maxSwipeVarianceFromStraightLine; float maxLengthAllowed = totalDistance + maxSwipeVarianceFromStraightLine; foreach (TouchFrame frame in touchEvent.GetFrames()) { Vector2 framePosition = frame.GetPosition(); float frameDistance = Vector2.Distance(startPosition, framePosition) + Vector2.Distance(framePosition, endPosition); if (frameDistance < minLengthAllowed || frameDistance > maxLengthAllowed) { Debug.Log("Frame distance " + frameDistance + " outside of " + minLengthAllowed + " and " + maxLengthAllowed); return(false); } } return(true); } return(false); }
private bool IsTap(TouchEvent touchEvent) { return(touchEvent.GetTouchEventTime() <= maxTapTime && touchEvent.GetTouchEventPositionDelta().magnitude < maxTapDistance); }