private List <Vector2> simplifySwipeInput(TouchEvent touchEvent) { List <Vector2> simplified = new List <Vector2>(); Vector2 prevPoint = touchEvent.GetStartPosition(); simplified.Add(prevPoint); Vector2 runningDelta = Vector2.zero; foreach (TouchFrame frame in touchEvent.GetFrames()) { runningDelta += frame.GetDeltaPosition(); if (runningDelta.magnitude > minSwipeDistance) { prevPoint += runningDelta; runningDelta = Vector2.zero; simplified.Add(prevPoint); } } //if (runningDelta != Vector2.zero) //{ // simplified.Add(prevPoint += runningDelta); //} return(simplified); }
public static void DrawTouch(TouchEvent touchEvent) { Vector2 currentTouch = touchEvent.GetStartPosition(); foreach (TouchFrame frame in touchEvent.GetFrames()) { Vector2 nextTouch = currentTouch + frame.GetDeltaPosition(); Vector3 currentTouchWorld; Vector3 nextTouchWorld; TouchPositionToWorldCoords(currentTouch, out currentTouchWorld, 0.5f); TouchPositionToWorldCoords(nextTouch, out nextTouchWorld, 0.5f); Debug.Log(currentTouch); Debug.DrawLine(currentTouchWorld, nextTouchWorld, Color.red, 5f); currentTouch = nextTouch; } }
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); }