Ejemplo n.º 1
0
    public void Users_CannotPairSameDeviceToUserMoreThanOnce()
    {
        var gamepad = InputSystem.AddDevice <Gamepad>();
        var user    = InputUser.PerformPairingWithDevice(gamepad);

        var receivedChanges = new List <UserChange>();

        InputUser.onChange +=
            (usr, change, device) => { receivedChanges.Add(new UserChange(usr, change, device)); };

        InputUser.PerformPairingWithDevice(gamepad, user: user);

        Assert.That(receivedChanges, Is.Empty);
    }
Ejemplo n.º 2
0
    public void Users_CanAssociatedActionsWithUser()
    {
        var gamepad = InputSystem.AddDevice <Gamepad>();

        InputUser.PerformPairingWithDevice(gamepad);

        Assert.That(InputUser.all[0].actions, Is.Null);

        var asset = ScriptableObject.CreateInstance <InputActionAsset>();

        InputUser.all[0].AssociateActionsWithUser(asset);

        Assert.That(InputUser.all[0].actions, Is.SameAs(asset));
    }
Ejemplo n.º 3
0
    public void Users_CanFindUserPairedToSpecificDevice()
    {
        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);
    }
Ejemplo n.º 4
0
 void AssignControllerToPlayer()
 {
     Color[] colors = GameObject.Find("PlayersManager").GetComponent <DebugIcons>().colors;
     foreach (Player player in playersInfos)
     {
         GameObject currentPlayerGO = playersGO.transform.GetChild(player.Id).gameObject;
         currentPlayerGO.GetComponent <QTE>().id = player.Id;
         currentPlayerGO.transform.Find("CP").GetComponent <SpriteRenderer>().color = colors[player.Skin];
         PlayerInput playerInput = currentPlayerGO.AddComponent <PlayerInput>();
         playerInput.actions = Instantiate(dragonsActions);
         playerInput.actions.Enable();
         playerInput.user.UnpairDevices();
         InputUser.PerformPairingWithDevice(playersInfos[player.Id].device, playerInput.user);
     }
 }
    public void TryAssignKeyboard()
    {
        GameObject[]  players      = GameObject.FindGameObjectsWithTag("Player");
        PlayerInput[] playerInputs = new PlayerInput[players.Length];

        for (int i = 0; i < players.Length; i++)
        {
            playerInputs[i] = players[i].GetComponent <PlayerInput>();
            if (playerInputs[i] != null && !playerInputs[i].Equals(null) && playerInputs[i].currentControlScheme == secondKeyboardControlScheme)
            {
                InputUser.PerformPairingWithDevice(Keyboard.current, playerInputs[i].user);
                break;
            }
        }
    }
Ejemplo n.º 6
0
        public static RemoteInput Create()
        {
            InputUser user = InputUser.CreateUserWithoutPairedDevices();

            user = InputUser.PerformPairingWithDevice(InputSystem.AddDevice <Mouse>(), user);
            user = InputUser.PerformPairingWithDevice(InputSystem.AddDevice <Keyboard>(), user);
            user = InputUser.PerformPairingWithDevice(InputSystem.AddDevice <Gamepad>(), user);
            user = InputUser.PerformPairingWithDevice(InputSystem.AddDevice <Touchscreen>(), user);
            RemoteInput remoteInput = new RemoteInput(ref user);

            s_mapRemoteInputAndInputUserId.Add(remoteInput, user.id);
            s_listRemoteInput.Add(remoteInput);

            return(remoteInput);
        }
 // Start is called before the first frame update
 void Awake()
 {
     playerInput = GetComponent <PlayerInput>();
     inputUser   = playerInput.user;
     inputUser.UnpairDevices();
     Debug.Log(inputUser.controlScheme.ToString());
     foreach (var js in Joystick.all)
     {
         InputUser.PerformPairingWithDevice(js, inputUser);
     }
     foreach (var gp in Gamepad.all)
     {
         InputUser.PerformPairingWithDevice(gp, inputUser);
         ProGamepad = gp;
     }
 }
