/// <summary> /// Checks if a swipe was valid and should get registered. /// </summary> /// <param name="completeSwipeVector">Vector of the swipe fro mstart to end.</param> /// <param name="swipeDirection">Direction form the swipe.</param> /// <returns>Should the swipe get registered as a swipe?</returns> private static bool IsSwipeValid(Vector2 completeSwipeVector, SwipeDirection swipeDirection) { var swipemagnitude = completeSwipeVector.magnitude; var swipeOnScreenPercentage = CalculateSwipeOnScreenPercentage(swipemagnitude); var minHorizontalSwipeLengthScreenPercentage = MobileInputModule.LoadSettings().minHorizontalSwipeLength / 100; var minVerticalSwipeLengthScreenPercentage = MobileInputModule.LoadSettings().minVerticalSwipeLength / 100; switch (swipeDirection) { case SwipeDirection.LEFT: case SwipeDirection.RIGHT: if (minHorizontalSwipeLengthScreenPercentage > swipeOnScreenPercentage.widthPercentage) { return(false); } break; case SwipeDirection.UP: case SwipeDirection.DOWN: if (minVerticalSwipeLengthScreenPercentage > swipeOnScreenPercentage.heightPercentage) { return(false); } break; } return(true); }
/// <summary> /// Checks if a tap was valid and should get registered. /// </summary> /// <param name="history">History of touch positions and their timestamps.</param> /// <returns>Should the tap get registered as a tap?</returns> private static bool IsTapValid(TouchHistory history) { var startTime = history.trace.First().Key; var endTime = history.trace.Last().Key; var duration = endTime - startTime; return(duration > MobileInputModule.LoadSettings().minTapDuration&& duration < MobileInputModule.LoadSettings().maxTapDuration); }