Ejemplo n.º 1
0
    private bool IsDeviceUsable(InputDevice device, PlayerControls playerControls)
    {
        InputActionAsset actions = playerControls.asset;

        if (actions.controlSchemes.Count > 0)
        {
            if (!(InputUser.GetUnpairedInputDevices().Contains(device)))
            {
                return(false);
            }

            if (InputControlScheme.FindControlSchemeForDevice(device, actions.controlSchemes) == null)
            {
                return(false);
            }


            return(true);
        }

        // This is so if there are no controlSchemes, it checks whether the device can be used with the actionMap.
        foreach (var actionMap in actions.actionMaps)
        {
            if (actionMap.IsUsableWithDevice(device))
            {
                return(true);
            }
        }

        return(false);
    }
Ejemplo n.º 2
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.º 3
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));
        }
    }