Ejemplo n.º 8
0
 private void setplayers()
 {
     for (int i = 0; i < Players.Count; i++)
     {
         try {
             portrats[i].sprite = possablePortrats[Settings.Instance.playerData[i].SelectedChar];
             Debug.Log("setting player " + i + " with device " + Settings.Instance.Devices[i]);
             Players[i].user.UnpairDevices();
             InputUser.PerformPairingWithDevice(Settings.Instance.Devices[i],Players[i].user);
         }
         catch
         {
             Debug.Log("own no youw nowt supposed tuwu see thiws scween");
         }
     }
 }
Ejemplo n.º 9
0
        InputUser SetupNewUser()
        {
            unpairedDevices = InputUser.GetUnpairedInputDevices();
            if (unpairedDevices.Count == 0)
            {
                return(new InputUser());
            }

            InputUser newUser = new InputUser();

            newUser = InputUser.PerformPairingWithDevice(unpairedDevices[0], newUser);
            Debug.Log($"Paired device to new user: {newUser.pairedDevices[0].displayName}");
            unpairedDevices = InputUser.GetUnpairedInputDevices();

            return(newUser);
        }
Ejemplo n.º 10
0
        private void AddPlayer(InputDevice device)
        {
            if (_currPlayerIndex.Equals(-1))
            {
                return;
            }

            // Don't execute if not a gamepad or keyboard
            if (!device.displayName.Contains("Controller") && !device.displayName.Contains("Gamepad") &&
                !device.displayName.Contains("Keyboard"))
            {
                return;
            }

            if (PlayerInput.all.SelectMany(player => player.devices)
                .Any(playerDevice => device == playerDevice && !device.displayName.Contains("Keyboard")))
            {
                return;
            }

            var playerInput = _playerInstances[_currPlayerIndex].GetComponent <PlayerInput>();

            if (device.displayName.Contains("Keyboard"))
            {
                keyboardScheme[_currPlayerIndex].SetActive(true);
                var scheme = _currPlayerIndex == 0 ? "KeyboardLeft" : "KeyboardRight";
                playerInput.SwitchCurrentControlScheme(scheme);
                InputUser.PerformPairingWithDevice(Keyboard.current, playerInput.user,
                                                   InputUserPairingOptions.UnpairCurrentDevicesFromUser);
                DeviceMap.PlayerDevices[_currPlayerIndex] = (device, scheme);
            }
            else
            {
                keyboardScheme[_currPlayerIndex].SetActive(false);
                playerInput.SwitchCurrentControlScheme("Gamepad");
                InputUser.PerformPairingWithDevice(device, playerInput.user,
                                                   InputUserPairingOptions.UnpairCurrentDevicesFromUser);
                DeviceMap.PlayerDevices[_currPlayerIndex] = (device, "Gamepad");
            }

            devicesText[_currPlayerIndex].text        = device.displayName;
            bindButton[_currPlayerIndex].interactable = true;
            OnControllerChange?.Invoke();
            CheckValidScheme();

            _currPlayerIndex = -1;
        }
Ejemplo n.º 11
0
    public void Users_CanActivateControlScheme_AndAutomaticallyPairRemainingDevices()
    {
        var gamepad1 = InputSystem.AddDevice <Gamepad>();
        var gamepad2 = InputSystem.AddDevice <Gamepad>();

        InputSystem.AddDevice <Mouse>(); // Noise.

        var gamepadScheme = new InputControlScheme("Gamepad")
                            .WithRequiredDevice("<Gamepad>")
                            .WithRequiredDevice("<Gamepad>")
                            .WithOptionalDevice("<Gamepad>");

        var user1 = InputUser.PerformPairingWithDevice(gamepad1);

        InputUser.PerformPairingWithDevice(gamepad2); // Should not get picked as already used.

        var actions = new InputActionMap();

        user1.AssociateActionsWithUser(actions);

        // First try it without having the devices we need.
        user1.ActivateControlScheme(gamepadScheme)
        .AndPairRemainingDevices();

        Assert.That(user1.pairedDevices, Is.EquivalentTo(new[] { gamepad1 }));
        Assert.That(actions.devices, Is.EquivalentTo(new[] { gamepad1 }));
        Assert.That(user1.hasMissingDevices, Is.True);
        Assert.That(user1.controlSchemeMatch.isSuccessfulMatch, Is.False);
        Assert.That(user1.controlSchemeMatch[0].control, Is.SameAs(gamepad1));
        Assert.That(user1.controlSchemeMatch[1].control, Is.Null);
        Assert.That(user1.controlSchemeMatch[2].control, Is.Null);

        // Now add another gamepad and try again.
        var gamepad3 = InputSystem.AddDevice <Gamepad>();

        user1.ActivateControlScheme(gamepadScheme)
        .AndPairRemainingDevices();

        Assert.That(user1.pairedDevices, Is.EquivalentTo(new[] { gamepad1, gamepad3 }));
        Assert.That(actions.devices, Is.EquivalentTo(new[] { gamepad1, gamepad3 }));
        Assert.That(user1.hasMissingDevices, Is.False);
        Assert.That(user1.controlSchemeMatch.isSuccessfulMatch, Is.True);
        Assert.That(user1.controlSchemeMatch[0].control, Is.SameAs(gamepad1));
        Assert.That(user1.controlSchemeMatch[1].control, Is.SameAs(gamepad3));
        Assert.That(user1.controlSchemeMatch[2].control, Is.Null); // Still don't have the optional one.
    }
