コード例 #1
0
    internal override bool touchesBegan(List <TKTouch> touches)
    {
        if (state == TKGestureRecognizerState.Possible)
        {
            _swipeDetectionState = _swipesToDetect;
            _startPoint          = touches[0].position;
            _startTime           = Time.time;
            _trackingTouches.Add(touches[0]);

            state = TKGestureRecognizerState.Began;
        }

        return(false);
    }
コード例 #2
0
    // Use this for initialization
    void Start()
    {
        var recognizer = new TKSwipeRecognizer(.1f);

        // recognizer.timeToSwipe = .1f;
        recognizer.gestureRecognizedEvent += (r) =>
        {
            TKSwipeDirection sdir = r.completedSwipeDirection;
            // Debug.Log( r.swipeVelocity );
            // Debug.Log( r.startPoint );
            // Debug.Log( r.endPoint );
            // Debug.Log( "=====" );
            Events.instance.Raise(new SwipeEvent(sdir, r.swipeVelocity));
        };
        TouchKit.addGestureRecognizer(recognizer);
    }
コード例 #3
0
    void swipeGestureDetected(TKSwipeRecognizer r)
    {
        TKSwipeDirection direction = r.completedSwipeDirection;

        switch (direction)
        {
        case TKSwipeDirection.Up:
            moveCamera(Direction.UP);
            break;

        case TKSwipeDirection.Down:
            moveCamera(Direction.DOWN);
            break;

        case TKSwipeDirection.Left:
            moveCamera(Direction.RIGHT);
            break;

        case TKSwipeDirection.Right:
            moveCamera(Direction.LEFT);
            break;

        case TKSwipeDirection.UpLeft:
            moveCamera(Direction.UP, Direction.RIGHT);
            break;

        case TKSwipeDirection.UpRight:
            moveCamera(Direction.UP, Direction.LEFT);
            break;

        case TKSwipeDirection.DownLeft:
            moveCamera(Direction.DOWN, Direction.RIGHT);
            break;

        case TKSwipeDirection.DownRight:
            moveCamera(Direction.DOWN, Direction.LEFT);
            break;

        default:
            break;
        }
//        Debug.Log("swipe gesture complete: " + direction);
    }
コード例 #4
0
        private void PopBubble(GestureType type, TKSwipeDirection direction)
        {
            switch (direction)
            {
            case TKSwipeDirection.Up:
                this.PopBubble(EBubbleType.SwipeUp);
                break;

            case TKSwipeDirection.Down:
                this.PopBubble(EBubbleType.SwipeDown);
                break;

            case TKSwipeDirection.Left:
                this.PopBubble(EBubbleType.SwipeLeft);
                break;

            case TKSwipeDirection.Right:
                this.PopBubble(EBubbleType.SwipeRight);
                break;
            }
        }
コード例 #5
0
ファイル: TKSwipeRecognizer.cs プロジェクト: loloop/equinox
    internal override bool touchesBegan(List <TKTouch> touches)
    {
        if (state == TKGestureRecognizerState.Possible)
        {
            // add any touches on screen
            for (int i = 0; i < touches.Count; i++)
            {
                _trackingTouches.Add(touches[i]);
            }

            // if the number of touches is within our constraints, begin tracking
            if (_trackingTouches.Count >= minimumNumberOfTouches && _trackingTouches.Count <= maximumNumberOfTouches)
            {
                _swipeDetectionState = _swipesToDetect;
                _startPoint          = touches[0].position;
                _startTime           = Time.time;
                state = TKGestureRecognizerState.Began;
            }
        }

        return(false);
    }
コード例 #6
0
ファイル: Direction.cs プロジェクト: tng2903/nodulus
        public static Direction ToDirection(this TKSwipeDirection direction)
        {
            if ((direction & TKSwipeDirection.Left) != 0)
            {
                return(Direction.Left);
            }

            if ((direction & TKSwipeDirection.Right) != 0)
            {
                return(Direction.Right);
            }

            if ((direction & TKSwipeDirection.Up) != 0)
            {
                return(Direction.Up);
            }

            if ((direction & TKSwipeDirection.Down) != 0)
            {
                return(Direction.Down);
            }

            return(Direction.None);
        }
