Пример #1
0
    private void Update()
    {
        #region TOGGLE PAUSE MENU
        if (PauseMenu && uiLevels.Count > 0 && currentLevel == 0)
        {
            InputController.PlayerInput playerInput = InputController.Instance.playerInput[0];

            switch (playerInput.controlMode)
            {
            case InputController.ControlsMode.KeyboardMouse:
                if (playerInput.keyboard.escapeKey.wasPressedThisFrame)
                {
                    TogglePauseMenu();
                }
                break;

            case InputController.ControlsMode.Controller:
                if (playerInput.gamepad.startButton.wasPressedThisFrame || (playerInput.gamepad.buttonEast.wasPressedThisFrame && PauseMenu.activeSelf))
                {
                    TogglePauseMenu();
                }

                break;
            }
        }
        #endregion
    }
Пример #2
0
    private void Update()
    {
        InputController.PlayerInput player1Input = InputController.Instance.playerInput[0];
        switch (player1Input.controlMode)
        {
        case InputController.ControlsMode.KeyboardMouse:
            if (player1Input.keyboard.spaceKey.wasPressedThisFrame)
            {
                Play();
            }
            if (player1Input.keyboard.escapeKey.wasPressedThisFrame)
            {
                Back();
            }
            break;

        case InputController.ControlsMode.Controller:
            if (player1Input.gamepad.startButton.wasPressedThisFrame)
            {
                Play();
            }
            if (player1Input.gamepad.buttonEast.wasPressedThisFrame)
            {
                Back();
            }
            break;
        }

        if (Keyboard.current.spaceKey.wasPressedThisFrame)
        {
            if (InputController.Instance.SetInput(InputController.ControlsMode.KeyboardMouse, 0) == 0)
            {
                player1.sprite   = keyboardImg;
                playLabel.sprite = spaceLabel;
                BImage.gameObject.SetActive(false);
                escImage.gameObject.SetActive(true);
            }
        }

        if (Keyboard.current.enterKey.wasPressedThisFrame)
        {
            if (InputController.Instance.SetInput(InputController.ControlsMode.KeyboardMouse, 1) == 1)
            {
                player2.sprite = keyboardImg;
            }
        }

        foreach (Gamepad gamepad in Gamepad.all)
        {
            if (gamepad.startButton.wasPressedThisFrame)
            {
                int id = InputController.Instance.SetInput(InputController.ControlsMode.Controller, -1, gamepad);

                switch (id)
                {
                case 0:
                    player1.sprite = gamepadImg;
                    escImage.gameObject.SetActive(false);
                    BImage.gameObject.SetActive(true);
                    break;

                case 1: player2.sprite = gamepadImg; break;
                }
            }
        }
    }
Пример #3
0
    private void Update()
    {
        if (SceneManager.GetActiveScene().name == "MainMenu")
        {
            if (Gamepad.current != null && (Gamepad.current.allControls.Any(x => x is ButtonControl && x.IsPressed() && !x.synthetic) || Gamepad.current.leftStick.ReadValue().magnitude >= InputController.idleStickThreshold))
            {
                if (!BBack.activeSelf)
                {
                    BBack.SetActive(true);
                    escBack.SetActive(false);
                }
            }

            if (Keyboard.current.anyKey.wasPressedThisFrame || Mouse.current.delta.IsActuated(0.2f))
            {
                if (!escBack.activeSelf)
                {
                    escBack.SetActive(true);
                    BBack.SetActive(false);
                }
            }

            if (Keyboard.current.escapeKey.wasPressedThisFrame)
            {
                StartCoroutine(OnBackPressed());
            }

            if (Gamepad.current != null && Gamepad.current.buttonEast.wasPressedThisFrame)
            {
                StartCoroutine(OnBackPressed());
            }
        }
        else
        {
            InputController.PlayerInput playerInput = InputController.Instance.playerInput[0];

            switch (playerInput.controlMode)
            {
            case InputController.ControlsMode.KeyboardMouse:
                if (BBack.activeSelf)
                {
                    BBack.SetActive(false);
                    escBack.SetActive(true);
                }

                if (playerInput.keyboard.escapeKey.wasPressedThisFrame)
                {
                    StartCoroutine(OnBackPressed());
                }

                break;

            case InputController.ControlsMode.Controller:
                if (escBack.activeSelf)
                {
                    escBack.SetActive(false);
                    BBack.SetActive(true);
                }

                if (playerInput.gamepad.buttonEast.wasPressedThisFrame)
                {
                    StartCoroutine(OnBackPressed());
                }
                break;
            }
        }
    }
