/// <summary> /// Gets the zoom speed based on player input /// </summary> /// <returns>The speed the camera should zoom in/out during the next frame, may be 0</returns> private float Scroll() { if (_zoomCamera.activeControl != null && _zoomCamera.activeControl.device == Mouse.current) { return(_zoomCamera.ReadValue <float>() * scrollSpeed); } if (Touch.activeFingers.Count != 2) { return(0f); } Touch touchZero = Touch.activeTouches[0]; Touch touchOne = Touch.activeTouches[1]; // Find the position in the previous frame of each touch. Vector2 touchZeroPrevPos = touchZero.screenPosition - touchZero.delta; Vector2 touchOnePrevPos = touchOne.screenPosition - touchOne.delta; // Find the magnitude of the vector (the distance) between the touches in each frame. float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude; float touchDeltaMag = (touchZero.screenPosition - touchOne.screenPosition).magnitude; // var touchZeroDeltaMag = Touch.activeTouches[0].delta.magnitude; // var touchOneDeltaMag = Touch.activeTouches[1].delta.magnitude; // Find the difference in the distances between each frame. return((touchDeltaMag - prevTouchDeltaMag) * pinchSpeed); }
public void ValidateInput() { for (int i = 0; i < _currentInputCount; i++) { bool valid = true; //If touch, check event is still active? if (_activeDragInputs[i]._touchId != 0) { //Check touch is still active Touch touch = GetTouch(_activeDragInputs[i]._touchId); valid = touch.valid && touch.phase != TouchPhase.None && touch.phase != TouchPhase.Canceled; } //Check touch is still active if (!valid) { //Remove touch for (int j = i; j < _currentInputCount - 1; j++) { _activeDragInputs[j] = _activeDragInputs[j + 1]; } _currentInputCount--; } } }