Beispiel #1
0
        private void UpdateInput()
        {
            this.m_ConsumeTurn = false;
            this.m_ConsumeZoom = false;
            if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) && EventSystem.current != null && UnityTools.IsPointerOverUI())
            {
                this.m_GUIClick = true;
            }

            if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1))
            {
                this.m_GUIClick = false;
            }

            if (!this.m_GUIClick)
            {
                for (int i = 0; i < this.m_Presets.Length; i++)
                {
                    CameraSettings preset = this.m_Presets[i];
                    switch (preset.Activation)
                    {
                    case CameraSettings.ActivationType.Button:
                        if (Input.GetButtonDown(preset.InputName))
                        {
                            preset.IsActive = true;
                        }
                        if (Input.GetButtonUp(preset.InputName))
                        {
                            preset.IsActive = false;
                        }
                        break;

                    case CameraSettings.ActivationType.Toggle:
                        if (Input.GetButtonDown(preset.InputName))
                        {
                            preset.IsActive = !preset.IsActive;
                        }
                        break;
                    }
                }
            }
            for (int i = 0; i < this.m_Presets.Length; i++)
            {
                CameraSettings preset = this.m_Presets[i];
                if (preset.IsActive)
                {
                    if (this.m_ActivePreset != preset)
                    {
                        this.m_ActivePreset = preset;
                        ApplyCrosshair(this.m_ActivePreset.Crosshair);
                    }
                    break;
                }
            }

            if (this.m_ActivePreset.ConsumeInputOverUI && this.m_GUIClick)
            {
                this.m_ConsumeTurn = true;
                this.m_ConsumeZoom = true;
            }

            if (!this.m_ConsumeTurn && (string.IsNullOrEmpty(this.m_ActivePreset.TurnButton) || Input.GetButton(this.m_ActivePreset.TurnButton)))
            {
                float x = Input.GetAxis("Mouse X") * this.m_ActivePreset.TurnSpeed;
                float y = Input.GetAxis("Mouse Y") * this.m_ActivePreset.TurnSpeed;

                if (this.m_ActivePreset.VisibilityDelta == 0f || Mathf.Abs(x) > this.m_ActivePreset.VisibilityDelta || Mathf.Abs(y) > this.m_ActivePreset.VisibilityDelta)
                {
                    Cursor.lockState        = CursorLockMode.Locked;
                    Cursor.visible          = false;
                    this.m_RotatedLastFrame = true;
                }
                this.m_MouseX += x;
                this.m_MouseY -= y;


                if (Mathf.Abs(this.m_ActivePreset.YawLimit.x) + Mathf.Abs(this.m_ActivePreset.YawLimit.y) < 360)
                {
                    this.m_MouseX = ClampAngle(this.m_MouseX, this.m_ActivePreset.YawLimit.x, this.m_ActivePreset.YawLimit.y);
                }
                this.m_MouseY = ClampAngle(this.m_MouseY, this.m_ActivePreset.PitchLimit.x, this.m_ActivePreset.PitchLimit.y);
            }
            else if (this.m_RotatedLastFrame)
            {
                Cursor.lockState        = this.m_ActivePreset.CursorMode;
                Cursor.visible          = this.m_ActivePreset.CursorMode == CursorLockMode.Locked ? false : true;
                this.m_RotatedLastFrame = false;
            }

            if (!this.m_ConsumeZoom)
            {
                this.m_ActivePreset.Zoom -= Input.GetAxis("Mouse ScrollWheel") * this.m_ActivePreset.ZoomSpeed;
                this.m_ActivePreset.Zoom  = Mathf.Clamp(this.m_ActivePreset.Zoom, this.m_ActivePreset.ZoomLimit.x - this.m_ActivePreset.Distance, this.m_ActivePreset.ZoomLimit.y - this.m_ActivePreset.Distance);
            }
        }