Ejemplo n.º 12
0
    public void Users_CanPairDevice_WhenDeviceHasPairedUserAccountAtPlatformLevel()
    {
        // Report a gamepad paired to a user at the platform level.
        runtime.ReportNewInputDevice <Gamepad>(userHandle: 1, userName: "******",
                                               userId: "TestId");
        InputSystem.Update();
        var gamepad = InputSystem.GetDevice <Gamepad>();

        var user = InputUser.PerformPairingWithDevice(gamepad);

        Assert.That(user.valid, Is.True);
        Assert.That(user.platformUserAccountHandle, Is.EqualTo(new InputUserAccountHandle("Test", 1)));
        Assert.That(user.platformUserAccountName, Is.EqualTo("TestUser"));
        Assert.That(user.platformUserAccountId, Is.EqualTo("TestId"));

        var receivedChanges = new List <UserChange>();

        InputUser.onChange +=
            (usr, change, device) => { receivedChanges.Add(new UserChange(usr, change, device)); };

        // Change the user account on the device.
        runtime.AssociateInputDeviceWithUser(gamepad, userHandle: 2, userName: "******", userId: "OtherId");
        InputSystem.QueueConfigChangeEvent(gamepad);
        InputSystem.Update();

        Assert.That(user.platformUserAccountHandle, Is.EqualTo(new InputUserAccountHandle("Test", 2)));
        Assert.That(user.platformUserAccountName, Is.EqualTo("OtherUser"));
        Assert.That(user.platformUserAccountId, Is.EqualTo("OtherId"));
        Assert.That(receivedChanges, Is.EquivalentTo(new[]
        {
            new UserChange(user, InputUserChange.AccountChanged, gamepad)
        }));

        receivedChanges.Clear();

        // Send config change event but do *NOT* change user account. Make sure
        // the system won't claim the account has changed.

        InputSystem.QueueConfigChangeEvent(gamepad);
        InputSystem.Update();

        Assert.That(user.platformUserAccountHandle, Is.EqualTo(new InputUserAccountHandle("Test", 2)));
        Assert.That(user.platformUserAccountName, Is.EqualTo("OtherUser"));
        Assert.That(user.platformUserAccountId, Is.EqualTo("OtherId"));
        Assert.That(receivedChanges, Is.Empty);
    }
Ejemplo n.º 13
0
 void SetupInGameDevices()
 {
     if (inputDevice is Gamepad)
     {
         gamepad   = inputDevice as Gamepad;
         inputType = InputType.GP;
     }
     else
     {
         keyboard  = inputDevice as Keyboard;
         mouse     = InputSystem.GetDevice <Mouse>();
         inputType = InputType.KB;
         inputUser = InputUser.PerformPairingWithDevice(mouse, inputUser);
     }
     inputUser = InputUser.PerformPairingWithDevice(inputDevice, inputUser);
     inputUser.AssociateActionsWithUser(controls);
 }
