// Use this for initialization void Start() { TKSwipeRecognizer recognizer = new TKSwipeRecognizer(TKSwipeDirection.All); recognizer.gestureRecognizedEvent += (r) => { //Ação desejada no swipe vem aqui Debug.Log(r); swipeText.text = r.completedSwipeDirection.ToString(); Color color = Color.black; switch (r.completedSwipeDirection) { case TKSwipeDirection.Down: color = Color.green; break; case TKSwipeDirection.Up: color = Color.blue; break; case TKSwipeDirection.Left: color = Color.magenta; break; case TKSwipeDirection.Right: color = Color.yellow; break; default: break; } background.color = color; }; TouchKit.addGestureRecognizer(recognizer); }
void setupRecognizers() { // left button _leftRecognizer = new TKAnyTouchRecognizer(new TKRect(0f, 0f, buttonWidth, buttonHeight)); TouchKit.addGestureRecognizer(_leftRecognizer); // right button _rightRecognizer = new TKAnyTouchRecognizer(new TKRect(buttonWidth + 1f, 0f, buttonWidth, buttonHeight)); TouchKit.addGestureRecognizer(_rightRecognizer); // up button. we place it 70% of the way up the other two buttons allowing some overlap _upRecognizer = new TKAnyTouchRecognizer(new TKRect(0f, buttonHeight * 0.7f, buttonWidth * 2f + 1f, 20f)); TouchKit.addGestureRecognizer(_upRecognizer); // attack button. we use the onSelectedEvent here because we only want to know the exact frame it was pressed _attackRecognizer = new TKButtonRecognizer(new TKRect(TouchKit.instance.designTimeResolution.x - buttonWidth * 2f, 0, buttonWidth, buttonHeight), 0f); _attackRecognizer.onSelectedEvent += (r) => { attackDown = true; }; TouchKit.addGestureRecognizer(_attackRecognizer); // jump button _jumpRecognizer = new TKButtonRecognizer(new TKRect(TouchKit.instance.designTimeResolution.x - buttonWidth, 0, buttonWidth, buttonHeight), 0f); TouchKit.addGestureRecognizer(_jumpRecognizer); }
void OnEnable() { var recognizer = new TKSwipeRecognizer(); recognizer.gestureRecognizedEvent += PlayerBehavoir.MoveBalls; TouchKit.addGestureRecognizer(recognizer); //TO DO ADD SIMPLE TOUCH RECIGNIZER }
// Use this for initialization void Start() { bagHandler = GetComponent <BagHandler>(); // // 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; // } // continuous gestures have a complete event so that we know when they are done recognizing swipeRecognizer.gestureRecognizedEvent += swipeGestureDetected; TouchKit.addGestureRecognizer(swipeRecognizer); twoTapRecognizer.numberOfTouchesRequired = 2; twoTapRecognizer.gestureRecognizedEvent += twoTapDetected; TouchKit.addGestureRecognizer(twoTapRecognizer); /* #if UNITY_IOS * Input.simulateMouseWithTouches = false; #endif #if UNITY_IOS || UNITY_ANDROID * tapRecognizer.numberOfTouchesRequired = 1; * tapRecognizer.gestureRecognizedEvent += tapDetected; * TouchKit.addGestureRecognizer(tapRecognizer); #endif */ continousHoldRecognizer.gestureHoldingEvent += touchHoldActive; continousHoldRecognizer.gestureHoldingEventEnded += touchHoldEnded; TouchKit.addGestureRecognizer(continousHoldRecognizer); StartCoroutine(preloadGameObjects()); }
private void Inputinit() { var recognizerTap = new TKTapRecognizer(); // we can limit recognition to a specific Rect, in this case the bottom-left corner of the screen recognizerTap.boundaryFrame = new TKRect(0, 0, Screen.width, Screen.height); // we can also set the number of touches required for the gesture if (Application.platform == RuntimePlatform.IPhonePlayer) { recognizerTap.numberOfTouchesRequired = 2; } recognizerTap.gestureRecognizedEvent += Tap_gestureRecognizedEvent; TouchKit.addGestureRecognizer(recognizerTap); var recognizerSwipe = new TKSwipeRecognizer(); recognizerSwipe.timeToSwipe = 0; recognizerSwipe.SetMinimumDistance(0.5f); //recognizerTap.addAngleRecogizedEvents (Recognizer_gestureRecognizedEvent, new Vector2(1,1), 45); recognizerSwipe.gestureRecognizedEvent += Swipe_gestureRecognizedEvent; TouchKit.addGestureRecognizer(recognizerSwipe); }
// Use this for initialization void Start () { var swipeRecognizer = new TKSwipeRecognizer(TKSwipeDirection.All,minimumSwipeDistance,allowedSwipeVariance); swipeRecognizer.timeToSwipe = timeToSwipe; swipeRecognizer.gestureRecognizedEvent += (r) => { if (r.completedSwipeDirection == TKSwipeDirection.Left ) { swipe ("left", r.startPoint); } if (r.completedSwipeDirection == TKSwipeDirection.Right) { swipe ("right", r.startPoint); } if (r.completedSwipeDirection == TKSwipeDirection.Up) { swipe ("up", r.startPoint); } if (r.completedSwipeDirection == TKSwipeDirection.Down ) { swipe("down", r.startPoint); } }; TouchKit.addGestureRecognizer(swipeRecognizer); }
void Start() { swipeRecognizer.gestureRecognizedEvent += (r) => { updateDirection(); }; TouchKit.addGestureRecognizer(swipeRecognizer); }
private void Start() { var recognizer = new TKSwipeRecognizer(swipeMinMax.x, swipeMinMax.y); recognizer.gestureRecognizedEvent += (r) => { Debug.Log("swipe recognizer fired: " + r); }; TouchKit.addGestureRecognizer(recognizer); }
public void InitTouchControl() { var recognizer = new TKPanRecognizer(); //recognizer.boundaryFrame = new TKRect(50f, 0,public GameObject ColorPicker; //public Material ColorPickerMaterial; 100f, 100f); // 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); //Debug.Log(recognizer.touchLocation()); //Debug.Log(recognizer.state); if (!EventSystem.current.IsPointerOverGameObject() || true) { if (IsDrawing == false) { clone = (GameObject)Instantiate(LineObject); clone.tag = "ARLines"; clone.GetComponent <LineRenderer>().material = CurrentMaterial; clone.transform.parent = DrawSpace.transform; line = clone.GetComponent <LineRenderer>(); //line.material.color = Color.white; line.startWidth = LineWidth; line.endWidth = LineWidth; LineDividNumber = 0; IsDrawing = true; } else { LineDividNumber++; line.positionCount = LineDividNumber; Vector2 touchLocation = recognizer.touchLocation(); line.SetPosition(LineDividNumber - 1, TargetCamera.ScreenToWorldPoint(new Vector3(touchLocation.x, touchLocation.y, DrawOffset))); } } }; // continuous gestures have a complete event so that we know when they are done recognizing recognizer.gestureCompleteEvent += r => { Debug.Log("pan gesture complete"); IsDrawing = false; }; TouchKit.addGestureRecognizer(recognizer); }
void Start() { _statsDetail = FindObjectOfType <StatsDetail>(); var recognizer = new TKPanRecognizer(); recognizer.gestureRecognizedEvent += (r) => { transform.Rotate(transform.up, -0.1f * recognizer.deltaTranslation.x); _statsDetail.transform.localScale = Vector3.zero; }; TouchKit.addGestureRecognizer(recognizer); }
public TouchKitInputSystem() { panRecognizer = new TKPanRecognizer(); pinchRecognizer = new TKPinchRecognizer(); rotationRecognizer = new TKRotationRecognizer(); panRecognizer.gestureRecognizedEvent += OnPan; pinchRecognizer.gestureRecognizedEvent += OnPinch; rotationRecognizer.gestureRecognizedEvent += OnRotation; TouchKit.addGestureRecognizer(panRecognizer); TouchKit.addGestureRecognizer(pinchRecognizer); TouchKit.addGestureRecognizer(rotationRecognizer); }
void Start() { var recognizer = new TKPinchRecognizer(); recognizer.gestureRecognizedEvent += (r) => { Vector3 newScale = transform.localScale + Vector3.one * recognizer.deltaScale; if (newScale.x > min && newScale.x < max) { transform.localScale = newScale; } }; TouchKit.addGestureRecognizer(recognizer); }
protected void Awake() { this.m_unityEventSystem = base.GetComponent <EventSystem>(); this.m_usesTouch = this.UnityEventSystem.currentInputModule is TouchInputModule; float num = (Screen.dpi != 0f) ? Screen.dpi : 72f; this.m_unityEventSystem.pixelDragThreshold = Mathf.FloorToInt(num * 0.1f); this.TouchKit = base.gameObject.AddComponent <TouchKit>(); this.TouchKit.autoScaleRectsAndDistances = true; this.TouchKit.shouldAutoUpdateTouches = true; this.TouchKit.maxTouchesToProcess = 1; this.TouchKit.drawDebugBoundaryFrames = !ConfigApp.ProductionBuild; this.TouchKit.drawTouches = !ConfigApp.ProductionBuild; this.TouchKit.simulateTouches = Application.isEditor; this.TouchKit.simulateMultitouch = Application.isEditor; TKSwipeRecognizer recognizer = new TKSwipeRecognizer(0.2f); recognizer.gestureRecognizedEvent += delegate(TKSwipeRecognizer r) { if (this.InputEnabled && (PlayerView.Binder.EventBus != null)) { PlayerView.Binder.EventBus.GestureSwipeRecognized(r); } }; TouchKit.addGestureRecognizer(recognizer); TKPanRecognizer recognizer2 = new TKPanRecognizer(0.05f); recognizer2.gestureRecognizedEvent += delegate(TKPanRecognizer r) { if (this.InputEnabled && (PlayerView.Binder.EventBus != null)) { PlayerView.Binder.EventBus.GesturePanRecognized(r); } }; recognizer2.gestureCompleteEvent += delegate(TKPanRecognizer r) { if (this.InputEnabled && (PlayerView.Binder.EventBus != null)) { PlayerView.Binder.EventBus.GesturePanCompleted(r); } }; TouchKit.addGestureRecognizer(recognizer2); TKTapRecognizer recognizer3 = new TKTapRecognizer(0.4f, 0.5f); recognizer3.gestureRecognizedEvent += delegate(TKTapRecognizer r) { if (this.InputEnabled && (PlayerView.Binder.EventBus != null)) { PlayerView.Binder.EventBus.GestureTapRecognized(r); } }; TouchKit.addGestureRecognizer(recognizer3); }
// 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); }
void addTapGesture() { TKTapRecognizer tapRecognizer = new TKTapRecognizer(); tapRecognizer.gestureRecognizedEvent += (r) => { //Debug.Log("tap recognizer fired: " + r); //print("Location of tap" + r.startTouchLocation()); _initialPosition = GetCurrentMousePosition(r.startTouchLocation()).GetValueOrDefault(); //print("vertex count is " + _vertextCount); _lineRenderer.SetPosition(_vertextCount - 1, _initialPosition); //1 -> initial pos _lineRenderer.SetVertexCount(++_vertextCount); //count = 2 isTapped = !isTapped; }; TouchKit.addGestureRecognizer(tapRecognizer); }
void addTapGesture() { TKTapRecognizer tapRecognizer = new TKTapRecognizer(); tapRecognizer.gestureRecognizedEvent += (r) => { //Debug.Log ("tap recognizer fired: " + r); if (gameObject.activeInHierarchy) { if (gameObject.GetComponent <BoxCollider> ().bounds.Contains(transform.TransformPoint(GetCurrentMousePosition(r.startTouchLocation()).GetValueOrDefault()))) { if (!isDrawing) { didDraw = false; isDrawing = true; _initialPos = GetCurrentMousePosition(r.startTouchLocation()).GetValueOrDefault(); instantiateNode(_initialPos); } else { didDraw = true; float newXpos = wallList.Last().transform.position.x + wallList.Last().transform.localScale.x *Mathf.Cos(_xRotation * Mathf.PI / 180f); float newYpos = wallList.Last().transform.position.y + wallList.Last().transform.localScale.x *Mathf.Sin(_xRotation * Mathf.PI / 180f); newXpos = Mathf.Round(newXpos * 100) / 100f; newYpos = Mathf.Round(newYpos * 100) / 100f; Vector3 newPos = new Vector3(newXpos, newYpos, 0); _initialPos = newPos; setPreviousWallEndNode(); handleOverlap(wallList.Last()); } instantiateWall(_initialPos); } else { removeDrawingWall(); } } }; TouchKit.addGestureRecognizer(tapRecognizer); }
private void Start() { foreach (OnlineMapsMarker3D marker in markers3D.Where(m => !m.inited)) { marker.control = this; marker.Init(transform); } UpdateMarkers3D(); var recognizer = new TKRotationRecognizer(); recognizer.gestureRecognizedEvent += (r) => { cameraRotation.y -= recognizer.deltaRotation * cameraSpeed.x; Debug.Log("rotation recognizer fired: " + r); }; TouchKit.addGestureRecognizer(recognizer); }
private void Start() { // Add event handlers for swiping the screen _swipeRecognizer = new TKSwipeRecognizer(MinSwipeDistanceCm) { minimumNumberOfTouches = 1, maximumNumberOfTouches = 10, timeToSwipe = 1f }; _swipeRecognizer.gestureRecognizedEvent += OnSwipe; TouchKit.addGestureRecognizer(_swipeRecognizer); // Add an event handler for tapping the screen _tapRecognizer = new TKTapRecognizer(); _tapRecognizer.gestureRecognizedEvent += OnTap; TouchKit.addGestureRecognizer(_tapRecognizer); }
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 addPanGestureRecognizer() { panRecognizer = new TKPanRecognizer(); panRecognizer.gestureRecognizedEvent += (r) => { //print("Touch delta is " + r.deltaTranslation.y); //print("Touch delta cm is " + r.deltaTranslationCm); print("Scale" + transform.localScale.y + 0.1f * r.deltaTranslation.y); float yScale = Mathf.Max(transform.localScale.y + 0.1f * r.deltaTranslation.y, 1.0f); transform.localScale = new Vector3(transform.localScale.x, yScale, 0); //Debug.Log(r); }; panRecognizer.gestureCompleteEvent += r => { Debug.Log("pan gesture complete"); }; TouchKit.addGestureRecognizer(panRecognizer); }
private void OnEnable() { rotationRecognizer = new TKRotationRecognizer(); rotationRecognizer.gestureRecognizedEvent += (r) => { float rotaionValue = -(r.deltaRotation * 2.0f); if (rotationX) { transform.Rotate(rotaionValue, 0, 0); } else if (rotationY) { transform.Rotate(0, rotaionValue, 0); } else if (rotationZ) { transform.Rotate(0, 0, rotaionValue); } }; TouchKit.addGestureRecognizer(rotationRecognizer); }
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 void Start() { var panRecognizer = new TKPanRecognizer(); panRecognizer.gestureRecognizedEvent += OnPan; panRecognizer.gestureCompleteEvent += OnPanComplete; TouchKit.addGestureRecognizer(panRecognizer); var tapRecognizer = new TKTapRecognizer(); tapRecognizer.gestureRecognizedEvent += OnTap; TouchKit.addGestureRecognizer(tapRecognizer); // Start with the saved start level _selectedLevel = Levels.CurrentLevelNum; GenerateLevelsList(); if (_levels[_selectedLevel] == null) { Debug.LogError($"Failed to start at level ({_selectedLevel})"); return; } var puzzleState = _levels[_selectedLevel].GetComponent <PuzzleState>(); var puzzleScale = _levels[_selectedLevel].GetComponent <PuzzleScale>(); puzzleState.BoardEnabled = true; puzzleScale.PuzzleInit += OnPuzzleInit; _levels[_selectedLevel].GetComponent <BoardAction>().PuzzleWin += OnPuzzleWin; puzzleState.LevelStateChanged += OnLevelStateChanged; var bounds = _levelBounds[_selectedLevel]; var mid = (bounds.Item1 + bounds.Item2) / 2f; transform.position = Vector3.up * mid; puzzleState.Init(_selectedLevel); }
// Start is called before the first frame update void Start() { _mainCamera = Camera.main; 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) => { Vector3 forward = Vector3.ProjectOnPlane(_mainCamera.transform.forward, Vector3.up) * recognizer.deltaTranslation.y; Vector3 right = Vector3.ProjectOnPlane(_mainCamera.transform.right, Vector3.up) * recognizer.deltaTranslation.x; Vector3 newPos = (forward + right) / 1000; transform.position += newPos; }; TouchKit.addGestureRecognizer(recognizer); }
void Start() { Application.targetFrameRate = 60; currentStickerParent = futureWorldStickerParent; currentStickerPicker = futureWorldStickerPicker; currentPostProcessVolume = normalPostProcessVolume; currentOverlay = futureWorldOverlay; screenCenter = new Vector3(Screen.width / 2, Screen.height / 2, 0); var pinchRecognizer = new TKPinchRecognizer(); pinchRecognizer.gestureRecognizedEvent += OnPinchRecognized; pinchRecognizer.gestureCompleteEvent += OnGestureComplete; TouchKit.addGestureRecognizer(pinchRecognizer); var rotationRecognizer = new TKRotationRecognizer(); rotationRecognizer.gestureRecognizedEvent += OnRotationRecognized; TouchKit.addGestureRecognizer(rotationRecognizer); var tapRecognizer = new TKTapRecognizer(); tapRecognizer.gestureRecognizedEvent += OnTapRecognized; TouchKit.addGestureRecognizer(tapRecognizer); SetupShowMainTableTweens(); }
// Use this for initialization void Start() { instance = this; print("GameManager instance change, Showcase mode is " + (instance.mainMenuMode ? "on" : "off")); if (!mainMenuMode) { GameLevel = 1; EndDayManager.AddExpense(ExpenseType.Maintenance, Departments.Start, maintenanceCost); Cash = startingMoney; rt.gestureRecognizedEvent += (i) => { if (!EndDayManager.IsPanelOpen) { cameraPivot.Rotate(Vector3.up, -rt.deltaRotation * rotateSensitivity, Space.World); } }; pr.gestureRecognizedEvent += (i) => { if (!EndDayManager.IsPanelOpen) { Camera.main.transform.Translate(Vector3.forward * 2 * pr.deltaScale * pinchSensitivity); } }; TouchKit.addGestureRecognizer(rt); TouchKit.addGestureRecognizer(pr); DaytimeManager.OnDayEnd += DaytimeManager_OnDayEnd; EventManager.RunStartEvent(); gameFaderAnim.Play("FadeOut"); } }
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(); }
public void SetInputSystem() { TouchKit.removeAllGestureRecognizers(); if (PlaybackManager.isPlaying == PlaybackManager.PlayStates.Playing) { return; } if (lineEditMode == LineEditMode.Camera) { //pan camera var panRecognizer = new TKPanRecognizer(); panRecognizer.gestureRecognizedEvent += (r) => { OnPanCamera(r); }; TouchKit.addGestureRecognizer(panRecognizer); //pinch zoom var pinchRecognizer = new TKPinchRecognizer(); pinchRecognizer.gestureRecognizedEvent += (r) => { OnZoomCamera(r); }; TouchKit.addGestureRecognizer(pinchRecognizer); } else if (lineEditMode == LineEditMode.Erase) { //eraser var tapRecognizer = new TKTapRecognizer(); tapRecognizer.zIndex = 2; tapRecognizer.numberOfTapsRequired = 1; tapRecognizer.gestureRecognizedEvent += (r) => { print(r); Erase(r); }; TouchKit.addGestureRecognizer(tapRecognizer); } else { //draw var drawRecognizer = new TKButtonRecognizer(new TKRect(0, 0, Screen.width, Screen.height)); drawRecognizer.zIndex = 0; drawRecognizer.onSelectedEvent += (r) => { OnDrawLineStart(r); }; drawRecognizer.onTouchUpInsideEvent += (r) => { OnDrawLineEnd(r); }; TouchKit.addGestureRecognizer(drawRecognizer); switch (lineEditMode) { case LineEditMode.DrawAccelerator: lineType = LineType.LineTypes.Accelerator; break; case LineEditMode.DrawBounce: lineType = LineType.LineTypes.Bounce; break; case LineEditMode.DrawBrake: lineType = LineType.LineTypes.Brake; break; case LineEditMode.DrawNormal: lineType = LineType.LineTypes.Normal; break; } } }