Ejemplo n.º 1
0
 void Awake()
 {
     // prep our TKLTouch cache so we avoid excessive allocations
     _touchCache = new TKLTouch[kTotalTouchesToProcess];
     for( int i = 0; i < kTotalTouchesToProcess; i++ )
     _touchCache[i] = new TKLTouch( i );
 }
Ejemplo n.º 2
0
 void Awake()
 {
     // prep our TKLTouch cache so we avoid excessive allocations
     _touchCache = new TKLTouch[kTotalTouchesToProcess];
     for (int i = 0; i < kTotalTouchesToProcess; i++)
     {
         _touchCache[i] = new TKLTouch(i);
     }
 }
Ejemplo n.º 3
0
        private bool checkForSwipeCompletion(TKLTouch touch)
        {
            // if we have a time stipulation and we exceeded it stop listening for swipes
            if (timeToSwipe > 0.0f && (Time.time - _startTime) > timeToSwipe)
            {
                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 || UNITY_WEBGL
            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 &= ~SwipeDirection.Left;
            }
            if (touch.deltaPosition.x < 0.0f)
            {
                _swipeDetectionState &= ~SwipeDirection.Right;
            }

            if (touch.deltaPosition.y < 0.0f)
            {
                _swipeDetectionState &= ~SwipeDirection.Up;
            }
            if (touch.deltaPosition.y > 0.0f)
            {
                _swipeDetectionState &= ~SwipeDirection.Down;
            }

                        #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER || UNITY_WEBGL
        }
                #endif

            //Debug.Log( string.Format( "swipeStatus: {0}", swipeDetectionState ) );

            // Grab the total distance moved in both directions
            var xDeltaAbsCm = Mathf.Abs(_startPoint.x - touch.position.x) / TouchKitLite.instance.screenPixelsPerCm;
            var yDeltaAbsCm = Mathf.Abs(_startPoint.y - touch.position.y) / TouchKitLite.instance.screenPixelsPerCm;

            // only check for swipes in directions that havent been ruled out yet
            // left check
            if ((_swipeDetectionState & SwipeDirection.Left) != 0)
            {
                if (xDeltaAbsCm > _minimumDistance)
                {
                    if (yDeltaAbsCm < _allowedVariance)
                    {
                        completedSwipeDirection = SwipeDirection.Left;
                        swipeVelocity           = xDeltaAbsCm / (Time.time - _startTime);
                        return(true);
                    }

                    // We exceeded our variance so this swipe is no longer allowed
                    _swipeDetectionState &= ~SwipeDirection.Left;
                }
            }

            // right check
            if ((_swipeDetectionState & SwipeDirection.Right) != 0)
            {
                if (xDeltaAbsCm > _minimumDistance)
                {
                    if (yDeltaAbsCm < _allowedVariance)
                    {
                        completedSwipeDirection = SwipeDirection.Right;
                        swipeVelocity           = xDeltaAbsCm / (Time.time - _startTime);
                        return(true);
                    }

                    // We exceeded our variance so this swipe is no longer allowed
                    _swipeDetectionState &= ~SwipeDirection.Right;
                }
            }

            // up check
            if ((_swipeDetectionState & SwipeDirection.Up) != 0)
            {
                if (yDeltaAbsCm > _minimumDistance)
                {
                    if (xDeltaAbsCm < _allowedVariance)
                    {
                        completedSwipeDirection = SwipeDirection.Up;
                        swipeVelocity           = yDeltaAbsCm / (Time.time - _startTime);
                        return(true);
                    }

                    // We exceeded our variance so this swipe is no longer allowed
                    _swipeDetectionState &= ~SwipeDirection.Up;
                }
            }

            // down check
            if ((_swipeDetectionState & SwipeDirection.Down) != 0)
            {
                if (yDeltaAbsCm > _minimumDistance)
                {
                    if (xDeltaAbsCm < _allowedVariance)
                    {
                        completedSwipeDirection = SwipeDirection.Down;
                        swipeVelocity           = yDeltaAbsCm / (Time.time - _startTime);
                        return(true);
                    }

                    // We exceeded our variance so this swipe is no longer allowed
                    _swipeDetectionState &= ~SwipeDirection.Down;
                }
            }

            return(false);
        }
Ejemplo n.º 4
0
	private bool checkForSwipeCompletion( TKLTouch touch )
	{
		// if we have a time stipulation and we exceeded it stop listening for swipes
		if( timeToSwipe > 0.0f && ( Time.time - _startTime ) > timeToSwipe )
		{
			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 || UNITY_WEBGL
		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 &= ~SwipeDirection.Left;
			if( touch.deltaPosition.x < 0.0f )
				_swipeDetectionState &= ~SwipeDirection.Right;

			if( touch.deltaPosition.y < 0.0f )
				_swipeDetectionState &= ~SwipeDirection.Up;			
			if( touch.deltaPosition.y > 0.0f )
				_swipeDetectionState &= ~SwipeDirection.Down;

			#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER || UNITY_WEBGL
		}
		#endif

		//Debug.Log( string.Format( "swipeStatus: {0}", swipeDetectionState ) );

		// Grab the total distance moved in both directions
		var xDeltaAbsCm = Mathf.Abs( _startPoint.x - touch.position.x ) / TouchKitLite.instance.screenPixelsPerCm;
		var yDeltaAbsCm = Mathf.Abs( _startPoint.y - touch.position.y ) / TouchKitLite.instance.screenPixelsPerCm;

		// only check for swipes in directions that havent been ruled out yet
		// left check
		if( ( _swipeDetectionState & SwipeDirection.Left ) != 0 )
		{
			if( xDeltaAbsCm > _minimumDistance )
			{
				if( yDeltaAbsCm < _allowedVariance )
				{
					completedSwipeDirection = SwipeDirection.Left;
					swipeVelocity = xDeltaAbsCm / ( Time.time - _startTime );
					return true;
				}

				// We exceeded our variance so this swipe is no longer allowed
				_swipeDetectionState &= ~SwipeDirection.Left;
			}
		}

		// right check
		if( ( _swipeDetectionState & SwipeDirection.Right ) != 0 )
		{
			if( xDeltaAbsCm > _minimumDistance )
			{
				if( yDeltaAbsCm < _allowedVariance )
				{
					completedSwipeDirection = SwipeDirection.Right;
					swipeVelocity = xDeltaAbsCm / ( Time.time - _startTime );
					return true;
				}

				// We exceeded our variance so this swipe is no longer allowed
				_swipeDetectionState &= ~SwipeDirection.Right;
			}
		}

		// up check
		if( ( _swipeDetectionState & SwipeDirection.Up ) != 0 )
		{
			if( yDeltaAbsCm > _minimumDistance )
			{
				if( xDeltaAbsCm < _allowedVariance )
				{
					completedSwipeDirection = SwipeDirection.Up;
					swipeVelocity = yDeltaAbsCm / ( Time.time - _startTime );
					return true;
				}

				// We exceeded our variance so this swipe is no longer allowed
				_swipeDetectionState &= ~SwipeDirection.Up;
			}
		}

		// down check
		if( ( _swipeDetectionState & SwipeDirection.Down ) != 0 )
		{
			if( yDeltaAbsCm > _minimumDistance )
			{
				if( xDeltaAbsCm < _allowedVariance )
				{
					completedSwipeDirection = SwipeDirection.Down;
					swipeVelocity = yDeltaAbsCm / ( Time.time - _startTime );
					return true;
				}

				// We exceeded our variance so this swipe is no longer allowed
				_swipeDetectionState &= ~SwipeDirection.Down;
			}
		}

		return false;
	}