protected override bool CanBegin(FingerGestures.IFingerList touches)
    {
        if (!base.CanBegin(touches))
        {
            return(false);
        }

        FingerGestures.Finger finger0 = touches[0];
        FingerGestures.Finger finger1 = touches[1];

        if (!FingerGestures.AllFingersMoving(finger0, finger1))
        {
            return(false);
        }

        if (!FingersMovedInOppositeDirections(finger0, finger1))
        {
            return(false);
        }

        float gapDelta = ComputeGapDelta(finger0, finger1, finger0.StartPosition, finger1.StartPosition);

        if (Mathf.Abs(gapDelta) < MinDistance)
        {
            return(false);
        }

        return(true);
    }
    protected override bool CanBegin(FingerGestures.IFingerList touches)
    {
        if (!base.CanBegin(touches))
        {
            return(false);
        }

        FingerGestures.Finger finger0 = touches[0];
        FingerGestures.Finger finger1 = touches[1];

        if (!FingerGestures.AllFingersMoving(finger0, finger1))
        {
            return(false);
        }

        if (!FingersMovedInOppositeDirections(finger0, finger1))
        {
            return(false);
        }

        // check if we went past the minimum rotation amount treshold
        float rotation = SignedAngularGap(finger0, finger1, finger0.StartPosition, finger1.StartPosition);

        if (Mathf.Abs(rotation) < MinRotation)
        {
            return(false);
        }

        return(true);
    }
示例#3
0
    protected override bool CanBegin(PinchGesture gesture, FingerGestures.IFingerList touches)
    {
        if (!base.CanBegin(gesture, touches))
        {
            return(false);
        }

        FingerGestures.Finger finger0 = touches[0];
        FingerGestures.Finger finger1 = touches[1];

        if (!FingerGestures.AllFingersMoving(finger0, finger1))
        {
            return(false);
        }

        if (!FingersMovedInOppositeDirections(finger0, finger1))
        {
            return(false);
        }

        float startGap = Vector2.SqrMagnitude(finger0.StartPosition - finger1.StartPosition);
        float curGap   = Vector2.SqrMagnitude(finger0.Position - finger1.Position);

        if (FingerGestures.GetAdjustedPixelDistance(Mathf.Abs(startGap - curGap)) < (MinDistance * MinDistance))
        {
            return(false);
        }

        return(true);
    }
    protected override GestureRecognitionState OnRecognize(PinchGesture gesture, FingerGestures.IFingerList touches)
    {
        if (touches.Count != RequiredFingerCount)
        {
            gesture.Delta = 0;

            // fingers were lifted?
            if (touches.Count < RequiredFingerCount)
            {
                return(GestureRecognitionState.Recognized);
            }

            // more fingers added, gesture failed
            return(GestureRecognitionState.Failed);
        }

        FingerGestures.Finger finger0 = touches[0];
        FingerGestures.Finger finger1 = touches[1];

        gesture.Position = 0.5f * (finger0.Position + finger1.Position);

        float curGap = Vector2.Distance(finger0.Position, finger1.Position);

        // dont do anything if both fingers arent moving
        if (!FingerGestures.AllFingersMoving(finger0, finger1))
        {
            return(GestureRecognitionState.InProgress);
        }


        float newDelta = FingerGestures.GetAdjustedPixelDistance(DeltaScale * (curGap - gesture.Gap));

        gesture.Gap = curGap;

        if (Mathf.Abs(newDelta) > 0.001f)
        {
            if (!FingersMovedInOppositeDirections(finger0, finger1))
            {
                // skip without firing event
                return(GestureRecognitionState.Failed);// GestureRecognitionState.InProgress; //TODO: might want to make this configurable, so the recognizer can fail if fingers move in same direction
            }

            gesture.Delta = newDelta;
            RaiseEvent(gesture);
        }

        return(GestureRecognitionState.InProgress);
    }
    protected override GestureState OnActive(FingerGestures.IFingerList touches)
    {
        Debug.Log("PinchGestureRecognizer OnActive count is " + touches.Count);
        if (touches.Count != RequiredFingerCount)
        {
            // fingers were lifted?
            if (touches.Count < RequiredFingerCount)
            {
                RaiseOnPinchEnd();
                return(GestureState.Recognized);
            }

            // more fingers added, gesture failed
            return(GestureState.Failed);
        }

        FingerGestures.Finger finger0 = touches[0];
        FingerGestures.Finger finger1 = touches[1];

        Position[0] = finger0.Position;
        Position[1] = finger1.Position;

        // dont do anything if both fingers arent moving
        if (!FingerGestures.AllFingersMoving(finger0, finger1))
        {
            return(GestureState.InProgress);
        }

        float newDelta = ComputeGapDelta(finger0, finger1, finger0.PreviousPosition, finger1.PreviousPosition);

        if (Mathf.Abs(newDelta) > 0.001f)
        {
            if (!FingersMovedInOppositeDirections(finger0, finger1))
            {
                return(GestureState.InProgress); //TODO: might want to make this configurable, so the recognizer can fail if fingers move in same direction
            }
            delta = DeltaScale * newDelta;

            RaiseOnPinchMove();
        }

        return(GestureState.InProgress);
    }
    protected override GestureState OnActive(FingerGestures.IFingerList touches)
    {
        if (touches.Count != RequiredFingerCount)
        {
            // fingers were lifted?
            if (touches.Count < RequiredFingerCount)
            {
                if (OnRotationEnd != null)
                {
                    OnRotationEnd(this);
                }

                return(GestureState.Recognized);
            }

            // more fingers added, gesture failed
            return(GestureState.Failed);
        }

        FingerGestures.Finger finger0 = touches[0];
        FingerGestures.Finger finger1 = touches[1];

        Position[0] = finger0.Position;
        Position[1] = finger1.Position;

        // dont do anything if both fingers arent moving
        if (!FingerGestures.AllFingersMoving(finger0, finger1))
        {
            return(GestureState.InProgress);
        }

        rotationDelta  = SignedAngularGap(finger0, finger1, finger0.PreviousPosition, finger1.PreviousPosition);
        totalRotation += rotationDelta;

        if (OnRotationMove != null)
        {
            OnRotationMove(this);
        }

        return(GestureState.InProgress);
    }
