protected override GestureState OnActive( FingerGestures.IFingerList touches )
    {
        if( touches.Count != RequiredFingerCount )
        {
            // all fingers lifted - fire the tap event
            if( touches.Count == 0 )
            {
                RaiseOnTap();
                return GestureState.Recognized;
            }

            // either lifted off some fingers or added some new ones
            return GestureState.Failed;
        }

        // check if the gesture timed out
        if( MaxDuration > 0 && ElapsedTime > MaxDuration )
            return GestureState.Failed;
        
        // check if finger moved too far from start position
        float sqrDist = Vector3.SqrMagnitude( touches.GetAveragePosition() - StartPosition );
        if( sqrDist >= MoveTolerance * MoveTolerance )
            return GestureState.Failed;
        
        return GestureState.InProgress;
    }
    protected override GestureState OnActive( FingerGestures.IFingerList touches )
    {
        if( touches.Count != RequiredFingerCount )
        {
            // fingers were lifted off
            if( touches.Count < RequiredFingerCount )
            {
                RaiseOnDragEnd();
                return GestureState.Recognized;
            }

            return GestureState.Failed;
        }

        Position = touches.GetAveragePosition();

        MoveDelta = Position - lastPos;

        if( MoveDelta.sqrMagnitude > 0 )
        {
            RaiseOnDragMove();
            lastPos = Position;
        }

        return GestureState.InProgress;
    }
    protected override void OnBegin( FingerGestures.IFingerList touches )
    {
        Position = touches.GetAveragePosition();
        StartPosition = Position;
        lastTapTime = Time.time;

        //Debuger.Log( this + " OnBegin @ " + StartPosition );
    }
 protected override void OnBegin( FingerGestures.IFingerList touches )
 {
     Position = touches.GetAveragePosition();
     StartPosition = Position;
     MoveDelta = Vector2.zero;
     lastPos = Position;
     
     RaiseOnDragBegin();
 }
 protected override void OnBegin( FingerGestures.IFingerList touches )
 {
     Position = touches.GetAveragePosition();
     StartPosition = Position;
 }
    protected override GestureState OnActive( FingerGestures.IFingerList touches )
    {
        wasDown = down;
        down = false;

        if( touches.Count == RequiredFingerCount )
        {
            down = true;
            lastDownTime = Time.time;
        }
        else if( touches.Count == 0 )
        {
            down = false;
        }
        else
        {
            // some fingers were lifted off
            if( touches.Count < RequiredFingerCount )
            {
                // give a bit of buffer time to lift-off the remaining fingers
                if( Time.time - lastDownTime > 0.25f )
                    return GestureState.Failed;
            }
            else // fingers were added
            {
                if( !Young( touches ) )
                    return GestureState.Failed;
            }
        }

        if( HasTimedOut() )
        {
            // if we requested unlimited taps and landed at least one, consider this a success
            if( RequiredTaps == 0 && Taps > 0 )
            {
                // if we didn't raise a tap event on each tap, at least raise the event once at the end of the tap sequence
                if( !RaiseEventOnEachTap )
                    RaiseOnTap();

                return GestureState.Recognized;
            }

            // else, timed out
            return GestureState.Failed;
        }

        if( down )
        {
            // check if finger moved too far from start position
            float sqrDist = Vector3.SqrMagnitude( touches.GetAveragePosition() - StartPosition );
            if( sqrDist >= MoveTolerance * MoveTolerance )
                return GestureState.Failed;
        }

        if( wasDown != down )
        {
            // fingers were just released
            if( !down )
            {
                ++taps;
                lastTapTime = Time.time;

                // If the requested tap count has been reached, validate the gesture and stop
                if( RequiredTaps > 0 && taps >= RequiredTaps )
                {
                    RaiseOnTap();
                    return GestureState.Recognized;
                }

                if( RaiseEventOnEachTap )
                    RaiseOnTap();
            }
        }

        return GestureState.InProgress;
    }
 protected override void OnBegin( FingerGestures.IFingerList touches )
 {
     Position = touches.GetAveragePosition();
     StartPosition = Position;
     direction = FingerGestures.SwipeDirection.None;
 }
    protected override GestureState OnActive( FingerGestures.IFingerList touches )
    {
        if( touches.Count != RequiredFingerCount )
        {
            // fingers were lifted off
            if( touches.Count < RequiredFingerCount )
            {
                if( direction != FingerGestures.SwipeDirection.None )
                {
                    if( OnSwipe != null )
                        OnSwipe( this );

                    return GestureState.Recognized;
                }
            }

            return GestureState.Failed;
        }

        Position = touches.GetAveragePosition();
        Move = Position - StartPosition;

        float distance = Move.magnitude;

        // didnt move far enough
        if( distance < MinDistance )
            return GestureState.InProgress;

        if( ElapsedTime > 0 )
            velocity = distance / ElapsedTime;
        else
            velocity = 0;

        // we're going too slow
        if( velocity < MinVelocity )
            return GestureState.Failed;

        FingerGestures.SwipeDirection newDirection = FingerGestures.GetSwipeDirection( Move.normalized, DirectionTolerance );

        // we went in a bad direction
        if( !IsValidDirection( newDirection ) || ( direction != FingerGestures.SwipeDirection.None && newDirection != direction ) )
            return GestureState.Failed;

        direction = newDirection;
        return GestureState.InProgress;
    }
示例#9
0
 protected override void OnBegin( FingerGestures.IFingerList touches )
 {
     Position = touches.GetAveragePosition();
     StartPosition = Position;
     lastTapTime = Time.time;
     startTime = Time.time;
 }