Exemple #1
0
    private void JoinGamepad(InputAction.CallbackContext ctx)
    {
        foreach (InputControl gamepad in _alreadyJoinedGamepads)
        {
            if (gamepad.device.deviceId == ctx.control.device.deviceId)
            {
                return;    //This device is already connected
            }
        }

        _alreadyJoinedGamepads.Add(ctx.control.device);

        Debug.Log($"Connecting: {ctx.ToString()}");

        _playerNumber++;

        var go = PlayerInput.Instantiate(
            playerPrefab,      //GameObject to instantiate - Must contain a PlayerInput Component
            _playerNumber,     //playerIndex - Must be unique
            "Gamepad",         //String must match Control Scheme name set in your InputActions
            -1,                //splitScreenIndex. -1 no split screen
            ctx.control.device //I've only been able to test with 2 different types of Gamepads.
                               //Don't know if you can connect 2 of the same types of controllers like this.
                               //Left in just in case, doesn't hurt.
            );

        go.transform.parent = gameObject.transform;
    }
Exemple #2
0
 private void OnInteractDown(InputAction.CallbackContext context)
 {
     if (debugInput)
     {
         Debug.Log("OnInteractDown " + context.ToString());
     }
     CrashdownPlayerController.activePlayerInstances[0].InputInteractDownThisFrame = true;
 }
    public void OnMove(InputAction.CallbackContext context)
    {
        var m_Move = context.ReadValue <Vector2>();

        Debug.Log(context.ToString());
        if (racingInteraction.IsRacing && context.phase == InputActionPhase.Started)
        {
            racingInteraction.TurnRight();
        }
    }
Exemple #4
0
 private void OnMovementChanged(InputAction.CallbackContext context)
 {
     if (debugInput)
     {
         Debug.Log("OnMovementChanged " + context.ToString());
     }
     if (context.performed)
     {
         CrashdownPlayerController.activePlayerInstances[0].InputMovementThisFrame = context.ReadValue <Vector2>();
     }
     if (context.canceled)
     {
         CrashdownPlayerController.activePlayerInstances[0].InputMovementThisFrame = Vector2.zero;
     }
 }
Exemple #5
0
    private void JoinKeyboard_2(InputAction.CallbackContext ctx)
    {
        Debug.Log($"Connecting: {ctx.ToString()}");

        _playerNumber++;

        var go = PlayerInput.Instantiate(
            playerPrefab,      //GameObject to instantiate - Must contain a PlayerInput Component
            _playerNumber,     //playerIndex - Must be unique
            "Keyboard2",       //String must match Control Scheme name set in your InputActions
            -1,                //splitScreenIndex. -1 no split screen
            ctx.control.device //If you have multiple Keyboard players you must implicitly specific the device to use
                               //otherwise only the first Joined keyboard will have the keyboard device associated with it.
            );

        go.transform.parent = gameObject.transform;

        //Unregister so we don't add this Control Scheme again
        _controls.Player.JoinKeyboard_2.performed -= JoinKeyboard_2;
    }