Ejemplo n.º 1
0
        private void MovePivot(PlayerCamCtrlSettings settings, bool pivotPreciseMode, bool cursorPreciseMode, Vector3 offset)
        {
            if (offset != Vector3.zero)
            {
                m_lockMouseToWorld = false;

                Vector3 offsetW = m_camera.cameraToWorldMatrix.MultiplyVector(offset);
                offsetW.y = 0;

                Vector3 newPivot = offsetW * settings.MoveSensitivity * Time.deltaTime;
                if (pivotPreciseMode || cursorPreciseMode)
                {
                    newPivot /= 5.0f;
                }
                newPivot += m_targetPivot;

                MapPos newMapPivot = m_voxelMap.GetMapPosition(newPivot, Weight);
                SetMapPivot(newMapPivot);
                m_targetPivot = newPivot;
            }
            else
            {
                Vector3 toPivot = m_targetPivot - m_boundsCenter;
                toPivot.y = 0;
                if (toPivot.magnitude > m_allowedRadius)
                {
                    toPivot       = toPivot.normalized * m_allowedRadius;
                    m_targetPivot = Vector3.up * m_targetPivot.y + m_boundsCenter + toPivot;
                }
            }
        }
Ejemplo n.º 2
0
        private void ReadPlayerCamSettings()
        {
            PlayerCamCtrlSettings settings = m_settings.PlayerCamCtrl[LocalPlayerIndex];

            m_camDistance = Mathf.Lerp(settings.MinCamDistance, settings.MaxCamDistance, 0.33f);
            m_camToVector = settings.ToCamVector.normalized;
        }
Ejemplo n.º 3
0
        protected override void Start()
        {
            var nav = m_selectableMinimap.navigation;

            nav.mode = m_input.IsKeyboardAndMouse(m_viewport.LocalPlayerIndex) ? UnityEngine.UI.Navigation.Mode.None : UnityEngine.UI.Navigation.Mode.Explicit;
            m_selectableMinimap.navigation = nav;

            m_eventSystem      = Dependencies.EventSystemManager.GetEventSystem(m_viewport.LocalPlayerIndex);
            m_cameraController = Dependencies.GameView.GetCameraController(m_viewport.LocalPlayerIndex);
            m_camCtrlSettings  = Dependencies.Settings.PlayerCamCtrl[m_viewport.LocalPlayerIndex];

            if (m_minimap.IsLoaded)
            {
                OnMinimapTextureChanged(this, EventArgs.Empty);
            }
            m_minimap.TextureChanged += OnMinimapTextureChanged;

            base.Start();
            StartCoroutine(Fit());
            UpdateVisibility();
        }
Ejemplo n.º 4
0
        public void MovePivot(Vector2 offset)
        {
            PlayerCamCtrlSettings settings = m_settings.PlayerCamCtrl[LocalPlayerIndex];

            MovePivot(settings, false, false, offset);
        }