示例#7
0
    protected override GestureRecognitionState OnRecognize(TwistGesture gesture, FingerGestures.IFingerList touches)
    {
        if (touches.Count != RequiredFingerCount)
        {
            gesture.DeltaRotation = 0;

            // fingers were lifted?
            if (touches.Count < RequiredFingerCount)
            {
                return(GestureRecognitionState.Ended);
            }

            // more fingers added, gesture failed
            return(GestureRecognitionState.Failed);
        }

        FingerGestures.Finger finger0 = touches[0];
        FingerGestures.Finger finger1 = touches[1];

        gesture.Position = 0.5f * (finger0.Position + finger1.Position);

        // dont do anything if both fingers arent moving
        if (!FingerGestures.AllFingersMoving(finger0, finger1))
        {
            return(GestureRecognitionState.InProgress);
        }

        gesture.DeltaRotation = SignedAngularGap(finger0, finger1, finger0.PreviousPosition, finger1.PreviousPosition);

        // only raise event when the twist angle has changed
        if (Mathf.Abs(gesture.DeltaRotation) > Mathf.Epsilon)
        {
            gesture.TotalRotation += gesture.DeltaRotation;
            RaiseEvent(gesture);
        }

        return(GestureRecognitionState.InProgress);
    }
    protected override GestureRecognitionState OnRecognize(PinchRotateGesture gesture, FingerGestures.IFingerList touches)
    {
        if (touches.Count != RequiredFingerCount)
        {
            gesture.Delta = 0;

            // fingers were lifted?
            if (touches.Count < RequiredFingerCount)
            {
                return(GestureRecognitionState.Recognized);
            }

            // more fingers added, gesture failed
            return(GestureRecognitionState.Failed);
        }

        FingerGestures.Finger finger0 = touches[0];
        FingerGestures.Finger finger1 = touches[1];

        gesture.Position = 0.5f * (finger0.Position + finger1.Position);

        float curGap = Vector2.Distance(finger0.Position, finger1.Position);

        // dont do anything if both fingers arent moving
        if (!FingerGestures.AllFingersMoving(finger0, finger1))   // && curGap >= UnityEngine.Screen.width * 0.25f
        {
            return(GestureRecognitionState.InProgress);
        }


        float newDelta = FingerGestures.GetAdjustedPixelDistance(DeltaScale * (curGap - gesture.Gap));

        gesture.Gap = curGap;

        // if( Mathf.Abs( newDelta ) > 0.001f )
        {
            if (touches.AllMoving() && touches.MovingInSameDirection(0.35f))//&& curGap < UnityEngine.Screen.width*0.25f
            {
                EventMessageName = OnTwoFingerDrag;
                //Debug.Log("OnTwoFingerDrag rec");
                // skip without firing event
                // return GestureRecognitionState.InProgress;// GestureRecognitionState.InProgress; //TODO: might want to make this configurable, so the recognizer can fail if fingers move in same direction
            }
            else if (touches.AllMoving() && FingersMovedInOppositeDirections(finger0, finger1))
            {
                EventMessageName = EventOnPinch;
                //   Debug.Log("EventOnPinch rec");
            }
            else
            {
                //  Debug.Log("pinch rotate inProgress");
                return(GestureRecognitionState.InProgress);
            }
            gesture.LastDelta = gesture.DeltaMove;
            gesture.Delta     = newDelta;
            gesture.DeltaMove = gesture.Position - gesture.LastPos;

            // if we are currently moving, or we were still moving last frame (allows listeners to detect when the finger is stationary when MoveDelta = 0)...
            if (gesture.DeltaMove.sqrMagnitude > 0 || gesture.LastDelta.sqrMagnitude > 0)
            {
                gesture.LastPos = gesture.Position;
            }
            RaiseEvent(gesture);
        }

        return(GestureRecognitionState.InProgress);
    }