Пример #1
0
    /// <summary>
    /// Attempts to detect the current swipe direction.
    /// Should be called over multiple frames in an Update-like loop.
    /// </summary>
    static void DetectSwipe()
    {
        if (GetTouchInput() || GetMouseInput())
        {
            Vector2 currentSwipe = new Vector3(secondPressPos.x - firstPressPos.x, secondPressPos.y - firstPressPos.y);

            float swipeCm = currentSwipe.magnitude / dpcm;

            // Make sure it was a legit swipe, not a tap
            if (swipeCm < instance.minSwipeLength)
            {
                swipeDirection = Swipe.None;
                touchDuration += Time.deltaTime;

                if (touch.phase == TouchPhase.Ended && touchDuration < 0.2f) // making sure it only check the touch once && it was a short touch/tap and not a dragging.
                {
                    instance.StartCoroutine("singleOrDouble");
                }
                return;
            }
            else
            {
                tap           = Tap.None;
                touchDuration = 0.0f;
            }

            swipeDirection = GetSwipeDirByTouch(currentSwipe);

            if (_OnSwipeDetected != null)
            {
                _OnSwipeDetected(swipeDirection);
            }
        }
        else
        {
            swipeDirection = Swipe.None;
        }
    }