Пример #4
0
    protected override void Update()
    {
        float prevPercent = percent;

        if (isClicked)
        {
            percent = (Mouse.current.position.ReadValue().x - rectTransform.position.x) / progressBar.rect.width;
            percent = Mathf.Floor(percent * 10) / 10;
            percent = Mathf.Clamp(percent, 0, 1f);

            if (prevPercent != percent)
            {
                OnVolumeChanged();
            }
        }

        if (currentSelectionState == SelectionState.Selected)
        {
            if (volumeTimer > 0f)
            {
                volumeTimer -= Time.unscaledDeltaTime;
            }
            if (volumeTimer < 0f)
            {
                volumeTimer = 0f;
            }

            InputController.PlayerInput player1Input = InputController.Instance.playerInput[0];

            if (useGenericInputs)
            {
                if (Keyboard.current.anyKey.wasPressedThisFrame || Mouse.current.delta.IsActuated(0.2f))
                {
                    player1Input.controlMode = InputController.ControlsMode.KeyboardMouse;
                }

                if (Gamepad.current != null && (Gamepad.current.allControls.Any(x => x is ButtonControl && x.IsPressed() && !x.synthetic) || Gamepad.current.leftStick.ReadValue().magnitude >= InputController.idleStickThreshold))
                {
                    player1Input.controlMode = InputController.ControlsMode.Controller;
                    player1Input.gamepad     = Gamepad.current;
                }
            }

            switch (player1Input.controlMode)
            {
            case InputController.ControlsMode.KeyboardMouse:
                break;

            case InputController.ControlsMode.Controller:
                Vector2 value = player1Input.gamepad.leftStick.ReadValue();
                if (Mathf.Abs(value.x) >= InputController.idleStickThreshold)
                {
                    if (Mathf.Abs(player1Input.gamepad.leftStick.ReadValueFromPreviousFrame().x) < InputController.idleStickThreshold)
                    {
                        volumeTimer = volumeCD;
                    }
                    if (volumeTimer == 0f)
                    {
                        if (value.x < 0)
                        {
                            percent = (Mathf.Round(percent * 10) - 1) / 10;
                            percent = Mathf.Clamp(percent, 0f, 1f);
                        }
                        else
                        {
                            percent = (Mathf.Round(percent * 10) + 1) / 10;
                            percent = Mathf.Clamp(percent, 0f, 1f);
                        }

                        if (prevPercent != percent)
                        {
                            OnVolumeChanged();
                        }

                        volumeTimer = volumeSmallCD;
                    }
                }
                else
                {
                    value = Vector2.zero;

                    if (player1Input.gamepad.dpad.left.isPressed)
                    {
                        value -= Vector2.right;
                    }
                    else if (player1Input.gamepad.dpad.right.isPressed)
                    {
                        value += Vector2.right;
                    }

                    if (value.x != 0)
                    {
                        if (player1Input.gamepad.dpad.right.wasPressedThisFrame || player1Input.gamepad.dpad.left.wasPressedThisFrame)
                        {
                            volumeTimer = volumeCD;
                        }
                        if (volumeTimer == 0f)
                        {
                            if (value.x < 0)
                            {
                                percent = (Mathf.Round(percent * 10) - 1) / 10;
                                percent = Mathf.Clamp(percent, 0f, 1f);
                            }
                            else
                            {
                                percent = (Mathf.Round(percent * 10) + 1) / 10;
                                percent = Mathf.Clamp(percent, 0f, 1f);
                            }

                            if (prevPercent != percent)
                            {
                                OnVolumeChanged();
                            }

                            volumeTimer = volumeSmallCD;
                        }
                    }
                    else
                    {
                        volumeTimer = 0f;
                    }
                }

                break;
            }
        }

        base.Update();
    }