Ejemplo n.º 5
0
        private void Update()
        {
            if (CursorHelper.lockState == CursorLockMode.None)
            {
                return;
            }

            PlayerCamCtrlSettings settings = m_settings.PlayerCamCtrl[LocalPlayerIndex];
            float cursorX = m_inputManager.GetAxisRaw(InputAction.CursorX, LocalPlayerIndex, false, false);
            float cursorY = m_inputManager.GetAxisRaw(InputAction.CursorY, LocalPlayerIndex, false, false);

            if (m_gameState.IsActionsMenuOpened(LocalPlayerIndex) ||
                m_gameState.IsMenuOpened(LocalPlayerIndex) ||
                m_gameState.IsPaused || m_gameState.IsPauseStateChanging ||
                m_camPixelRect.size == Vector2.zero ||
                m_boxSelector.IsActive)
            {
                if (m_prevMouseOffset != Vector3.zero)
                {
                    CursorIconFromMouseOffset(Vector3.zero);
                    m_prevMouseOffset = Vector3.zero;
                }

                if (m_isVirtualMouseEnabled)
                {
                    m_clampCursorPadding  = 1;
                    VirtualMousePosition += new Vector2(cursorX, cursorY) * settings.CursorSensitivity;
                    m_clampCursorPadding  = 0;
                }

                AnimatePivotPoint(settings.MoveSensitivity / 2, settings.MoveSensitivity / 8);
                return;
            }

            Vector3 mouseOffset = GetVirtualMouseOffset();

            if (IsInputEnabled && !m_lockInputDuringPivotAnimation)
            {
                float deltaY       = m_inputManager.GetAxisRaw(InputAction.MoveForward, LocalPlayerIndex, true, false);
                float deltaX       = m_inputManager.GetAxisRaw(InputAction.MoveSide, LocalPlayerIndex, true, false);
                bool  rotateCamCW  = m_inputManager.GetButton(InputAction.LT, LocalPlayerIndex, true, false);
                bool  rotateCamCCW = m_inputManager.GetButton(InputAction.RT, LocalPlayerIndex, true, false);

                bool aPressed          = m_inputManager.GetButton(InputAction.A, LocalPlayerIndex);
                bool pivotPreciseMode  = aPressed | m_inputManager.GetButton(InputAction.RightStickButton, LocalPlayerIndex, true, false);
                bool cursorPreciseMode = aPressed | m_inputManager.GetButton(InputAction.LeftStickButton, LocalPlayerIndex, true, false);
                if (m_inputManager.IsAnyButtonDown(LocalPlayerIndex, false, false))
                {
                    m_lockMouseToWorld = false;
                }

                if (m_inputManager.GetButtonUp(InputAction.LT, LocalPlayerIndex, true, false) || m_inputManager.GetButtonUp(InputAction.RT, LocalPlayerIndex, true, false))
                {
                    if (!rotateCamCW && !rotateCamCCW)
                    {
                        m_cursorIcon.sprite = m_spritePointer;
                    }
                }

                if (m_inputManager.GetButtonUp(InputAction.MMB, LocalPlayerIndex))
                {
                    m_cursorIcon.sprite = m_spritePointer;
                }
                else if (m_inputManager.GetButton(InputAction.MMB, LocalPlayerIndex))
                {
                    m_lockMouseToWorld = false;

                    MoveVirtualMouseToCenterOfScreen();

                    m_camAngle += Time.deltaTime * cursorX * m_settings.PlayerCamCtrl[LocalPlayerIndex].RotateSensitivity;
                    SetCameraPosition();

                    if (cursorX != 0)
                    {
                        m_cursorIcon.sprite = cursorX > 0 ? m_spriteRotateCW : m_spriteRotateCCW;
                    }
                    else
                    {
                        m_cursorIcon.sprite = m_spritePointer;
                    }

                    cursorX = 0;
                    cursorY = 0;
                }
                else
                {
                    if (rotateCamCW && !rotateCamCCW)
                    {
                        m_cursorIcon.sprite = m_spriteRotateCW;
                        MoveVirtualMouseToCenterOfScreen();
                        m_camAngle += Time.deltaTime * settings.RotateSensitivity;
                        SetCameraPosition();
                    }
                    else if (rotateCamCCW && !rotateCamCW)
                    {
                        m_cursorIcon.sprite = m_spriteRotateCCW;
                        MoveVirtualMouseToCenterOfScreen();
                        m_camAngle -= Time.deltaTime * settings.RotateSensitivity;
                        SetCameraPosition();
                    }

                    if (cursorX != 0 && cursorY != 0)
                    {
                        float cursorSens = settings.CursorSensitivity;
                        if (cursorPreciseMode || pivotPreciseMode)
                        {
                            cursorSens /= 5.0f;
                        }
                        else
                        {
                            cursorSens *= VirtualMouseSensitivityScale;
                        }

                        if (m_isVirtualMouseEnabled)
                        {
                            VirtualMousePosition += new Vector2(cursorX, cursorY) * cursorSens;
                        }
                        m_lockMouseToWorld = false;
                    }
                }

                Vector3 deltaOffset = new Vector3(deltaX, deltaY, 0);
                Vector3 offset      = Vector2.zero;
                if (deltaOffset != Vector3.zero)
                {
                    offset      = deltaOffset;
                    mouseOffset = Vector2.zero;
                }
                else
                {
                    if (!m_lockMouseToWorld)
                    {
                        offset = mouseOffset;
                    }
                }

                MovePivot(settings, pivotPreciseMode, cursorPreciseMode, offset);

                if (m_prevMouseOffset != mouseOffset)
                {
                    CursorIconFromMouseOffset(mouseOffset);
                    m_prevMouseOffset = mouseOffset;
                }
            }

            AnimatePivotPoint(settings.MoveSensitivity / 2, settings.MoveSensitivity / 8);

            if (m_lockMouseToWorld)
            {
                Vector2 targetMousePos = m_camera.WorldToScreenPoint(m_lockMousePosWorld);

                if (m_animateMousePosition)
                {
                    SetVirtualMousePosition(Vector2.Lerp(VirtualMousePosition, targetMousePos, Time.deltaTime * 20));
                    CursorIconFromMouseOffset(mouseOffset);
                }
                else
                {
                    SetVirtualMousePosition(targetMousePos);
                    CursorIconFromMouseOffset(mouseOffset);
                }
            }
            Debug.DrawLine(Pivot, Pivot + Vector3.up, Color.red);
        }