Пример #1
0
    private bool CheckForSwipeStart(TouchEvent touchEvent)
    {
        if (touchEvent.GetCurrentState() != TouchPhase.Moved && touchEvent.GetCurrentState() != TouchPhase.Ended)
        {
            return(false);
        }

        Vector2 totalDistance = touchEvent.GetTouchEventPositionDelta();

        return(totalDistance.magnitude >= minSwipeDistance);
    }
Пример #2
0
    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);
    }
Пример #3
0
 private bool IsTap(TouchEvent touchEvent)
 {
     return(touchEvent.GetTouchEventTime() <= maxTapTime &&
            touchEvent.GetTouchEventPositionDelta().magnitude < maxTapDistance);
 }