コード例 #7
0
 public TKSwipeRecognizer(TKSwipeDirection swipesToDetect, float minimumDistance, float allowedVariance)
 {
     _swipesToDetect  = swipesToDetect;
     _minimumDistance = minimumDistance * TouchKit.instance.runtimeDistanceModifier;
     _allowedVariance = allowedVariance * TouchKit.instance.runtimeDistanceModifier;
 }
コード例 #8
0
    private bool checkForSwipeCompletion(TKTouch touch)
    {
        // if we have a time stipulation and we exceeded it stop listening for swipes
        if (timeToSwipe > 0.0f && (Time.time - _startTime) > timeToSwipe)
        {
            state = TKGestureRecognizerState.FailedOrEnded;
            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 &= ~TKSwipeDirection.Left;
        }
        if (touch.deltaPosition.x < 0.0f)
        {
            _swipeDetectionState &= ~TKSwipeDirection.Right;
        }

        if (touch.deltaPosition.y < 0.0f)
        {
            _swipeDetectionState &= ~TKSwipeDirection.Up;
        }
        if (touch.deltaPosition.y > 0.0f)
        {
            _swipeDetectionState &= ~TKSwipeDirection.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) / TouchKit.instance.ScreenPixelsPerCm;
        var yDeltaAbsCm = Mathf.Abs(_startPoint.y - touch.position.y) / TouchKit.instance.ScreenPixelsPerCm;

        _endPoint = touch.position;

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

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

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

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

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

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

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

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

        return(false);
    }
コード例 #9
0
 public TKSwipeRecognizer(TKSwipeDirection swipesToDetect, float minimumDistanceCm, float allowedVarianceCm)
 {
     _swipesToDetect  = swipesToDetect;
     _minimumDistance = minimumDistanceCm;
     _allowedVariance = allowedVarianceCm;
 }
コード例 #10
0
 public TKSwipeRecognizer(TKSwipeDirection swipesToDetect) : this(swipesToDetect, 2f, 1.5f)
 {
 }
コード例 #11
0
 public void addSwipeDirection(TKSwipeDirection _direction)
 {
     swipeDirections.Add(new SwipeDirection(_direction));
 }
コード例 #12
0
ファイル: TKSwipeRecognizer.cs プロジェクト: nolimet/Liaka
	private bool checkForSwipeCompletion( TKTouch touch )
	{
		// if we have a time stipulation and we exceeded it stop listening for swipes
		if( timeToSwipe > 0.0f && ( Time.time - _startTime ) > timeToSwipe )
		{
			state = TKGestureRecognizerState.FailedOrEnded;
			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 &= ~TKSwipeDirection.Left;
			if( touch.deltaPosition.x < 0.0f )
				_swipeDetectionState &= ~TKSwipeDirection.Right;
			
			if( touch.deltaPosition.y < 0.0f )
				_swipeDetectionState &= ~TKSwipeDirection.Up;			
			if( touch.deltaPosition.y > 0.0f )
				_swipeDetectionState &= ~TKSwipeDirection.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) / TouchKit.instance.ScreenPixelsPerCm;
		var yDeltaAbsCm = Mathf.Abs(_startPoint.y - touch.position.y) / TouchKit.instance.ScreenPixelsPerCm;

		_endPoint = touch.position;

		// only check for swipes in directions that havent been ruled out yet
		// left check
		if( ( _swipeDetectionState & TKSwipeDirection.Left ) != 0 )
		{
			if (xDeltaAbsCm > _minimumDistance)
			{
				if (yDeltaAbsCm < _allowedVariance)
				{
					completedSwipeDirection = TKSwipeDirection.Left;
					swipeVelocity = xDeltaAbsCm / (Time.time - _startTime);
					return true;
				}
				
				// We exceeded our variance so this swipe is no longer allowed
				_swipeDetectionState &= ~TKSwipeDirection.Left;
			}
		}

		// right check
		if( ( _swipeDetectionState & TKSwipeDirection.Right ) != 0 )
		{
			if (xDeltaAbsCm > _minimumDistance)
			{
				if (yDeltaAbsCm < _allowedVariance)
				{
					completedSwipeDirection = TKSwipeDirection.Right;
					swipeVelocity = xDeltaAbsCm / (Time.time - _startTime);
					return true;
				}
				
				// We exceeded our variance so this swipe is no longer allowed
				_swipeDetectionState &= ~TKSwipeDirection.Right;
			}
		}
		
		// up check
		if( ( _swipeDetectionState & TKSwipeDirection.Up ) != 0 )
		{
			if (yDeltaAbsCm > _minimumDistance)
			{
				if (xDeltaAbsCm < _allowedVariance)
				{
					completedSwipeDirection = TKSwipeDirection.Up;
					swipeVelocity = yDeltaAbsCm / (Time.time - _startTime);
					return true;
				}
				
				// We exceeded our variance so this swipe is no longer allowed
				_swipeDetectionState &= ~TKSwipeDirection.Up;
			}
		}
		
		// cown check
		if( ( _swipeDetectionState & TKSwipeDirection.Down ) != 0 )
		{
			if (yDeltaAbsCm > _minimumDistance)
			{
				if (xDeltaAbsCm < _allowedVariance)
				{
					completedSwipeDirection = TKSwipeDirection.Down;
					swipeVelocity = yDeltaAbsCm / (Time.time - _startTime);
					return true;
				}
				
				// We exceeded our variance so this swipe is no longer allowed
				_swipeDetectionState &= ~TKSwipeDirection.Down;
			}
		}
		
		return false;
	}
