示例#1
0
文件: GamePad.cs 项目: simul/unity
        void Update()
        {
            if (Application.isConsolePlatform)
            {
#if UNITY_PS4
                if (PS4Input.PadIsConnected(playerId))
                {
                    // Set the gamepad to the start values for the player
                    if (!hasSetupGamepad)
                    {
                        ToggleGamePad(true);
                    }

                    // Handle each part individually
                    Thumbsticks();

                    // Options button is on its own, so we'll do it here
                    if (Input.GetKey((KeyCode)Enum.Parse(typeof(KeyCode), "Joystick" + stickID + "Button7", true)))
                    {
                        // Reset the gyro orientation to default
                        PS4Input.PadResetOrientation(playerId);
                    }
                }
#endif
            }
            else if (hasSetupGamepad)
            {
                ToggleGamePad(false);
            }
        }
示例#2
0
    void Update()
    {
        if (PS4Input.PadIsConnected(playerId))
        {
            // Set the gamepad to the start values for the player
            if (!hasSetupGamepad)
            {
                ToggleGamePad(true);
            }

            // Handle each part individually
            Touchpad();
            Thumbsticks();
            InputButtons();
            DPadButtons();
            TriggerShoulderButtons();
            Lightbar();
            Speaker();

            // Options button is on its own, so we'll do it here
            if (Input.GetKey((KeyCode)Enum.Parse(typeof(KeyCode), "Joystick" + stickID + "Button7", true)))
            {
                gamePad.options.color = inputOn;

                // Reset the gyro orientation and lightbar to default
                PS4Input.PadResetOrientation(playerId);
                PS4Input.PadResetLightBar(playerId);
                lightbarColour = GetPlayerColor(PS4Input.GetUsersDetails(playerId).color);
            }
            else
            {
                gamePad.options.color = inputOff;
            }

            // Make the gyro rotate to match the physical controller
            gamePad.gyro.localEulerAngles = new Vector3(-PS4Input.PadGetLastOrientation(playerId).x,
                                                        -PS4Input.PadGetLastOrientation(playerId).y,
                                                        PS4Input.PadGetLastOrientation(playerId).z) * 100;

            // rebuild the username everyframe, in case it's changed due to PSN access
            gamePad.text.text = PS4Input.RefreshUsersDetails(playerId).userName + "\n(" + connectionType + ")";
        }
        else if (hasSetupGamepad)
        {
            ToggleGamePad(false);
        }
    }