Ejemplo n.º 14
0
    private void Start()
    {
        // Link controller input to specific single device
        if (playerControllerID != -1)
        {
            PlayerInput playerInput = GetComponent <PlayerInput>();

            foreach (InputDevice input in InputDevice.all)
            {
                if (input.deviceId == playerControllerID)
                {
                    InputUser.PerformPairingWithDevice(input, playerInput.user, InputUserPairingOptions.UnpairCurrentDevicesFromUser);
                    break;
                }
            }
        }
    }
Ejemplo n.º 15
0
    public void Awake()
    {
        playerCommands = new List <Command>();

        playerControls = new PlayerControls(); //Must Generate a C# Class from controls

        playerInput = GetComponent <PlayerInput>();

        string deviceName = playerInput.devices[0].name;

        if (deviceName.Contains("Mouse") || deviceName.Contains("Keyboard"))
        {
            if (deviceName.Contains("Mouse"))
            {
                InputUser.PerformPairingWithDevice(Keyboard.current, playerInput.user);
            }
            if (deviceName.Contains("Keyboard"))
            {
                InputUser.PerformPairingWithDevice(Mouse.current, playerInput.user);
            }
//                playerInput.user.AssociateActionsWithUser((InputActionMap)playerControls.asset.actionMaps[0]);
//                var scheme = InputControlScheme.FindControlSchemeForDevice(playerInput.user.pairedDevices[1], playerInput.user.actions.controlSchemes);

////                print(scheme.ToString());
//                playerInput.user.ActivateControlScheme(scheme.ToString());
        }

        //Add all device names to "list"
        deviceNames = new string[playerInput.user.pairedDevices.Count];
        for (int i = 0; i < deviceNames.Length; i++)
        {
            deviceNames[i] = playerInput.user.pairedDevices[i].name;
        }

        actionMap    = (InputActionMap)playerControls.asset.actionMaps[0];
        commandNames = new Dictionary <string, Command>();
        for (int i = 0; i < actionMap.actions.Count; i++)
        {
            Command newCommand = new Command();
            newCommand.AddInput(actionMap.actions[i], deviceNames);
            commandNames.Add(actionMap.actions[i].name, newCommand);
            playerCommands.Add(newCommand);
//           print(actionMap.actions[i].name);
        }
    }
Ejemplo n.º 16
0
    public void Users_HaveIndices()
    {
        var gamepad1 = InputSystem.AddDevice <Gamepad>();
        var gamepad2 = InputSystem.AddDevice <Gamepad>();

        var user1 = InputUser.PerformPairingWithDevice(gamepad1);
        var user2 = InputUser.PerformPairingWithDevice(gamepad2);

        Assert.That(user1.index, Is.EqualTo(0));
        Assert.That(user2.index, Is.EqualTo(1));
        Assert.That(InputUser.all, Is.EquivalentTo(new[] { user1, user2 }));

        // Remove first user.
        user1.UnpairDevicesAndRemoveUser();

        Assert.That(InputUser.all, Is.EquivalentTo(new[] { user2 }));
        Assert.That(user2.index, Is.EqualTo(0));
    }
Ejemplo n.º 17
0
    public void PairToDevice(InputDevice device)
    {
        if (!hasAuthority)
        {
            return;
        }

        print("PairToDevice called" + device);

        this.device = device;

        playerInput.user.UnpairDevices();

        print("Input user: "******"Paired devices: " + playerInput.user.pairedDevices.Count);
        print("Lost Devices: " + playerInput.user.lostDevices.Count);
        print("Switch Control Scheme: " + playerInput.SwitchCurrentControlScheme(new InputDevice[] { device }));
    }
Ejemplo n.º 18
0
 void AssignControllerToPlayer()
 {
     Color[] colors = GameObject.Find("PlayersManager").GetComponent <DebugIcons>().colors;
     foreach (Player player in playersInfos)
     {
         GameObject currentPlayerGO = players.Single(x => x.playerNumber == player.Id).gameObject;
         ApplySkin(currentPlayerGO, skinToUse[player.Id]);
         PlayerInput playerInput = currentPlayerGO.AddComponent <PlayerInput>();
         playerInput.actions = Instantiate(actions);
         playerInput.actions.Enable();
         playerInput.SwitchCurrentActionMap("Dead");
         playerInput.currentActionMap.Disable();
         playerInput.SwitchCurrentActionMap("Alive");
         playerInput.user.UnpairDevices();
         playerInput.GetComponent <KTB_Player>().playerInput = playerInput;
         InputUser.PerformPairingWithDevice(playersInfos[player.Id].device, playerInput.user);
     }
 }
