private void ProcessLostTouches() { // handle lost touches due to Unity bugs, Unity can not send touch end states properly // and it appears that even the id's of touches can change in WebGL foreach (GestureTouch t in this.m_PrevTouches) { if (!this.m_CurrentTouches.Contains(t)) { this.m_TempTouches.Add(t); } } foreach (IGestureActionCallbackBase g in gestures) { bool reset = false; foreach (GestureTouch t in g.m_CurrentTrackGestrueList) { if (!this.m_CurrentTouches.Contains(t)) { this.m_TempTouches.Add(t); reset = true; } } if (reset) { g.Reset(); } } foreach (GestureTouch t in this.m_TempTouches) { // only end touch here, as end touch removes from previousTouches list GestureTouch tmp = t; FingersEndTouch(ref tmp, true); this.m_PrevTouches.Remove(tmp); } this.m_TempTouches.Clear(); }
private void ProcessMouseWheel() { if (Input.mousePresent == false) { return; } var delta = Input.mouseScrollDelta; float scrollDelta = delta.y == 0.0f ? delta.x : delta.y * this.MouseWheelDeltaMutliplier; var threshold = DeviceInfo.UnitToPixels(this.MouseDistanceInUnitsRotationAndScale * 0.5f); this.operatorType = EMouseOperatorType.None; if (this.RequireControlKeyForMouseZoom == false) { if (delta == Vector2.zero) { if (this.lastMouseWheelTime != DateTime.MinValue) { var whellTime = (DateTime.UtcNow - this.lastMouseWheelTime).TotalSeconds; if (whellTime < 1.0f) { //继续滚动 pinchScale = Mathf.Max(0.35f, pinchScale + scrollDelta); this.operatorType = EMouseOperatorType.Move; } else { //停止滚动 this.operatorType = EMouseOperatorType.End; this.lastMouseWheelTime = DateTime.MinValue; } } } else if (this.lastMouseWheelTime == DateTime.MinValue) { this.operatorType = EMouseOperatorType.Begin; this.lastMouseWheelTime = DateTime.UtcNow; } else { this.pinchScale = Mathf.Max(0.35f, this.pinchScale + scrollDelta); this.operatorType = EMouseOperatorType.Move; this.lastMouseWheelTime = DateTime.UtcNow; } } else if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl)) { this.operatorType = EMouseOperatorType.Begin; } else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) { this.operatorType = EMouseOperatorType.Move; this.pinchScale = Mathf.Max(0.35f, this.pinchScale + scrollDelta); } else if (Input.GetKeyUp(KeyCode.LeftControl) || Input.GetKeyUp(KeyCode.RightControl)) { this.operatorType = EMouseOperatorType.End; } if (this.operatorType == EMouseOperatorType.None) { this.pinchScale = 1; this.rotationAngle = 0; return; } //计算旋转 float x = Input.mousePosition.x; float y = Input.mousePosition.y; float xRot1 = x - threshold; float yRot1 = y; float xRot2 = threshold + x; float yRot2 = y; float distance = threshold * pinchScale; xRot1 = x - distance; yRot2 = y; xRot2 = x + distance; yRot2 = y; this.RotateAroundPoint(ref xRot1, ref yRot1, x, y, this.rotationAngle); this.RotateAroundPoint(ref xRot2, ref yRot2, x, y, this.rotationAngle); if (this.operatorType == EMouseOperatorType.Move) { this.rotatePinch1 = new GestureTouch(MouseGestureRotationId1, new Vector2(xRot1, yRot1), this.rotatePinch1.GetCurPos(), TouchPhase.Moved); this.rotatePinch2 = new GestureTouch(MouseGestureRotationId2, new Vector2(xRot2, yRot2), this.rotatePinch2.GetCurPos(), TouchPhase.Moved); this.ProcessFingerTouch(ref this.rotatePinch1); this.ProcessFingerTouch(ref this.rotatePinch2); } else if (this.operatorType == EMouseOperatorType.Begin) { this.rotatePinch1 = new GestureTouch(MouseGestureRotationId1, new Vector2(xRot1, yRot1), this.rotatePinch1.GetCurPos(), TouchPhase.Began); this.rotatePinch2 = new GestureTouch(MouseGestureRotationId2, new Vector2(xRot2, yRot2), this.rotatePinch2.GetCurPos(), TouchPhase.Began); this.ProcessFingerTouch(ref this.rotatePinch1); this.ProcessFingerTouch(ref this.rotatePinch2); } else if (this.operatorType == EMouseOperatorType.End) { this.rotatePinch1 = new GestureTouch(MouseGestureRotationId1, new Vector2(xRot1, yRot1), this.rotatePinch1.GetCurPos(), TouchPhase.Ended); this.rotatePinch2 = new GestureTouch(MouseGestureRotationId2, new Vector2(xRot2, yRot2), this.rotatePinch2.GetCurPos(), TouchPhase.Ended); this.ProcessFingerTouch(ref this.rotatePinch1); this.ProcessFingerTouch(ref this.rotatePinch2); } }