Esempio n. 1
0
    public void Users_CanAssignControlScheme_AndAutomaticallyAssignMatchingUnusedDevices()
    {
        var keyboard = InputSystem.AddDevice <Keyboard>();

        InputSystem.AddDevice <Mouse>(); // Noise.
        var gamepad1 = InputSystem.AddDevice <Gamepad>();
        var gamepad2 = InputSystem.AddDevice <Gamepad>();
        var gamepad3 = InputSystem.AddDevice <Gamepad>();

        var singleGamepadScheme = new InputControlScheme("SingleGamepad")
                                  .WithRequiredDevice("<Gamepad>");
        var dualGamepadScheme = new InputControlScheme("DualGamepad")
                                .WithRequiredDevice("<Gamepad>")
                                .WithRequiredDevice("<Gamepad>");

        var user1 = new TestUser();
        var user2 = new TestUser();
        var user3 = new TestUser();

        InputUser.Add(user1);
        InputUser.Add(user2);
        InputUser.Add(user3);

        user1.AssignInputDevice(keyboard); // Should automatically be unassigned.
        user3.AssignInputDevice(keyboard); // Should not be affected by any of what we do here.

        user1.AssignControlScheme(singleGamepadScheme).AndAssignDevices();
        user2.AssignControlScheme(dualGamepadScheme).AndAssignDevices();

        Assert.That(user1.GetAssignedInputDevices(), Is.EquivalentTo(new[] { gamepad1 }));
        Assert.That(user2.GetAssignedInputDevices(), Is.EquivalentTo(new[] { gamepad2, gamepad3 }));
        Assert.That(user3.GetAssignedInputDevices(), Is.EquivalentTo(new[] { keyboard }));
    }
Esempio n. 2
0
    public void Users_CanAssignDevicesToUsers()
    {
        var user1 = new TestUser();
        var user2 = new TestUser();

        var gamepad  = InputSystem.AddDevice <Gamepad>();
        var keyboard = InputSystem.AddDevice <Keyboard>();
        var mouse    = InputSystem.AddDevice <Mouse>();

        Assert.That(user1.GetAssignedInputDevices(), Is.Empty);
        Assert.That(user2.GetAssignedInputDevices(), Is.Empty);

        InputUser.Add(user1);
        InputUser.Add(user2);

        user1.AssignInputDevices(new InputDevice[] { keyboard, mouse });
        user2.AssignInputDevice(gamepad);

        Assert.That(user1.GetAssignedInputDevices(), Is.EquivalentTo(new InputDevice[] { keyboard, mouse }));
        Assert.That(user2.GetAssignedInputDevices(), Is.EquivalentTo(new InputDevice[] { gamepad }));
    }
Esempio n. 3
0
    public void Users_AssigningSameDeviceToSameUserMoreThanOnce_IsIgnored()
    {
        var device = InputSystem.AddDevice <Gamepad>();
        var user   = new TestUser();

        InputUser.Add(user);

        user.AssignInputDevice(device);
        user.AssignInputDevice(device);
        user.AssignInputDevice(device);

        Assert.That(user.GetAssignedInputDevices(), Is.EquivalentTo(new InputDevice[] { device }));
    }
Esempio n. 4
0
    public void Users_AssignedDevices_AreLostWhenUserIsRemoved()
    {
        var device1 = InputSystem.AddDevice <Gamepad>();
        var device2 = InputSystem.AddDevice <Gamepad>();

        var user = new TestUser();

        InputUser.Add(user);

        user.AssignInputDevice(device1);
        user.AssignInputDevice(device2);

        InputUser.Remove(user);

        Assert.That(user.GetAssignedInputDevices(), Has.Count.Zero);
    }
Esempio n. 5
0
    public void Users_CanAssignSameDeviceToMoreThanOneUser()
    {
        var user1 = new TestUser();
        var user2 = new TestUser();

        InputUser.Add(user1);
        InputUser.Add(user2);

        var gamepad = InputSystem.AddDevice <Gamepad>();

        user1.AssignInputDevice(gamepad);
        user2.AssignInputDevice(gamepad);

        Assert.That(user1.GetAssignedInputDevices(), Is.EquivalentTo(new InputDevice[] { gamepad }));
        Assert.That(user2.GetAssignedInputDevices(), Is.EquivalentTo(new InputDevice[] { gamepad }));
    }
Esempio n. 6
0
    public void Users_CanAssignControlScheme_AndAssignMissingDevices()
    {
        var gamepad1 = InputSystem.AddDevice <Gamepad>();
        var gamepad2 = InputSystem.AddDevice <Gamepad>();

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

        var user = new TestUser();

        InputUser.Add(user);

        user.AssignInputDevice(gamepad2);
        user.AssignControlScheme(gamepadScheme).AndAssignMissingDevices();

        Assert.That(user.GetAssignedInputDevices(), Is.EquivalentTo(new[] { gamepad2, gamepad1 }));
    }
Esempio n. 7
0
    public void Users_CanAssignDevicesToUserStepByStep()
    {
        var device1 = InputSystem.AddDevice <Gamepad>();
        var device2 = InputSystem.AddDevice <Gamepad>();
        var device3 = InputSystem.AddDevice <Gamepad>();

        var user1 = new TestUser();
        var user2 = new TestUser();

        InputUser.Add(user1);
        InputUser.Add(user2);

        user1.AssignInputDevice(device1);
        user2.AssignInputDevice(device2);
        user1.AssignInputDevice(device3);

        Assert.That(user1.GetAssignedInputDevices(), Is.EquivalentTo(new InputDevice[] { device1, device3 }));
        Assert.That(user2.GetAssignedInputDevices(), Is.EquivalentTo(new InputDevice[] { device2 }));
    }
Esempio n. 8
0
    public void Users_CanClearAssignedDevices()
    {
        var device = InputSystem.AddDevice <Gamepad>();

        var user1 = new TestUser();
        var user2 = new TestUser();
        var user3 = new TestUser();

        InputUser.Add(user1);
        InputUser.Add(user2);

        user1.AssignInputDevice(device);
        user1.ClearAssignedInputDevices();
        user2.ClearAssignedInputDevices();
        user3.ClearAssignedInputDevices();

        Assert.That(user1.GetAssignedInputDevices(), Is.Empty);
        Assert.That(user2.GetAssignedInputDevices(), Is.Empty);
        Assert.That(user3.GetAssignedInputDevices(), Is.Empty);
    }