Ejemplo n.º 19
0
    void Assign()
    {
        var gamepads = Gamepad.all;
        int limit    = Math.Min(players.Length, gamepads.Count);
        int start    = gamepadassigned;

        for (int i = 0; i < limit; i++)
        {
            InputUser.PerformPairingWithDevice(gamepads[i], InputUser.all[players[i].playerIndex], InputUserPairingOptions.UnpairCurrentDevicesFromUser);
            InputUser.PerformPairingWithDevice(Keyboard.current, InputUser.all[players[i].playerIndex]);

            players[i].SwitchCurrentControlScheme("Gamepad", gamepads[i], Keyboard.current);
            players[i].defaultActionMap = "Player" + (i + 1);

            UnityEngine.Debug.Log("Assign " + gamepads[i].name + " to " + players[i].name + " with " + "Player" + (i + 1));
            gamepadassigned++;
        }
    }
Ejemplo n.º 20
0
    public void Users_CanActivateAndDeactivateControlScheme()
    {
        var gamepad = InputSystem.AddDevice <Gamepad>();
        var user    = InputUser.PerformPairingWithDevice(gamepad);

        var actions = new InputActionMap();

        user.AssociateActionsWithUser(actions);

        var gamepadScheme = new InputControlScheme("Gamepad")
                            .WithRequiredDevice("<Gamepad>");

        var receivedChanges = new List <UserChange>();

        InputUser.onChange +=
            (usr, change, device) => { receivedChanges.Add(new UserChange(usr, change, device)); };

        Assert.That(user.controlScheme, Is.Null);

        user.ActivateControlScheme(gamepadScheme);

        Assert.That(user.controlScheme, Is.EqualTo(gamepadScheme));
        Assert.That(actions.bindingMask, Is.EqualTo(new InputBinding {
            groups = "Gamepad"
        }));
        Assert.That(actions.devices, Is.EquivalentTo(new[] { gamepad }));
        Assert.That(receivedChanges, Is.EquivalentTo(new[]
        {
            new UserChange(user, InputUserChange.ControlSchemeChanged)
        }));

        receivedChanges.Clear();

        user.ActivateControlScheme(null);

        Assert.That(user.controlScheme, Is.Null);
        Assert.That(user.pairedDevices, Is.EquivalentTo(new[] { gamepad }));
        Assert.That(actions.bindingMask, Is.Null);
        Assert.That(actions.devices, Is.EquivalentTo(new[] { gamepad })); // Devices should be unaffected by control scheme; should be affected by paired devices only.
        Assert.That(receivedChanges, Is.EquivalentTo(new[]
        {
            new UserChange(user, InputUserChange.ControlSchemeChanged)
        }));
    }
Ejemplo n.º 21
0
 void OnUnpairedDeviceUsed(InputControl c, InputEventPtr e)
 {
     if (!(c.device.GetType() == Keyboard.current.GetType() || c.device.GetType() == Gamepad.current.GetType()))
     {
         return;
     }
     if (!player1.InputUser.valid)
     {
         player1.InputUser = InputUser.PerformPairingWithDevice(c.device);
         player1.InputUser.AssociateActionsWithUser(player1.PlayerControl);
         Debug.Log("Pairing player1 with " + c.device.name);
     }
     else if (!player2.InputUser.valid)
     {
         player2.InputUser = InputUser.PerformPairingWithDevice(c.device);
         player2.InputUser.AssociateActionsWithUser(player2.PlayerControl);
         Debug.Log("Pairing player2 with " + c.device.name);
     }
 }
Ejemplo n.º 22
0
    // Start is called before the first frame update
    void Start()
    {
        playerInput = GetComponent <PlayerInput>();
        user        = playerInput.user;

        controller = GetComponent <CharacterController>();

        stickVector    = new Vector2();
        movementVector = new Vector3();

        rStickVector = new Vector2();
        cameraVector = new Vector3();

        //InputUser.PerformPairingWithDevice(InputSystem.devices[2], user);
        //InputUser.PerformPairingWithDevice(InputSystem.devices[3], user);
        //jcLeft = user.pairedDevices[1];
        //jcRight = user.pairedDevices[0];
        InputUser.PerformPairingWithDevice(InputSystem.devices[5], user);
    }
