Пример #1
0
    /*
     * Checks all input sources for a player pressing "Start" and binds them when they join.
     */
    void PollForNewPlayer()
    {
        int nextPlayerIndex = NumPlayers;

        foreach (InputDevice device in InputDevices.GetAllInputDevices())
        {
            if (!boundDevices.ContainsKey(device) || (IsCheatingEnabled && cheats.BIND_MANY_TO_ONE_DEVICE))
            {
                if (RBInput.GetButtonDownForPlayer(InputStrings.PAUSE, nextPlayerIndex, device))
                {
                    BindNextPlayer(device);

                    // Deactivate the splash screen once a player is bound. This is NOT ideal, but
                    // neither is putting a splash screen into every scene. It should be it's own scene.
                    WorldTime worldTime  = (WorldTime)GetComponent <WorldTime> ();
                    Transform startPoint = worldTime.startPointP2;
                    if (NumPlayers == 1)
                    {
                        HideSplashScreen();
                        worldTime.Reset();
                    }
                    else
                    {
                        players [nextPlayerIndex].GetComponent <PlayerController> ().SnapToPoint(startPoint);
                    }
                }
            }
        }
    }
Пример #2
0
    void Awake()
    {
        AssignReferences();
        isPlayerBound = false;
        ShowReticle(false);

        BindPlayer(0, InputDevices.GetAllInputDevices() [(int)InputDevices.ControllerTypes.Keyboard]);
    }
Пример #3
0
    public static float GetAxisForPlayer(string axisName, int playerIndex, InputDevice device)
    {
//        return Input.GetAxis (ConcatPlayerIndex (axisName, playerIndex, device));
        float xbox     = Input.GetAxis(ConcatPlayerIndex(axisName, playerIndex, InputDevices.GetAllInputDevices() [(int)InputDevices.ControllerTypes.XBox]));
        float keyboard = Input.GetAxis(ConcatPlayerIndex(axisName, playerIndex, InputDevices.GetAllInputDevices() [(int)InputDevices.ControllerTypes.Keyboard]));

        return(xbox + keyboard);
    }
Пример #4
0
    public static bool GetButtonForPlayer(string buttonName, int playerIndex, InputDevice device)
    {
//        return Input.GetButton (ConcatPlayerIndex (buttonName, playerIndex, device));
        bool xbox     = Input.GetButton(ConcatPlayerIndex(buttonName, playerIndex, InputDevices.GetAllInputDevices() [(int)InputDevices.ControllerTypes.XBox]));
        bool keyboard = Input.GetButton(ConcatPlayerIndex(buttonName, playerIndex, InputDevices.GetAllInputDevices() [(int)InputDevices.ControllerTypes.Keyboard]));

        return(xbox || keyboard);
    }
Пример #5
0
    void Awake()
    {
        fighter       = gameObject.GetComponent <Fighter> ();
        isPlayerBound = false;
        ResetTargetIndex();
        HighlightArrow(false);

        BindPlayer(0, InputDevices.GetAllInputDevices() [(int)InputDevices.ControllerTypes.Keyboard]);
    }
Пример #6
0
    public static bool GetButtonDownForPlayer(string buttonName, int playerIndex)
    {
        bool isAnyButtonDown = false;

        foreach (InputDevice d in InputDevices.GetAllInputDevices())
        {
            isAnyButtonDown |= Input.GetButtonDown(ConcatPlayerIndex(buttonName, playerIndex, d));
        }
        return(isAnyButtonDown);
    }
Пример #7
0
    public static float GetAxisForPlayer(string axisName, int playerIndex)
    {
        float axisTotal = 0.0f;

        foreach (InputDevice d in InputDevices.GetAllInputDevices())
        {
            axisTotal += Input.GetAxis(ConcatPlayerIndex(axisName, playerIndex, d));
        }
        return(axisTotal);
    }
