コード例 #1
0
    /// <summary>
    /// Process a gesture using start and ending positions of finger or mouse.
    /// </summary>
    private void ProcessGesture(FingerData finger, bool isHoldingScreen)
    {
        if (!finger.Enabled)
        {
            #if VERBOSE_LOGGING
            Debug.Log("Operation was cancelled by UI.");
            #endif
            return;
        }

        // Only allow gestures that weren't previously processed in the same touch.
        if (!finger.IsValidGesture)
        {
            return;
        }

        if (finger.IsSwiping && (finger.StartPoint.IsInScreenRegion(VectorMath.ScreenRegion.Left) ^ UseReverseControls))
        {
            switch (finger.GetSwipe())
            {
            case FingerData.SwipeDirection.Up:
                ExecuteEvent(onLaneJump);
                break;

            case FingerData.SwipeDirection.Down:
                ExecuteEvent(onLaneRoll);
                break;

            case FingerData.SwipeDirection.Left:
                ExecuteEvent(onLaneJump);
                break;

            case FingerData.SwipeDirection.Right:
                ExecuteEvent(onLaneRoll);
                break;

            default:
                Debug.LogError("SwipeDirection reached the default case!");
                break;
            }
            finger.Reset();
        }
        else if (!finger.CancelHoldGesture)
        {
            if (finger.StartPoint.IsInScreenRegion(VectorMath.ScreenRegion.Right) ^ UseReverseControls)
            {
                ExecuteEvent(onShoot);
                finger.Reset();
            }

            if (!isHoldingScreen)
            {
                ExecuteEvent(onHold, finger.StartPoint, finger.EndPoint);
                finger.Reset();
            }
        }

        #if VERBOSE_LOGGING
        Debug.Log(
            "A gesture was processed." +
            "     id = " + fingerId +
            ",     t = " + timeHeld.ToString("00.0000") +
            ",     SwipeDirection: " + (isSwiping ? swipeDir.ToString() : "None") +
            "\nStartPos: " + startPos.ToString() + ",  EndPos: " + endPos.ToString()
            );
        #endif
    }