Ejemplo n.º 23
0
    public void Users_CanQueryUnpairedDevices()
    {
        var gamepad  = InputSystem.AddDevice <Gamepad>();
        var keyboard = InputSystem.AddDevice <Keyboard>();
        var mouse    = InputSystem.AddDevice <Mouse>();
        var touch    = InputSystem.AddDevice <Touchscreen>();
        var gyro     = InputSystem.AddDevice <Gyroscope>();

        InputUser.PerformPairingWithDevice(gamepad);
        InputUser.PerformPairingWithDevice(keyboard);
        InputUser.PerformPairingWithDevice(mouse, user: InputUser.all[1]);

        using (var unusedDevices = InputUser.GetUnpairedInputDevices())
        {
            Assert.That(unusedDevices, Has.Count.EqualTo(2));
            Assert.That(unusedDevices, Has.Exactly(1).SameAs(touch));
            Assert.That(unusedDevices, Has.Exactly(1).SameAs(gyro));
        }
    }
Ejemplo n.º 24
0
    private void OnInputUserOnOnUnpairedDeviceUsed(InputControl control)
    {
        if (control.device is Gamepad gamepad)
        {
            Debug.LogFormat("new unpaired device activity: {0}", gamepad.name);

            for (var i = 0; i < _users.Length; i++)
            {
                var user           = _users[i];
                var pairedGamepads = user.pairedDevices.Count(d => d is Gamepad);
                if (pairedGamepads == 0)
                {
                    _users[i] = InputUser.PerformPairingWithDevice(gamepad, _users[i],
                                                                   InputUserPairingOptions.None);
                    return;
                }
            }
        }
    }
Ejemplo n.º 25
0
 void SetupTestingDevices()
 {
     if (testingController)
     {
         inputDevice = InputSystem.GetDevice <Gamepad>();
         gamepad     = inputDevice as Gamepad;
         inputType   = InputType.GP;
     }
     else if (testingMouseAndKeyboard)
     {
         inputDevice = InputSystem.GetDevice <Keyboard>();
         keyboard    = inputDevice as Keyboard;
         mouse       = InputSystem.GetDevice <Mouse>();
         inputType   = InputType.KB;
         inputUser   = InputUser.PerformPairingWithDevice(mouse, inputUser);
     }
     inputUser = InputUser.PerformPairingWithDevice(inputDevice, inputUser);
     inputUser.AssociateActionsWithUser(controls);
 }
Ejemplo n.º 26
0
    public void Users_HaveUniqueIds()
    {
        var gamepad1 = InputSystem.AddDevice <Gamepad>();
        var gamepad2 = InputSystem.AddDevice <Gamepad>();

        var user1 = InputUser.PerformPairingWithDevice(gamepad1);
        var user2 = InputUser.PerformPairingWithDevice(gamepad2);

        Assert.That(user1.id, Is.Not.EqualTo(InputUser.kInvalidId));
        Assert.That(user2.id, Is.Not.EqualTo(InputUser.kInvalidId));
        Assert.That(user1.id, Is.Not.EqualTo(user2.id));

        user1.UnpairDevicesAndRemoveUser();

        var user3 = InputUser.PerformPairingWithDevice(gamepad1);

        Assert.That(user3.id, Is.Not.EqualTo(user1.id));
        Assert.That(user3.id, Is.Not.EqualTo(user2.id));
    }
