예제 #1
0
    internal void recognizeTouches(List <TSTouch> touches)
    {
        for (var i = touches.Count - 1; i >= 0; i--)
        {
            TSTouch touch = touches[i];
            switch (touch.phase)
            {
            case TouchPhase.Began:
            {
                touchesBegan(touches);
                break;
            }

            case TouchPhase.Moved:
            {
                touchesMoved(touches);
                break;
            }

            case TouchPhase.Ended:
            case TouchPhase.Canceled:
            {
                touchesEnded(touches);
                break;
            }
            }
        }
    }
예제 #2
0
    internal override bool canTrigger(List <TSTouch> touches)
    {
        if (touches.Count == touchCounts)
        {
            bool result = true;
            for (int i = 0; i < touchCounts; i++)
            {
                TSTouch touch = touches[i];
                if (touch.phase != TouchPhase.Ended && touch.deltaPosition.magnitude > minMoveDistance)
                {
                }
                else
                {
                    result = false;
                }
            }

            if (result)
            {
                result = isIdentical(touches);
            }

            if (result && gestureCanTrigger != null)
            {
                return(gestureCanTrigger());
            }
            else
            {
                return(result);
            }
        }
        return(false);
    }
예제 #3
0
 void Awake()
 {
     touchesCache = new TSTouch[maxTouches];
     for (int i = 0; i < maxTouches; i++)
     {
         touchesCache[i] = new TSTouch(i);
     }
 }
예제 #4
0
    private void gestureRecognized()
    {
        TSTouch touch0 = tracingTouches[0];
        TSTouch touch1 = tracingTouches[1];

        float currentDistance = vector2Distance(touch0, touch1);

        deltaDistance = currentDistance - distance;
        distance      = currentDistance;

        emitRecognizedEvent();
    }
예제 #5
0
 internal override bool canTrigger(List <TSTouch> touches)
 {
     if (touches.Count == 1)
     {
         TSTouch touch = touches[0];
         if (touch.phase == TouchPhase.Ended && touch.deltaPosition.magnitude < maxMoveDistance)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #6
0
    internal override void touchesEnded(List <TSTouch> touches)
    {
        if (touches.Count == 1)
        {
            TSTouch touch = touches[0];
            tracingTouches.Add(touch);
            state = RecognizerState.Recognized;
            emitRecognizedEvent();
        }

        state = RecognizerState.Ended;
        end();
        reset();
    }
예제 #7
0
    private void gestureEnd()
    {
        if (state == RecognizerState.Recognized || state == RecognizerState.Began)
        {
            state = RecognizerState.Ended;
            TSTouch touch0 = tracingTouches[0];
            TSTouch touch1 = tracingTouches[1];

            float currentDistance = vector2Distance(touch0, touch1);
            deltaDistance = currentDistance - distance;
            distance      = currentDistance;

            emitEndEvent();

            end();
            reset();
        }
    }
예제 #8
0
    internal override void touchesMoved(List <TSTouch> touches)
    {
        if (touches.Count == 2)
        {
            // if (!isOpposite(touches))
            // {
            //     gestureEnd();
            // }
            if (state == RecognizerState.Possible)
            {
                state = RecognizerState.Began;

                for (int i = 0; i < 2; i++)
                {
                    TSTouch touch = touches[i];
                    tracingTouches.Add(touch);
                }

                TSTouch touch0 = tracingTouches[0];
                TSTouch touch1 = tracingTouches[1];

                startDistance = vector2Distance(touch0, touch1);
                distance      = startDistance;
                deltaDistance = 0;

                emitBeginEvent();
            }
            else if (state == RecognizerState.Began)
            {
                state = RecognizerState.Recognized;

                gestureRecognized();
            }
            else if (state == RecognizerState.Recognized)
            {
                gestureRecognized();
            }
        }
    }
예제 #9
0
    internal override bool canTrigger(List <TSTouch> touches)
    {
        if (touches.Count == 2)
        {
            bool result = true;
            for (int i = 0; i < 2; i++)
            {
                TSTouch touch = touches[i];
                if (touch.phase != TouchPhase.Ended && touch.deltaPosition.magnitude > minMoveDistance)
                {
                }
                else
                {
                    result = false;
                }
            }

            if (result)
            {
                return(isOpposite(touches));
            }
        }
        return(false);
    }
예제 #10
0
    internal override void touchesMoved(List <TSTouch> touches)
    {
        if (touches.Count == touchCounts)
        {
            // if (!isIdentical(touches))
            // {
            //     gestureEnd();
            // }
            if (state == RecognizerState.Possible)
            {
                state = RecognizerState.Began;

                for (int i = 0; i < touchCounts; i++)
                {
                    TSTouch touch = touches[i];
                    tracingTouches.Add(touch);
                }

                startPosition = midStartPosition(tracingTouches);
                position      = midPosition(tracingTouches);
                deltaPosition = midDeltaPosition(tracingTouches);

                emitBeginEvent();
            }
            else if (state == RecognizerState.Began)
            {
                state = RecognizerState.Recognized;

                gestureRecognized();
            }
            else if (state == RecognizerState.Recognized)
            {
                gestureRecognized();
            }
        }
    }
예제 #11
0
 private float vector2Distance(TSTouch t1, TSTouch t2)
 {
     return(Vector2.Distance(t1.position, t2.position));
 }