Пример #8
0
    /*
     * Handle toggling of targetting as well as switching between targets. While holding down
     * target button, player can cycle through targets.
     */
    void TryTargetting()
    {
        float       deadStickThreshold = 0.5f;
        InputDevice xbox = InputDevices.GetAllInputDevices() [(int)InputDevices.ControllerTypes.XBox];
        float       rightStickPressedAxis = Input.GetAxisRaw(RBInput.ConcatPlayerIndex(InputStrings.TARGET, PlayerIndex, xbox));
        bool        rightStickPressed     = rightStickPressedAxis >= 0.99 && rightStickAvailable;
        // Consolidate bool for PC and XBox
        bool isTargetPressed = RBInput.GetButtonDownForPlayer(InputStrings.TARGET, PlayerIndex) ||
                               rightStickPressed;

        // Toggle Targeting on and off
        if (isTargetPressed)
        {
            rightStickAvailable = false;
            if (!fighter.isLockedOn)
            {
                TargetNearest();
            }
            else
            {
                fighter.LoseTarget();
            }
        }

        // Switch between targets
        if (fighter.isLockedOn)
        {
            // PC and Controller controls likely should diverge here due to right stick use
            InputDevice pc = InputDevices.GetAllInputDevices() [(int)InputDevices.ControllerTypes.Keyboard];
            float       horizontalTargetAxis = Input.GetAxisRaw(RBInput.ConcatPlayerIndex(InputStrings.TARGETHORIZONTAL, PlayerIndex, xbox));
            float       verticalTargetAxis   = -Input.GetAxisRaw(RBInput.ConcatPlayerIndex(InputStrings.TARGETVERTCIAL, PlayerIndex, xbox));

            // Move target in axis direction
            bool  changingTarget = false;
            float horizontal     = 0;
            float vertical       = 0;

            //
            // Read in PC input
            //
            // Set Horizontal Input for PC
            if (Input.GetButtonDown(RBInput.ConcatPlayerIndex(InputStrings.TARGETLEFT, PlayerIndex, pc)))
            {
                //|| )) {
                //rightStickHorizontalAvailable = false;
                //TargetNext (true);
                horizontal     = -1;
                changingTarget = true;
            }
            else if (Input.GetButtonDown(RBInput.ConcatPlayerIndex(InputStrings.TARGETRIGHT, PlayerIndex, pc)))
            {
                horizontal     = 1;
                changingTarget = true;
            }
            // Set Vertical Input
            if (Input.GetButtonDown(RBInput.ConcatPlayerIndex(InputStrings.TARGETDOWN, PlayerIndex, pc)))
            {
                vertical       = -1;
                changingTarget = true;
            }
            else if (Input.GetButtonDown(RBInput.ConcatPlayerIndex(InputStrings.TARGETUP, PlayerIndex, pc)))
            {
                vertical       = 1;
                changingTarget = true;
            }

            //
            // Read in XBox input
            //
            // Set Horizontal and Vertical values for XBox
            bool horizontalAxisPressed = rightStickAxisAvailable &&
                                         (horizontalTargetAxis <-deadStickThreshold || horizontalTargetAxis> deadStickThreshold);
            bool verticalAxisPressed = rightStickAxisAvailable &&
                                       (verticalTargetAxis <-deadStickThreshold || verticalTargetAxis> deadStickThreshold);
            if (horizontalAxisPressed || verticalAxisPressed)
            {
                rightStickAxisAvailable = false;
                TargetNearDirection(horizontalTargetAxis, verticalTargetAxis);
                changingTarget = true;
            }

            // Make target change
            if (changingTarget)
            {
                TargetNearDirection(horizontal, vertical);
            }

            // Enforce stick behavior like a button
            rightStickAxisAvailable = IsAxisDead(horizontalTargetAxis, deadStickThreshold) &&
                                      IsAxisDead(verticalTargetAxis, deadStickThreshold);
        }
        rightStickAvailable = IsAxisDead(rightStickPressedAxis, deadStickThreshold);
    }