private void RemoveUser(InputDevice device)
    {
        var user = InputUser.FindUserPairedToDevice(device);

        playerManager.HandleDisconnection(device.id);
        user.Value.UnpairDevicesAndRemoveUser();
    }
Example #2
0
    void ListenForUnpairedDevices(InputControl control, InputEventPtr arg)
    {
        //Debug.Log("Found unpaired device " + control);
        if ((control.device is Gamepad || control.device is Keyboard) && !gameStarted)
        {
            InputDevice pair_with_device = control.device;
            if (playerInputManager.playerCount < 4)
            {
                if (control.device is Keyboard)
                {
                    Keyboard = pair_with_device;
                }
                if (play_testing && play_test_characters.Length > playerInputManager.playerCount)
                {
                    playerPrefab = play_test_characters[playerInputManager.playerCount];
                }
                playerInputManager.playerPrefab = playerPrefab;

                playerInputManager.JoinPlayer(-1, -1, controlScheme, pair_with_device);
            }
        }
        if (control.device is Mouse && Keyboard != null)
        {
            InputDevice pair_with_device = control.device;
            InputUser.PerformPairingWithDevice(pair_with_device, InputUser.FindUserPairedToDevice(Keyboard).Value, InputUserPairingOptions.None);
        }
    }
Example #3
0
 private void OnPauseHandler(InputAction.CallbackContext context)
 {
     if (InputUser.FindUserPairedToDevice(context.control.device).HasValue)
     {
         this.OnPause?.Invoke();
     }
 }
Example #4
0
    private DemoPlayerController FindPlayerControllerForDevice(InputDevice device)
    {
        var user = InputUser.FindUserPairedToDevice(device);

        if (user == null)
        {
            return(null);
        }

        return(FindPlayerControllerForUser(user.Value));
    }
Example #5
0
        private static bool IsUserRegistered(InputDevice device, out uint userId)
        {
            var user = InputUser.FindUserPairedToDevice(device);

            if (!user.HasValue)
            {
                userId = 999;
                return(false);
            }

            userId = user.Value.id;
            return(true);
        }
Example #6
0
    public void Users_CanFindUserThatPairedToSpecificDevice()
    {
        var gamepad1 = InputSystem.AddDevice <Gamepad>();
        var gamepad2 = InputSystem.AddDevice <Gamepad>();
        var gamepad3 = InputSystem.AddDevice <Gamepad>();

        var user1 = InputUser.PerformPairingWithDevice(gamepad1);
        var user2 = InputUser.PerformPairingWithDevice(gamepad2);
        var user3 = InputUser.PerformPairingWithDevice(gamepad2); // Same gamepad on two users.

        Assert.That(InputUser.FindUserPairedToDevice(gamepad1), Is.EqualTo(user1));
        Assert.That(InputUser.FindUserPairedToDevice(gamepad2), Is.EqualTo(user2).Or.EqualTo(user3)); // Either is acceptable.
        Assert.That(InputUser.FindUserPairedToDevice(gamepad3), Is.Null);
    }
Example #7
0
 private static uint GetUserId(InputAction.CallbackContext context) => InputUser.FindUserPairedToDevice(context.control.device) !.Value.id;