/// <summary> /// checks to see if the touch is currently being tracked by the recognizer /// </summary> protected bool isTrackingTouch( GKTouch t ) { return _trackingTouches.Contains( t ); }
private void Awake() { #if UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER // we only need one touch on mouse driven platforms maxTouchesToProcess = 1; #endif // prep our GKTouch cache so we avoid excessive allocations _touchCache = new GKTouch[maxTouchesToProcess]; for( int i = 0; i < maxTouchesToProcess; i++ ) _touchCache[i] = new GKTouch( i ); }
private void Awake() { #if UNITY_IPHONE // check to see if we are on a retina device if( iPhone.generation == iPhoneGeneration.iPad3Gen || iPhone.generation == iPhoneGeneration.iPadUnknown || iPhone.generation == iPhoneGeneration.iPhone4 || iPhone.generation == iPhoneGeneration.iPhone4S || iPhone.generation == iPhoneGeneration.iPhone5 || iPhone.generation == iPhoneGeneration.iPodTouch4Gen || iPhone.generation == iPhoneGeneration.iPodTouch5Gen || iPhone.generation == iPhoneGeneration.iPodTouchUnknown ) isRetina = true; #endif // prep our GKTouch cache so we avoid excessive allocations _touchCache = new GKTouch[maxTouchesToProcess]; for( int i = 0; i < maxTouchesToProcess; i++ ) _touchCache[i] = new GKTouch( i ); }
private bool checkForSwipeCompletion( GKTouch touch ) { // if we have a time stipulation and we exceeded it stop listening for swipes if( timeToSwipe > 0.0f && ( Time.time - _startTime ) > timeToSwipe ) { state = GKGestureRecognizerState.Failed; return false; } // when dealing with standalones (non touch-based devices) we need to be careful what we examaine // we filter out all touches (mouse movements really) that didnt move #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER if( touch.deltaPosition.x != 0.0f || touch.deltaPosition.y != 0.0f ) { #endif // check the delta move positions. We can rule out at least 2 directions if( touch.deltaPosition.x > 0.0f ) _swipeDetectionState &= ~GKSwipeDirection.Left; if( touch.deltaPosition.x < 0.0f ) _swipeDetectionState &= ~GKSwipeDirection.Right; if( touch.deltaPosition.y < 0.0f ) _swipeDetectionState &= ~GKSwipeDirection.Up; if( touch.deltaPosition.y > 0.0f ) _swipeDetectionState &= ~GKSwipeDirection.Down; #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER } #endif //Debug.Log( string.Format( "swipeStatus: {0}", swipeDetectionState ) ); // Grab the total distance moved in both directions var xDeltaAbs = Mathf.Abs( _startPoint.x - touch.position.x ); var yDeltaAbs = Mathf.Abs( _startPoint.y - touch.position.y ); // only check for swipes in directions that havent been ruled out yet // left check if( ( _swipeDetectionState & GKSwipeDirection.Left ) != 0 ) { if( xDeltaAbs > minimumDistance ) { if( yDeltaAbs < allowedVariance ) { completedSwipeDirection = GKSwipeDirection.Left; swipeVelocity = xDeltaAbs / ( Time.time - _startTime ); return true; } // We exceeded our variance so this swipe is no longer allowed _swipeDetectionState &= ~GKSwipeDirection.Left; } } // right check if( ( _swipeDetectionState & GKSwipeDirection.Right ) != 0 ) { if( xDeltaAbs > minimumDistance ) { if( yDeltaAbs < allowedVariance ) { completedSwipeDirection = GKSwipeDirection.Right; swipeVelocity = xDeltaAbs / ( Time.time - _startTime ); return true; } // We exceeded our variance so this swipe is no longer allowed _swipeDetectionState &= ~GKSwipeDirection.Right; } } // up check if( ( _swipeDetectionState & GKSwipeDirection.Up ) != 0 ) { if( yDeltaAbs > minimumDistance ) { if( xDeltaAbs < allowedVariance ) { completedSwipeDirection = GKSwipeDirection.Up; swipeVelocity = yDeltaAbs / ( Time.time - _startTime ); return true; } // We exceeded our variance so this swipe is no longer allowed _swipeDetectionState &= ~GKSwipeDirection.Up; } } // cown check if( ( _swipeDetectionState & GKSwipeDirection.Down ) != 0 ) { if( yDeltaAbs > minimumDistance ) { if( xDeltaAbs < allowedVariance ) { completedSwipeDirection = GKSwipeDirection.Down; swipeVelocity = yDeltaAbs / ( Time.time - _startTime ); return true; } // We exceeded our variance so this swipe is no longer allowed _swipeDetectionState &= ~GKSwipeDirection.Down; } } return false; }