public void OnLongTapFinished(TKLongPressRecognizer r) { Debug.Log("long press finished"); if (!_useNetwork) { GameSignals.INPUT_LONG_PRESS.Dispatch(); } else { var signal = GameSignals.INPUT_GENERIC; signal.AddParameter(GameParams.INPUT_TYPE, GestureType.LONG_PRESS); signal.Dispatch(); signal.ClearParameters(); } }
private void Start() { TouchKit.instance.designTimeResolution = new Vector2(800, 480); Debug.Log(Camera.main); TKAnyTouchRecognizer tapLeft = new TKAnyTouchRecognizer(new TKRect(0, 0, xBorderLeftRight, 480)); tapLeft.onEnteredEvent += TapLeft_onEnteredEvent; tapLeft.onExitedEvent += TapLeft_onExitedEvent; TKAnyTouchRecognizer tapRight = new TKAnyTouchRecognizer(new TKRect(xBorderLeftRight, 0, xBorderRightGesture - xBorderLeftRight, 480)); tapRight.onEnteredEvent += TapRight_onEnteredEvent; tapRight.onExitedEvent += TapRight_onExitedEvent; TKSwipeRecognizer swipeDash = new TKSwipeRecognizer(1); swipeDash.boundaryFrame = new TKRect(xBorderRightGesture, 0, 800 - xBorderRightGesture, 480); swipeDash.gestureRecognizedEvent += SwipeDash_gestureRecognizedEvent; swipeDash.timeToSwipe = 0; swipeDash.TrackTouchesStartedOutOfBounds = true; TKLongPressRecognizer block = new TKLongPressRecognizer(1, 4, 1); block.boundaryFrame = new TKRect(xBorderRightGesture, 0, 800 - xBorderRightGesture, 480); block.cancelAfterRecognitionWhenOutOfBounds = true; block.ignoreMovementAfterRecognition = true; block.gestureRecognizedEvent += Block_gestureRecognizedEvent; block.gestureCompleteEvent += Block_gestureCompleteEvent; TKTapRecognizer jump = new TKTapRecognizer(); jump.boundaryFrame = new TKRect(xBorderRightGesture, yBorderJumpGesture, 800 - xBorderRightGesture, 480 - yBorderJumpGesture); jump.gestureRecognizedEvent += Jump_gestureRecognizedEvent; TouchKit.addGestureRecognizer(tapRight); TouchKit.addGestureRecognizer(tapLeft); TouchKit.addGestureRecognizer(swipeDash); TouchKit.addGestureRecognizer(block); TouchKit.addGestureRecognizer(jump); playerMotor.motorInput = this; health.OnDeath += Health_OnDeath; }
void InitializeRecognizers() { swipeRecognizer = new TKSwipeRecognizer(); swipeRecognizer.gestureRecognizedEvent += OnSwipeRecognized; TouchKit.addGestureRecognizer(swipeRecognizer); tapRecognizer = new TKTapRecognizer(); tapRecognizer.gestureRecognizedEvent += OnTapRecognized; TouchKit.addGestureRecognizer(tapRecognizer); pinchRecognizer = new TKPinchRecognizer(); pinchRecognizer.gestureRecognizedEvent += OnPinchRecognized; TouchKit.addGestureRecognizer(pinchRecognizer); longPressRecognizer = new TKLongPressRecognizer(); longPressRecognizer.gestureRecognizedEvent += OnLongTapRecognized; longPressRecognizer.gestureCompleteEvent += OnLongTapFinished; TouchKit.addGestureRecognizer(longPressRecognizer); Debug.Log("recognizers successfully initialized"); }
private Vector2 _scrollPosition; // for the scroll view void OnGUI() { GUI.skin.button.padding = new RectOffset(10, 10, 20, 20); GUI.skin.button.fixedWidth = 250; GUILayout.BeginArea(new Rect(Screen.width - GUI.skin.button.fixedWidth - 20, 0, GUI.skin.button.fixedWidth + 20, Screen.height)); _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, GUILayout.Width(GUI.skin.button.fixedWidth + 20), GUILayout.Height(Screen.height)); if (GUILayout.Button("Add Curve Recognizer")) { var recognizer = new TKCurveRecognizer(); recognizer.gestureRecognizedEvent += (r) => { cube.Rotate(Vector3.back, recognizer.deltaRotation); Debug.Log("curve recognizer fired: " + r); }; recognizer.gestureCompleteEvent += (r) => { Debug.Log("curve completed."); }; TouchKit.addGestureRecognizer(recognizer); } if (GUILayout.Button("Add Tap Recognizer")) { var recognizer = new TKTapRecognizer(); // we can limit recognition to a specific Rect, in this case the bottom-left corner of the screen recognizer.boundaryFrame = new TKRect(0, 0, 50f, 50f); // we can also set the number of touches required for the gesture if (Application.platform == RuntimePlatform.IPhonePlayer) { recognizer.numberOfTouchesRequired = 2; } recognizer.gestureRecognizedEvent += (r) => { Debug.Log("tap recognizer fired: " + r); }; TouchKit.addGestureRecognizer(recognizer); } if (GUILayout.Button("Add Long Press Recognizer")) { var recognizer = new TKLongPressRecognizer(); recognizer.gestureRecognizedEvent += (r) => { Debug.Log("long press recognizer fired: " + r); }; recognizer.gestureCompleteEvent += (r) => { Debug.Log("long press recognizer finished: " + r); }; TouchKit.addGestureRecognizer(recognizer); } if (GUILayout.Button("Add Pan Recognizer")) { var recognizer = new TKPanRecognizer(); // when using in conjunction with a pinch or rotation recognizer setting the min touches to 2 smoothes movement greatly if (Application.platform == RuntimePlatform.IPhonePlayer) { recognizer.minimumNumberOfTouches = 2; } recognizer.gestureRecognizedEvent += (r) => { Camera.main.transform.position -= new Vector3(recognizer.deltaTranslation.x, recognizer.deltaTranslation.y) / 100; Debug.Log("pan recognizer fired: " + r); }; // continuous gestures have a complete event so that we know when they are done recognizing recognizer.gestureCompleteEvent += r => { Debug.Log("pan gesture complete"); }; TouchKit.addGestureRecognizer(recognizer); } if (GUILayout.Button("Add Horizontal Swipe Recognizer")) { var recognizer = new TKSwipeRecognizer(TKSwipeDirection.Horizontal); recognizer.gestureRecognizedEvent += (r) => { Debug.Log("swipe recognizer fired: " + r); }; TouchKit.addGestureRecognizer(recognizer); } if (GUILayout.Button("Add Pinch Recognizer")) { var recognizer = new TKPinchRecognizer(); recognizer.gestureRecognizedEvent += (r) => { cube.transform.localScale += Vector3.one * recognizer.deltaScale; Debug.Log("pinch recognizer fired: " + r); }; TouchKit.addGestureRecognizer(recognizer); } if (GUILayout.Button("Add Rotation Recognizer")) { var recognizer = new TKRotationRecognizer(); recognizer.gestureRecognizedEvent += (r) => { cube.Rotate(Vector3.back, recognizer.deltaRotation); Debug.Log("rotation recognizer fired: " + r); }; TouchKit.addGestureRecognizer(recognizer); } if (GUILayout.Button("Add Button Recognizer")) { var recognizer = new TKButtonRecognizer(new TKRect(5f, 145f, 80f, 30f), 10f); recognizer.zIndex = 1; recognizer.onSelectedEvent += (r) => { Debug.Log("button recognizer selected: " + r); }; recognizer.onDeselectedEvent += (r) => { Debug.Log("button recognizer deselected: " + r); }; recognizer.onTouchUpInsideEvent += (r) => { Debug.Log("button recognizer touch up inside: " + r); }; TouchKit.addGestureRecognizer(recognizer); } if (GUILayout.Button("Add One Finger Rotation Recognizer")) { var recognizer = new TKOneFingerRotationRecognizer(); recognizer.targetPosition = Camera.main.WorldToScreenPoint(cube.position); recognizer.gestureRecognizedEvent += (r) => { cube.Rotate(Vector3.back, recognizer.deltaRotation); Debug.Log("one finger rotation recognizer fired: " + r); }; TouchKit.addGestureRecognizer(recognizer); } if (GUILayout.Button("Add Any Touch Recognizer")) { var recognizer = new TKAnyTouchRecognizer(new TKRect(10, 10, 80, 50)); recognizer.zIndex = 1; recognizer.onEnteredEvent += (r) => { Debug.Log("any touch entered: " + r); }; recognizer.onExitedEvent += (r) => { Debug.Log("any touch exited: " + r); }; TouchKit.addGestureRecognizer(recognizer); } if (GUILayout.Button("Remove All Recognizers")) { TouchKit.removeAllGestureRecognizers(); } GUILayout.EndScrollView(); GUILayout.EndArea(); }
private Vector2 _scrollPosition; // for the scroll view #endregion Fields #region Methods void OnGUI() { GUI.skin.button.padding = new RectOffset( 10, 10, 20, 20 ); GUI.skin.button.fixedWidth = 250; GUILayout.BeginArea( new Rect( Screen.width - GUI.skin.button.fixedWidth - 20, 0, GUI.skin.button.fixedWidth + 20, Screen.height ) ); _scrollPosition = GUILayout.BeginScrollView( _scrollPosition, GUILayout.Width( GUI.skin.button.fixedWidth + 20 ), GUILayout.Height( Screen.height ) ); if( GUILayout.Button( "Add Tap Recognizer" ) ) { var recognizer = new TKTapRecognizer(); // we can limit recognition to a specific Rect, in this case the bottom-left corner of the screen recognizer.boundaryFrame = new TKRect( 0, 0, 50f, 50f ); // we can also set the number of touches required for the gesture if( Application.platform == RuntimePlatform.IPhonePlayer ) recognizer.numberOfTouchesRequired = 2; recognizer.gestureRecognizedEvent += ( r ) => { Debug.Log( "tap recognizer fired: " + r ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add Long Press Recognizer" ) ) { var recognizer = new TKLongPressRecognizer(); recognizer.gestureRecognizedEvent += ( r ) => { Debug.Log( "long press recognizer fired: " + r ); }; recognizer.gestureCompleteEvent += ( r ) => { Debug.Log( "long press recognizer finished: " + r ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add Pan Recognizer" ) ) { var recognizer = new TKPanRecognizer(); // when using in conjunction with a pinch or rotation recognizer setting the min touches to 2 smoothes movement greatly if( Application.platform == RuntimePlatform.IPhonePlayer ) recognizer.minimumNumberOfTouches = 2; recognizer.gestureRecognizedEvent += ( r ) => { Camera.main.transform.position -= new Vector3( recognizer.deltaTranslation.x, recognizer.deltaTranslation.y ) / 100; Debug.Log( "pan recognizer fired: " + r ); }; // continuous gestures have a complete event so that we know when they are done recognizing recognizer.gestureCompleteEvent += r => { Debug.Log( "pan gesture complete" ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add TouchPad Recognizer" ) ) { var recognizer = new TKTouchPadRecognizer( new TKRect( 0f, 50f, 80f, 50f ) ); recognizer.inputCurve = touchPadInputCurve; recognizer.gestureRecognizedEvent += ( r ) => { //Camera.main.transform.position -= new Vector3( recognizer.deltaTranslation.x, recognizer.deltaTranslation.y ) / 100; Debug.Log( "touchpad recognizer fired: " + r ); }; // continuous gestures have a complete event so that we know when they are done recognizing recognizer.gestureCompleteEvent += r => { Debug.Log( "touchpad gesture complete" ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add Horizontal Swipe Recognizer" ) ) { var recognizer = new TKSwipeRecognizer(); recognizer.gestureRecognizedEvent += ( r ) => { Debug.Log( "swipe recognizer fired: " + r ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add Top-Right Swipe Recognizer" ) ) { var recognizer = new TKAngleSwipeRecognizer(); recognizer.addAngleRecogizedEvents ( (TKAngleSwipeRecognizer r) => { Debug.Log( "Top-Right angle swipe fired " + r ); }, new Vector2(1,1), 45); recognizer.gestureRecognizedEvent += r => { // You can also do ordinary event, which fires at any angle // Debug.Log( "angle swipe recognizer fired: " + r ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add Pinch Recognizer" ) ) { var recognizer = new TKPinchRecognizer(); recognizer.gestureRecognizedEvent += ( r ) => { cube.transform.localScale += Vector3.one * recognizer.deltaScale; Debug.Log( "pinch recognizer fired: " + r ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add Rotation Recognizer" ) ) { var recognizer = new TKRotationRecognizer(); recognizer.gestureRecognizedEvent += ( r ) => { cube.Rotate( Vector3.back, recognizer.deltaRotation ); Debug.Log( "rotation recognizer fired: " + r ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add Button Recognizer" ) ) { var recognizer = new TKButtonRecognizer( new TKRect( 5f, 145f, 80f, 30f ), 10f ); recognizer.zIndex = 1; recognizer.onSelectedEvent += ( r ) => { Debug.Log( "button recognizer selected: " + r ); }; recognizer.onDeselectedEvent += ( r ) => { Debug.Log( "button recognizer deselected: " + r ); }; recognizer.onTouchUpInsideEvent += ( r ) => { Debug.Log( "button recognizer touch up inside: " + r ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add One Finger Rotation Recognizer" ) ) { var recognizer = new TKOneFingerRotationRecognizer(); recognizer.targetPosition = Camera.main.WorldToScreenPoint( cube.position ); recognizer.gestureRecognizedEvent += ( r ) => { cube.Rotate( Vector3.back, recognizer.deltaRotation ); Debug.Log( "one finger rotation recognizer fired: " + r ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add Any Touch Recognizer" ) ) { var recognizer = new TKAnyTouchRecognizer( new TKRect( 10, 10, 80, 50 ) ); recognizer.zIndex = 1; recognizer.onEnteredEvent += ( r ) => { Debug.Log( "any touch entered: " + r ); }; recognizer.onExitedEvent += ( r ) => { Debug.Log( "any touch exited: " + r ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add Curve Recognizer" ) ) { var recognizer = new TKCurveRecognizer(); recognizer.gestureRecognizedEvent += ( r ) => { cube.Rotate( Vector3.back, recognizer.deltaRotation ); Debug.Log( "curve recognizer fired: " + r ); }; recognizer.gestureCompleteEvent += ( r ) => { Debug.Log( "curve completed."); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Remove All Recognizers" ) ) { TouchKit.removeAllGestureRecognizers(); } GUILayout.EndScrollView(); GUILayout.EndArea(); }
private Vector2 _scrollPosition; // for the scroll view #endregion Fields #region Methods void OnGUI() { //GUI.matrix = Matrix4x4.Scale( new Vector3( 1.5f, 1.5f, 1.5f ) ); GUI.skin.button.padding = new RectOffset( 10, 10, 20, 20 ); GUI.skin.button.fixedWidth = 250; GUILayout.BeginArea( new Rect( Screen.width - GUI.skin.button.fixedWidth - 20, 0, GUI.skin.button.fixedWidth + 20, Screen.height ) ); _scrollPosition = GUILayout.BeginScrollView( _scrollPosition, GUILayout.Width( GUI.skin.button.fixedWidth + 20 ), GUILayout.Height( Screen.height ) ); if( GUILayout.Button( "Add Tap Recognizer" ) ) { var recognizer = new TKTapRecognizer(); // we can limit recognition to a specific Rect, in this case the bottom-left corner of the screen recognizer.boundaryFrame = new TKRect( 50, 50, 400, 400 ); // we can also set the number of touches required for the gesture if( Application.platform == RuntimePlatform.IPhonePlayer ) recognizer.numberOfTouchesRequired = 2; recognizer.gestureRecognizedEvent += ( r ) => { Debug.Log( "tap recognizer fired: " + r ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add Long Press Recognizer" ) ) { var recognizer = new TKLongPressRecognizer(); recognizer.gestureRecognizedEvent += ( r ) => { Debug.Log( "long press recognizer fired: " + r ); }; recognizer.gestureCompleteEvent += ( r ) => { Debug.Log( "long press recognizer finished: " + r ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add Pan Recognizer" ) ) { var recognizer = new TKPanRecognizer(); // when using in conjunction with a pinch or rotation recognizer setting the min touches to 2 smoothes movement greatly if( Application.platform == RuntimePlatform.IPhonePlayer ) recognizer.minimumNumberOfTouches = 2; recognizer.gestureRecognizedEvent += ( r ) => { Camera.mainCamera.transform.position -= new Vector3( recognizer.deltaTranslation.x, recognizer.deltaTranslation.y ) / 100; Debug.Log( "pan recognizer fired: " + r ); }; // continuous gestures have a complete event so that we know when they are done recognizing recognizer.gestureCompleteEvent += r => { Debug.Log( "pan gesture complete" ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add Horizontal Swipe Recognizer" ) ) { var recognizer = new TKSwipeRecognizer( TKSwipeDirection.Horizontal ); recognizer.gestureRecognizedEvent += ( r ) => { Debug.Log( "swipe recognizer fired: " + r ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add Pinch Recognizer" ) ) { var recognizer = new TKPinchRecognizer(); recognizer.gestureRecognizedEvent += ( r ) => { cube.transform.localScale += Vector3.one * recognizer.deltaScale; Debug.Log( "pinch recognizer fired: " + r ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add Rotation Recognizer" ) ) { var recognizer = new TKRotationRecognizer(); recognizer.gestureRecognizedEvent += ( r ) => { cube.Rotate( Vector3.back, recognizer.deltaRotation ); Debug.Log( "rotation recognizer fired: " + r ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add Button Recognizer" ) ) { var recognizer = new TKButtonRecognizer( new TKRect( 300, 30, 278, 90 ), 20 ); recognizer.zIndex = 1; recognizer.onSelectedEvent += ( r ) => { Debug.Log( "button recognizer selected: " + r ); }; recognizer.onDeselectedEvent += ( r ) => { Debug.Log( "button recognizer deselected: " + r ); }; recognizer.onTouchUpInsideEvent += ( r ) => { Debug.Log( "button recognizer touch up inside: " + r ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Add One Finger Rotation Recognizer" ) ) { var recognizer = new TKOneFingerRotationRecognizer(); recognizer.targetPosition = Camera.mainCamera.WorldToScreenPoint( cube.position ); recognizer.gestureRecognizedEvent += ( r ) => { cube.Rotate( Vector3.back, recognizer.deltaRotation ); Debug.Log( "one finger rotation recognizer fired: " + r ); }; TouchKit.addGestureRecognizer( recognizer ); } if( GUILayout.Button( "Remove All Recognizers" ) ) { TouchKit.removeAllGestureRecognizers(); } GUILayout.EndScrollView(); GUILayout.EndArea(); }
public void OnLongTapRecognized(TKLongPressRecognizer r) { Debug.Log("long press started"); }
private void Block_gestureRecognizedEvent(TKLongPressRecognizer obj) { shouldBlock = true; Debug.Log("Player starts blocking"); }
private void Block_gestureCompleteEvent(TKLongPressRecognizer obj) { shouldBlock = false; Debug.Log("Player ends blocking"); }