private void VerifyFailGestureAfterDelay(GestureTouch currentTouch) { float elapsedSeconds = VelocityTracker.ElapsedSeconds; if (touchId == currentTouch.Id && State == GestureRecognizerState.Possible && elapsedSeconds >= MinimumDurationSeconds) { VelocityTracker.Restart(currentTouch.X, currentTouch.Y); SetState(GestureRecognizerState.Began); } }
private void ProcessMouseWheel() { // if the mouse is not setup or the user doesn't want the mouse treated as touches, return right away if (!Input.mousePresent || !TreatMousePointerAsFinger) { return; } // the mouse wheel will act as a rotate and pinch / zoom const float threshold = 50.0f; const float deltaModifier = 0.025f; Vector2 delta = Input.mouseScrollDelta; float scrollDelta = (delta.y == 0.0f ? delta.x : delta.y) * deltaModifier; // add type 1 = moved, 2 = begin, 3 = ended, 4 = none int addType1 = 4; int addType2 = 4; // left or right control initial down means begin if (!RequireControlKeyForMouseZoom) { if (delta == Vector2.zero) { if (lastMouseWheelTime != System.DateTime.MinValue) { if ((System.DateTime.UtcNow - lastMouseWheelTime).TotalSeconds < 1.0f) { // continue zooming pinchScale = Mathf.Max(0.35f, pinchScale + scrollDelta); addType1 = 1; } else { // stop zooming lastMouseWheelTime = System.DateTime.MinValue; addType1 = 3; } } } else if (lastMouseWheelTime == System.DateTime.MinValue) { // start zooming addType1 = 2; lastMouseWheelTime = System.DateTime.UtcNow; } else { // continue zooming pinchScale = Mathf.Max(0.35f, pinchScale + scrollDelta); addType1 = 1; lastMouseWheelTime = System.DateTime.UtcNow; } } else if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl)) { // initial start of scale addType1 = 2; } // left or right control still down means move else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) { pinchScale = Mathf.Max(0.35f, pinchScale + scrollDelta); addType1 = 1; } // left or right control initial up means end else if (Input.GetKeyUp(KeyCode.LeftControl) || Input.GetKeyUp(KeyCode.RightControl)) { addType1 = 3; } // left or right shift initial down means begin if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift)) { addType2 = 2; } // left or right shift still down means move else if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { rotateAngle += scrollDelta; addType2 = 1; } // left or right shift initial up means end else if (Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.RightShift)) { addType2 = 3; } // use the minimum add type so that moves are preferred over begins and begins are preferred over ends int addType = Mathf.Min(addType1, addType2); // no begins, moves or ends, set defaults and end if (addType == 4) { pinchScale = 1.0f; rotateAngle = 0.0f; return; } // calculate rotation float x = Input.mousePosition.x; float y = Input.mousePosition.y; float xRot1 = x - threshold; float yRot1 = y; float xRot2 = x + threshold; float yRot2 = y; float distance = threshold * pinchScale; xRot1 = x - distance; yRot1 = y; xRot2 = x + distance; yRot2 = y; RotateAroundPoint(ref xRot1, ref yRot1, x, y, rotateAngle); RotateAroundPoint(ref xRot2, ref yRot2, x, y, rotateAngle); #if DEBUG if (scrollDelta != 0.0f) { //Debug.LogFormat("Mouse delta: {0}", scrollDelta); } #endif // calculate rotation and zoom based on mouse values if (addType == 1) { // moved rotatePinch1 = new GestureTouch(int.MaxValue - 5, xRot1, yRot1, rotatePinch1.X, rotatePinch1.Y, 0.0f, xRot1, yRot1, null, TouchPhase.Moved); rotatePinch2 = new GestureTouch(int.MaxValue - 6, xRot2, yRot2, rotatePinch2.X, rotatePinch2.Y, 0.0f, xRot2, yRot2, null, TouchPhase.Moved); FingersProcessTouch(ref rotatePinch1); FingersProcessTouch(ref rotatePinch2); } else if (addType == 2) { // begin rotatePinch1 = new GestureTouch(int.MaxValue - 5, xRot1, yRot1, xRot1, yRot1, 0.0f, xRot1, yRot1, null, TouchPhase.Began); rotatePinch2 = new GestureTouch(int.MaxValue - 6, xRot2, yRot2, xRot2, yRot2, 0.0f, xRot1, yRot1, null, TouchPhase.Began); FingersProcessTouch(ref rotatePinch1); FingersProcessTouch(ref rotatePinch2); } else if (addType == 3) { // end rotatePinch1 = new GestureTouch(int.MaxValue - 5, xRot1, yRot1, xRot1, yRot1, 0.0f, xRot1, yRot1, null, TouchPhase.Ended); rotatePinch2 = new GestureTouch(int.MaxValue - 6, xRot2, yRot2, xRot2, yRot2, 0.0f, xRot1, yRot1, null, TouchPhase.Ended); FingersProcessTouch(ref rotatePinch1); FingersProcessTouch(ref rotatePinch2); } }
private void FingersContinueTouch(ref GestureTouch g) { touchesMoved.Add(g); previousTouchPositions[g.Id] = new Vector2(g.X, g.Y); }
private void GestureTouchFromTouch(ref Touch t, out GestureTouch g) { g = new GestureTouch(t.fingerId, t.position.x, t.position.y, t.position.x - t.deltaPosition.x, t.position.y - t.deltaPosition.y, 0.0f); }
private void ProcessMouseWheel() { if (!Input.mousePresent || !TreatMousePointerAsFinger) { return; } const float threshold = 100.0f; const float deltaModifier = 0.025f; Vector2 delta = Input.mouseScrollDelta; float scrollDelta = (delta.y == 0.0f ? delta.x : delta.y) * deltaModifier; int addType1 = 4; int addType2 = 4; if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl)) { addType1 = 2; } else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) { pinchScale += scrollDelta; addType1 = 1; } else if (Input.GetKeyUp(KeyCode.LeftControl) || Input.GetKeyUp(KeyCode.RightControl)) { addType1 = 3; } if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift)) { addType2 = 2; } else if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { rotateAngle += scrollDelta; addType2 = 1; } else if (Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.RightShift)) { addType2 = 3; } int addType = Mathf.Min(addType1, addType2); if (addType == 4) { pinchScale = 1.0f; rotateAngle = 0.0f; return; } float x = Input.mousePosition.x; float y = Input.mousePosition.y; float xRot1 = x - threshold; float yRot1 = y; float xRot2 = x + threshold; float yRot2 = y; float distance = threshold * pinchScale; xRot1 = x - distance; yRot1 = y; xRot2 = x + distance; yRot2 = y; RotateAroundPoint(ref xRot1, ref yRot1, x, y, rotateAngle); RotateAroundPoint(ref xRot2, ref yRot2, x, y, rotateAngle); #if DEBUG if (scrollDelta != 0.0f) { Debug.Log("Mouse delta: " + scrollDelta); } #endif if (addType == 1) { // moved rotatePinch1 = new GestureTouch(int.MaxValue - 5, xRot1, yRot1, rotatePinch1.X, rotatePinch1.Y, 0.0f); rotatePinch2 = new GestureTouch(int.MaxValue - 6, xRot2, yRot2, rotatePinch2.X, rotatePinch2.Y, 0.0f); touchesMoved.Add(rotatePinch1); touchesMoved.Add(rotatePinch2); } else if (addType == 2) { // begin rotatePinch1 = new GestureTouch(int.MaxValue - 5, xRot1, yRot1, xRot1, yRot1, 0.0f); rotatePinch2 = new GestureTouch(int.MaxValue - 6, xRot2, yRot2, xRot2, yRot2, 0.0f); touchesBegan.Add(rotatePinch1); touchesBegan.Add(rotatePinch2); } else if (addType == 3) { // end touchesEnded.Add(rotatePinch1); touchesEnded.Add(rotatePinch2); } }
private void AddMouseTouch(int index, int id, float x, float y) { float prevX = mousePrev[index].Key; float prevY = mousePrev[index].Value; prevX = (prevX == float.MinValue ? x : prevX); prevY = (prevY == float.MinValue ? y : prevY); GestureTouch g = new GestureTouch(mousePointerId1, x, y, prevX, prevY, 0.0f); if (Input.GetMouseButtonDown(index)) { mousePrev[index] = new KeyValuePair<float, float>(x, y); touchesBegan.Add(g); } else if (Input.GetMouseButton(index)) { mousePrev[index] = new KeyValuePair<float, float>(x, y); touchesMoved.Add(g); } else if (Input.GetMouseButtonUp(index)) { mousePrev[index] = new KeyValuePair<float, float>(float.MinValue, float.MinValue); touchesEnded.Add(g); } }
private void GestureTouchFromMouse(float mx, float my, out GestureTouch g) { float prevX, prevY; if (previousMouseX == float.MinValue) { prevX = mx; prevY = my; } else { prevX = previousMouseX; prevY = previousMouseY; } g = new GestureTouch(mousePointerId, mx, my, prevX, prevY, 0.0f); }