Exemplo n.º 1
0
    void DrawState(int controller)
    {
        float width = Screen.width / 5;

        GUILayout.BeginArea(new Rect(width * controller, 0, width, Screen.height));

        GamepadPadState state = GamePad.GetState(controller);

        // buttons
        GUILayout.Label("Controller " + controller);
        GUILayout.Label("" + state.A);
        GUILayout.Label("" + state.B);
        GUILayout.Label("" + state.X);
        GUILayout.Label("" + state.Y);
        GUILayout.Label("" + state.Start);
        GUILayout.Label("" + state.Back);
        GUILayout.Label("" + state.LeftShoulder);
        GUILayout.Label("" + state.RightShoulder);
        GUILayout.Label("" + state.Left);
        GUILayout.Label("" + state.Right);
        GUILayout.Label("" + state.Up);
        GUILayout.Label("" + state.Down);
        GUILayout.Label("" + state.LeftStick);
        GUILayout.Label("" + state.RightStick);

        GUILayout.Label("");

        // triggers
        GUILayout.Label("" + state.LeftTrigger);
        GUILayout.Label("" + state.RightTrigger);

        GUILayout.Label("");

        // Axes
        GUILayout.Label("" + state.LeftStickAxis);
        GUILayout.Label("" + state.rightStickAxis);
        GUILayout.Label("" + state.dPadAxis);


        GUILayout.EndArea();
    }
Exemplo n.º 2
0
    public static GamepadPadState GetState(int controller, bool raw = false)
    {
        GamepadPadState state = new GamepadPadState();

        if (controller < 1 || controller > 4)
        {
            Debug.Log("Invalid Controller: " + controller + ". Index must lie between 1 and 4");
            return(state);
        }

        state.A = GetButton(Button.A, controller);
        state.B = GetButton(Button.B, controller);
        state.Y = GetButton(Button.Y, controller);
        state.X = GetButton(Button.X, controller);

        state.RightShoulder = GetButton(Button.RightShoulder, controller);
        state.LeftShoulder  = GetButton(Button.LeftShoulder, controller);
        state.RightStick    = GetButton(Button.RightStick, controller);
        state.LeftStick     = GetButton(Button.LeftStick, controller);

        state.Start = GetButton(Button.Start, controller);
        state.Back  = GetButton(Button.Back, controller);

        state.LeftStickAxis  = GetAxis(Axis.LeftStick, controller, raw);
        state.rightStickAxis = GetAxis(Axis.RightStick, controller, raw);
        state.dPadAxis       = GetAxis(Axis.Dpad, controller, raw);

        state.Left  = (state.dPadAxis.x < 0);
        state.Right = (state.dPadAxis.x > 0);
        state.Up    = (state.dPadAxis.y > 0);
        state.Down  = (state.dPadAxis.y < 0);

        state.LeftTrigger  = GetTrigger(Trigger.LeftTrigger, controller, raw);
        state.RightTrigger = GetTrigger(Trigger.RightTrigger, controller, raw);

        return(state);
    }
Exemplo n.º 3
0
    public static GamepadPadState GetState(int controller, bool raw = false)
    {
        GamepadPadState state = new GamepadPadState();
        if (controller < 1 || controller > 4)
        {
            Debug.Log("Invalid Controller: " + controller + ". Index must lie between 1 and 4");
            return state;
        }

        state.A = GetButton(Button.A, controller);
        state.B = GetButton(Button.B, controller);
        state.Y = GetButton(Button.Y, controller);
        state.X = GetButton(Button.X, controller);

        state.RightShoulder = GetButton(Button.RightShoulder, controller);
        state.LeftShoulder = GetButton(Button.LeftShoulder, controller);
        state.RightStick = GetButton(Button.RightStick, controller);
        state.LeftStick = GetButton(Button.LeftStick, controller);

        state.Start = GetButton(Button.Start, controller);
        state.Back = GetButton(Button.Back, controller);

        state.LeftStickAxis = GetAxis(Axis.LeftStick, controller, raw);
        state.rightStickAxis = GetAxis(Axis.RightStick, controller, raw);
        state.dPadAxis = GetAxis(Axis.Dpad, controller, raw);

        state.Left = (state.dPadAxis.x < 0);
        state.Right = (state.dPadAxis.x > 0);
        state.Up = (state.dPadAxis.y > 0);
        state.Down = (state.dPadAxis.y < 0);

        state.LeftTrigger = GetTrigger(Trigger.LeftTrigger, controller, raw);
        state.RightTrigger = GetTrigger(Trigger.RightTrigger, controller, raw);

        return state;
    }