Пример #1
0
    private void Update()
    {
        // Pan.
        if (_currentPanValue.magnitude > JoystickDeadZone)
        {
            _mapNavigation.Pan(_currentPanValue, true);
        }

        // Zoom and Rotate - share the same touchpad button.
        var rotateZoomMagnitude = _currentRotateZoomValue.magnitude;

        if (rotateZoomMagnitude > JoystickDeadZone)
        {
            var angle = Mathf.Rad2Deg * Mathf.Abs(Mathf.Atan2(_currentRotateZoomValue.y, _currentRotateZoomValue.x));

            // Zoom.
            if (_isRotateZoomButtonDown)
            {
                if ((angle > 45 && angle < 135))
                {
                    _mapNavigation.Zoom(2.0f * Mathf.Sign(_currentRotateZoomValue.y)); // Need to hookup Gaze.
                }
            }

            // Rotate.
            if (_isRotateZoomButtonDownThisFrame && rotateZoomMagnitude > 0.5f)
            {
                if (angle > 145 && angle < 215)
                {
                    _mapNavigation.RotateMap(true);
                }
                else if (angle < 35)
                {
                    _mapNavigation.RotateMap(false);
                }
            }
        }

        // This bool should only be true for the first frame which the rotate/zoom button was pressed.
        _isRotateZoomButtonDownThisFrame = false;
    }
    private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj)
    {
        if (obj.state.source.handedness.Equals(InteractionSourceHandedness.Right))
        {
            // Handle panning from touchpad.
            if (obj.state.touchpadPosition.magnitude > TouchpadDeadzone && obj.state.touchpadPressed)
            {
                _mapNavigation.Pan(obj.state.touchpadPosition, true);
            }
        }

        if (obj.state.source.handedness.Equals(InteractionSourceHandedness.Left))
        {
            var magnitude = obj.state.touchpadPosition.magnitude;
            if (magnitude > TouchpadDeadzone && obj.state.touchpadPressed)
            {
                const float halfValidPressRangeInDegrees = 0.5f * 60; // Should be less than 45 degrees to not overlap.

                var normalizedTouchpadPosition = obj.state.touchpadPosition.normalized;
                var angle = Mathf.Rad2Deg * Mathf.Atan2(normalizedTouchpadPosition.y, normalizedTouchpadPosition.x);
                //Debug.Log(angle + ": " + normalizedTouchpadPosition.x + ", " + normalizedTouchpadPosition.y);

                // Handle continuous zooming from touchpad up/down.
                if (Mathf.Abs(90 - angle) < halfValidPressRangeInDegrees)
                {
                    _mapNavigation.Zoom(1);
                }
                else if (Mathf.Abs(-90 - angle) < halfValidPressRangeInDegrees)
                {
                    _mapNavigation.Zoom(-1);
                }

                // Handle rotation from touchpad left/right.
                else if (Mathf.Abs(angle) < halfValidPressRangeInDegrees && magnitude > RotationThreshold)
                {
                    if (!_rotated)
                    {
                        _mapNavigation.RotateMap(true);
                        _rotated = true;
                    }
                }
                else if (
                    (Mathf.Abs(180 - angle) < halfValidPressRangeInDegrees || Mathf.Abs(-180 - angle) < halfValidPressRangeInDegrees) &&
                    magnitude > RotationThreshold)
                {
                    if (!_rotated)
                    {
                        _mapNavigation.RotateMap(false);
                        _rotated = true;
                    }
                }
                else
                {
                    _rotated = false;
                }
            }
            else
            {
                _rotated = false;
            }
        }
    }