コード例 #13
0
ファイル: TKSwipeRecognizer.cs プロジェクト: nolimet/Liaka
	public TKSwipeRecognizer(TKSwipeDirection swipesToDetect, float minimumDistanceCm, float allowedVarianceCm)
	{
		_swipesToDetect = swipesToDetect;
		_minimumDistance = minimumDistanceCm;
		_allowedVariance = allowedVarianceCm;
	}
コード例 #14
0
ファイル: TKSwipeRecognizer.cs プロジェクト: nolimet/Liaka
	public TKSwipeRecognizer(TKSwipeDirection swipesToDetect) : this(swipesToDetect, 2f, 1.5f)
	{ }
コード例 #15
0
ファイル: TKSwipeRecognizer.cs プロジェクト: nolimet/Liaka
	internal override bool touchesBegan( List<TKTouch> touches )
	{
		if( state == TKGestureRecognizerState.Possible )
		{
			// add any touches on screen
			for( int i = 0; i < touches.Count; i++ )
				_trackingTouches.Add( touches[i] );

			// if the number of touches is within our constraints, begin tracking
			if ( _trackingTouches.Count >= minimumNumberOfTouches && _trackingTouches.Count <= maximumNumberOfTouches )
			{
				_swipeDetectionState = _swipesToDetect;
				_startPoint = touches[0].position;
				_startTime = Time.time;
				state = TKGestureRecognizerState.Began;
			}
		}
		
		return false;
	}
コード例 #16
0
 public SwipeDirection(TKSwipeDirection _direction, bool _isSuccess = false)
 {
     direction = _direction;
     isSuccess = _isSuccess;
 }
コード例 #17
0
	public TKSwipeRecognizer( TKSwipeDirection swipesToDetect, float minimumDistance, float allowedVariance )
	{
		_swipesToDetect = swipesToDetect;
		_minimumDistance = minimumDistance * TouchKit.instance.runtimeDistanceModifier;
		_allowedVariance = allowedVariance * TouchKit.instance.runtimeDistanceModifier;
	}
コード例 #18
0
	internal override bool touchesBegan( List<TKTouch> touches )
	{
		if( state == TKGestureRecognizerState.Possible )
		{
			_swipeDetectionState = _swipesToDetect;
			_startPoint = touches[0].position;
			_startTime = Time.time;
			_trackingTouches.Add( touches[0] );
			
			state = TKGestureRecognizerState.Began;
		}
		
		return false;
	}
コード例 #19
0
 public SwipeEvent(TKSwipeDirection thisDir, float vel)
 {
     dir      = thisDir;
     velocity = vel;
 }