protected override GestureRecognitionState OnRecognize(DragGesture gesture, FingerGestures.IFingerList touches) { if (touches.Count != RequiredFingerCount) { // fingers were lifted off if (touches.Count < RequiredFingerCount) { return(GestureRecognitionState.Ended); } return(GestureRecognitionState.Failed); } if (RequiredFingerCount >= 2 && ApplySameDirectionConstraint && touches.AllMoving() && !touches.MovingInSameDirection(0.35f)) { return(GestureRecognitionState.Failed); } gesture.Position = touches.GetAveragePosition(); gesture.LastDelta = gesture.DeltaMove; 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); }
protected override GestureRecognitionState OnRecognize(PointCloudGesture gesture, FingerGestures.IFingerList touches) { if (touches.Count != RequiredFingerCount) { // fingers lifted off? if (touches.Count < RequiredFingerCount) { // recognize if (RecognizePointCloud(gesture)) { return(GestureRecognitionState.Recognized); } return(GestureRecognitionState.Failed); } return(GestureRecognitionState.Failed); } // update current gesture position gesture.Position = touches.GetAveragePosition(); Vector2 lastSamplePos = gesture.RawPoints[gesture.RawPoints.Count - 1].Position; // check if we should take a new sample float dist = Vector2.SqrMagnitude(gesture.Position - lastSamplePos); if (dist > MinDistanceBetweenSamples * MinDistanceBetweenSamples) { int strokeId = 0; gesture.RawPoints.Add(new Point(strokeId, gesture.Position)); } return(GestureRecognitionState.InProgress); }
protected override GestureRecognitionState OnRecognize(PointCloudGesture gesture, FingerGestures.IFingerList touches) { if (touches.Count != RequiredFingerCount) { // fingers lifted off? if (touches.Count < RequiredFingerCount) { // recognize if (RecognizePointCloud(gesture)) { return(GestureRecognitionState.Recognized); } return(GestureRecognitionState.Failed); } return(GestureRecognitionState.Failed); } // update current gesture position gesture.Position = touches.GetAveragePosition(); float minSampleDelta = FingerGestures.GetAdjustedPixelDistance(MinDistanceBetweenSamples); Vector2 lastSamplePos = gesture.RawPoints[gesture.RawPoints.Count - 1].Position; // check if we should take a new sample if (Vector2.SqrMagnitude(gesture.Position - lastSamplePos) > minSampleDelta * minSampleDelta) { int strokeId = 0; //TODO increment this after each finger up>down gesture.RawPoints.Add(new Point(strokeId, gesture.Position)); } return(GestureRecognitionState.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 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 void OnBegin(FingerGestures.IFingerList touches) { Position = touches.GetAveragePosition(); StartPosition = Position; lastTapTime = Time.time; startTime = Time.time; }
protected override void OnBegin(FingerGestures.IFingerList touches) { Position = touches.GetAveragePosition(); StartPosition = Position; direction = FingerGestures.SwipeDirection.None; startTime = Time.time; }
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); } float elapsedTime = Time.time - startTime; 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); }
GestureRecognitionState RecognizeSingleTap(TapGesture gesture, FingerGestures.IFingerList touches) { if (touches.Count != RequiredFingerCount) { // all fingers lifted - fire the tap event if (touches.Count == 0) { return(GestureRecognitionState.Recognized); } // either lifted off some fingers or added some new ones return(GestureRecognitionState.Failed); } if (HasTimedOut(gesture)) { return(GestureRecognitionState.Failed); } // check if finger moved too far from start position float sqrDist = Vector3.SqrMagnitude(touches.GetAveragePosition() - gesture.StartPosition); if (sqrDist >= MoveTolerance * MoveTolerance) { return(GestureRecognitionState.Failed); } return(GestureRecognitionState.InProgress); }
protected override void OnBegin(FingerGestures.IFingerList touches) { Position = touches.GetAveragePosition(); StartPosition = Position; lastTapTime = Time.time; //Debug.Log( this + " OnBegin @ " + StartPosition ); }
protected override void OnBegin(PointCloudGesture gesture, FingerGestures.IFingerList touches) { gesture.StartPosition = touches.GetAverageStartPosition(); gesture.Position = touches.GetAveragePosition(); gesture.RawPoints.Clear(); gesture.RawPoints.Add(new Point(0, gesture.Position)); }
protected override void OnBegin(DragGesture gesture, FingerGestures.IFingerList touches) { gesture.Position = touches.GetAveragePosition(); gesture.StartPosition = touches.GetAverageStartPosition(); gesture.DeltaMove = gesture.Position - gesture.StartPosition; gesture.LastDelta = Vector2.zero; gesture.LastPos = gesture.Position; }
protected override void OnBegin(SwipeGesture gesture, FingerGestures.IFingerList touches) { gesture.StartPosition = touches.GetAverageStartPosition(); gesture.Position = touches.GetAveragePosition(); gesture.Move = Vector3.zero; gesture.MoveCounter = 0; gesture.Deviation = 0; gesture.Direction = FingerGestures.SwipeDirection.None; }
protected override void OnBegin(FingerGestures.IFingerList touches) { Position = touches.GetAveragePosition(); StartPosition = Position; MoveDelta = Vector2.zero; lastPos = Position; RaiseOnDragBegin(); }
protected override void OnBegin(SwipeGesture gesture, FingerGestures.IFingerList touches) { gesture.StartPosition = touches.GetAverageStartPosition(); gesture.Position = touches.GetAveragePosition(); gesture.Move = Vector3.zero; gesture.MoveCounter = 0; gesture.Deviation = 0; gesture.Direction = FingerGestures.SwipeDirection.None; //Debug.Log( "BeginSwipe: " + EventMessageName + " touches.Count=" + FingerGestures.Touches.Count ); }
protected override GestureRecognitionState OnRecognize(SwipeGesture gesture, FingerGestures.IFingerList touches) { if (touches.Count != RequiredFingerCount) { // more fingers were added - fail right away if (touches.Count > RequiredFingerCount) { return(GestureRecognitionState.Failed); } // // fingers were lifted-off // // didn't swipe far enough if (FingerGestures.GetAdjustedPixelDistance(gesture.Move.magnitude) < Mathf.Max(1, MinDistance)) { return(GestureRecognitionState.Failed); } // get approx swipe direction gesture.Direction = FingerGestures.GetSwipeDirection(gesture.Move); return(GestureRecognitionState.Recognized); } Vector2 previousMotion = gesture.Move; gesture.Position = touches.GetAveragePosition(); gesture.Move = gesture.Position - gesture.StartPosition; float distance = FingerGestures.GetAdjustedPixelDistance(gesture.Move.magnitude); // moved too far if (MaxDistance > MinDistance && distance > MaxDistance) { //Debug.LogWarning( "Too far: " + distance ); return(GestureRecognitionState.Failed); } if (gesture.ElapsedTime > 0) { gesture.Velocity = distance / gesture.ElapsedTime; } else { gesture.Velocity = 0; } // we're going too slow if (gesture.MoveCounter > 2 && gesture.Velocity < MinVelocity) { //Debug.LogWarning( "Too slow: " + gesture.Velocity ); return(GestureRecognitionState.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 GestureRecognitionState.Failed; * * direction = newDirection; */ // check if we have deviated too much from our initial direction if (distance > 50.0f && gesture.MoveCounter > 2) { // accumulate delta angle gesture.Deviation += Mathf.Rad2Deg * FingerGestures.SignedAngle(previousMotion, gesture.Move); if (Mathf.Abs(gesture.Deviation) > MaxDeviation) { //Debug.LogWarning( "Swipe: deviated too much from initial direction (" + gesture.Deviation + ")" ); return(GestureRecognitionState.Failed); } } ++gesture.MoveCounter; return(GestureRecognitionState.InProgress); }
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 { 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) { Vector2 curPos = touches.GetAveragePosition(); // check if finger moved too far from start position if (MovedTooFar(curPos)) { 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 GestureRecognitionState OnRecognize(SwipeGesture gesture, FingerGestures.IFingerList touches) { float minDistanceInPixels = ToPixels(MinDistance); float maxDistanceInPixels = ToPixels(MaxDistance); if (touches.Count != RequiredFingerCount) { // more fingers were added - fail right away if (touches.Count > RequiredFingerCount) { return(GestureRecognitionState.Failed); } // // fingers were lifted-off // // didn't swipe far enough if (gesture.Move.magnitude < Mathf.Max(1, minDistanceInPixels)) { return(GestureRecognitionState.Failed); } // get approx swipe direction gesture.Direction = FingerGestures.GetSwipeDirection(gesture.Move); return(GestureRecognitionState.Recognized); } Vector2 previousMotion = gesture.Move; gesture.Position = touches.GetAveragePosition(); gesture.Move = gesture.Position - gesture.StartPosition; // pixel-adjusted distance float distance = gesture.Move.magnitude; // moved too far if (maxDistanceInPixels > minDistanceInPixels && distance > maxDistanceInPixels) { //Debug.LogWarning( "Too far: " + distance ); return(GestureRecognitionState.Failed); } if (gesture.ElapsedTime > 0) { gesture.Velocity = distance / gesture.ElapsedTime; } else { gesture.Velocity = 0; } // we're going too slow if (gesture.MoveCounter > 2 && gesture.Velocity < ToPixels(MinVelocity)) { //Debug.LogWarning( "Too slow: " + gesture.Velocity ); return(GestureRecognitionState.Failed); } // check if we have deviated too much from our initial direction if (distance > 50.0f && gesture.MoveCounter > 2) { // accumulate delta angle gesture.Deviation += Mathf.Rad2Deg * FingerGestures.SignedAngle(previousMotion, gesture.Move); if (Mathf.Abs(gesture.Deviation) > MaxDeviation) { //Debug.LogWarning( "Swipe: deviated too much from initial direction (" + gesture.Deviation + ")" ); return(GestureRecognitionState.Failed); } } ++gesture.MoveCounter; return(GestureRecognitionState.InProgress); }
protected override void OnBegin(LongPressGesture gesture, FingerGestures.IFingerList touches) { gesture.Position = touches.GetAveragePosition(); gesture.StartPosition = gesture.Position; }
protected override void OnBegin(FingerGestures.IFingerList touches) { Position = touches.GetAveragePosition(); StartPosition = Position; }
protected override void OnBegin(TapGesture gesture, FingerGestures.IFingerList touches) { gesture.Position = touches.GetAveragePosition(); gesture.StartPosition = gesture.Position; gesture.LastTapTime = Time.time; }
GestureRecognitionState RecognizeMultiTap(TapGesture gesture, FingerGestures.IFingerList touches) { gesture.WasDown = gesture.Down; gesture.Down = false; if (touches.Count == RequiredFingerCount) { gesture.Down = true; gesture.LastDownTime = Time.time; } else if (touches.Count == 0) { gesture.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 - gesture.LastDownTime > 0.25f) { return(GestureRecognitionState.Failed); } } else // fingers were added { if (!Young(touches)) { return(GestureRecognitionState.Failed); } } } if (HasTimedOut(gesture)) { return(GestureRecognitionState.Failed); } if (gesture.Down) { // check if finger moved too far from start position float sqrDist = Vector3.SqrMagnitude(touches.GetAveragePosition() - gesture.StartPosition); if (sqrDist >= MoveTolerance * MoveTolerance) { return(GestureRecognitionState.Failed); } } if (gesture.WasDown != gesture.Down) { // fingers were just released if (!gesture.Down) { ++gesture.Taps; gesture.LastTapTime = Time.time; // If the requested tap count has been reached, validate the gesture and stop if (gesture.Taps >= RequiredTaps) { return(GestureRecognitionState.Recognized); } } } return(GestureRecognitionState.InProgress); }