Ejemplo n.º 27
0
    private void SpawnSelectedPlayers()
    {
        foreach (var player in PlayerObjectHandler.playerControllers)
        {
            var playerController    = PlayerObjectHandler.playerControllers[player.Key];
            var playerObjectName    = PlayerObjectHandler.playerSelectionNames[player.Key];
            var playerControlScheme = PlayerObjectHandler.playerControlSchemes[player.Key];

            GameObject parentPlayerObject = new GameObject();

            for (int i = 0; i < playerObjectName.Count; i++)
            {
                var currentObject = Resources.Load <GameObject>(playerObjectName[i]);

                // Only activate PlayerInput component on the first object (it defines the "player"
                if (i == 0)
                {
                    parentPlayerObject = currentObject;
                    PlayerInput playerInput = PlayerInput.Instantiate(currentObject, player.Key, playerControlScheme, -1, playerController);

                    // Activates the player input component on the prefab we just instantiated
                    // We have the component disabled by default, otherwise it could not be a "selectable object" independent of the PlayerInput component on the cursor
                    // in the selection screen
                    currentObject.GetComponent <PlayerControls>().SetPlayerInputActive(true, playerInput);

                    //  *** It seems...that the above Instantiation doesn't exactly work... I'm assuming, because the PlayerInput component on the prefab is starting off
                    // disabled, that it...doesn't work.  This code here will force it to keep the device/scheme/etc... that we tried to assign the wretch above!
                    var inputUser = playerInput.user;
                    playerInput.SwitchCurrentControlScheme(playerControlScheme);
                    InputUser.PerformPairingWithDevice(playerController, inputUser, InputUserPairingOptions.UnpairCurrentDevicesFromUser);
                }

                // If not the first object (sword/vehicle/etc...) just instantiate, don't associate a PlayerInput
                else
                {
                    Instantiate(currentObject, parentPlayerObject.transform);
                }
            }
        }
    }
Ejemplo n.º 28
0
    public void Users_CanPairDevice_WithGivenUser_AndUnpairCurrentDevices()
    {
        var gamepad1 = InputSystem.AddDevice <Gamepad>();
        var gamepad2 = InputSystem.AddDevice <Gamepad>();

        var user = InputUser.PerformPairingWithDevice(gamepad1);

        var receivedChanges = new List <UserChange>();

        InputUser.onChange +=
            (usr, change, device) => { receivedChanges.Add(new UserChange(usr, change, device)); };

        InputUser.PerformPairingWithDevice(gamepad2, user: user,
                                           options: InputUserPairingOptions.UnpairCurrentDevicesFromUser);

        Assert.That(user.pairedDevices, Is.EquivalentTo(new[] { gamepad2 }));
        Assert.That(receivedChanges, Is.EquivalentTo(new[]
        {
            new UserChange(user, InputUserChange.DeviceUnpaired, gamepad1),
            new UserChange(user, InputUserChange.DevicePaired, gamepad2),
        }));
    }
Ejemplo n.º 29
0
    // This will Spawn a player prefab, And then assign an available device to a newly created input user
    private GameObject SpawnPlayer(int playerIndex, InputDevice deviceToPair)
    {
        GameObject newPlayer = Instantiate(playerPrefab, spawnPoint.position, Quaternion.identity, this.transform);

        PlayerInputHandler newPlayerInputHandler = newPlayer.GetComponent <PlayerInputHandler>();

        newPlayerInputHandler.playerIndex     = playerIndex;
        newPlayerInputHandler.deviceBeingUsed = deviceToPair;

        InputUser newInputUser;

        // Clear the list of devices for the player that are automatically registered.
        newPlayerInputHandler.playerControls.devices = new InputDevice[] { };
        newInputUser = InputUser.PerformPairingWithDevice(deviceToPair);
        newInputUser.AssociateActionsWithUser(newPlayerInputHandler.playerControls.asset);

        newPlayerInputHandler.inputUser = newInputUser;

        currentPlayerIndex++;

        return(newPlayer);
    }
Ejemplo n.º 30
0
    // Start is called before the first frame update
    void Start()
    {
        playerInput = GetComponent <PlayerInput>();
        user        = playerInput.user;

        rb = GetComponent <Rigidbody>();

        stickVector    = new Vector2();
        movementVector = new Vector3();

        rStickVector = new Vector2();
        cameraVector = new Vector3();

        heading    = 0f;
        oldHeading = 0f;

        InputUser.PerformPairingWithDevice(InputSystem.devices[2], user);
        InputUser.PerformPairingWithDevice(InputSystem.devices[3], user);
        /// TODO:
        jcLeft  = user.pairedDevices[0];
        jcRight = user.pairedDevices[1];
    }