/// <summary> /// Detection /// </summary> /// <returns> Result of detection</returns> protected override GestureDetectionResult Detection() { // if we are late to detect another tap ignore previous results if (_TapIntervalTW.IsEnabledAndOver) { return(GestureDetectionResult.Failed); } // check if tracking touches are valid for (int i = 0; i < TrackingToucheCount; i++) { TouchState touch = GetTrackingToucheByIndex(i); if (!touch.IsValidFor(this) || (touch.Phase == UnityEngine.TouchPhase.Moved && touch.DeltaPosition.magnitude >= MaxDeltaMovement)) { return(GestureDetectionResult.Failed); } if (_Phases[i] != _DesiredPhase) { _Phases[i] = touch.Phase; } } if (IsAllDesiredPhase()) { if (_DesiredPhase == TouchPhase.Ended) { _NumberOfDetectedTap++; if (_NumberOfDetectedTap == TapCount) { OnTap(); return(GestureDetectionResult.Detected); } else { _TapIntervalTW.Begin(MaxTapInterval); } _DesiredPhase = TouchPhase.Began; } else if (_DesiredPhase == TouchPhase.Began) { _DesiredPhase = TouchPhase.Ended; } } return(GestureDetectionResult.None); }
/// <summary> /// Detection /// </summary> /// <returns>Result of detection </returns> protected override GestureDetectionResult Detection() { // if we have a time stipulation and we exceeded it stop listening for swipes if ((Time.time - _StartTime) > _TimeToSwipe) { return(GestureDetectionResult.Failed); } for (int i = 0; i < FingerCount; i++) { TouchState ts = GetTrackingToucheByIndex(i); if (!ts.IsValidFor(this)) { return(GestureDetectionResult.Failed); } // check the delta move positions. We can rule out at least 2 directions if (ts.DeltaPosition.x > 0.0f) { _SwipeDetectionState &= ~SwipeDirection.Left; } if (ts.DeltaPosition.x < 0.0f) { _SwipeDetectionState &= ~SwipeDirection.Right; } if (ts.DeltaPosition.y < 0.0f) { _SwipeDetectionState &= ~SwipeDirection.Up; } if (ts.DeltaPosition.y > 0.0f) { _SwipeDetectionState &= ~SwipeDirection.Down; } } // Grab the total distance moved in both directions Vector2 deltaLocation = _StartPoint - TouchLocation(); deltaLocation.x = Mathf.Abs(deltaLocation.x); deltaLocation.y = Mathf.Abs(deltaLocation.y); if (CheckForEvent(SwipeDirection.Left, deltaLocation.x, deltaLocation.y)) // left check { return(GestureDetectionResult.Detected); } else if (CheckForEvent(SwipeDirection.Right, deltaLocation.x, deltaLocation.y)) // right check { return(GestureDetectionResult.Detected); } else if (CheckForEvent(SwipeDirection.Up, deltaLocation.y, deltaLocation.x)) // up check { return(GestureDetectionResult.Detected); } else if (CheckForEvent(SwipeDirection.Down, deltaLocation.y, deltaLocation.x)) // down check { return(GestureDetectionResult.Detected); } return(GestureDetectionResult.None); }