Example #1
0
    public void Users_CanActivateAndPassivateInput()
    {
        var gamepad = InputSystem.AddDevice <Gamepad>();

        var action             = new InputAction(binding: "<Gamepad>/leftTrigger");
        var actionWasTriggered = false;

        action.performed += _ => actionWasTriggered = true;

        var user = new TestUser();

        InputUser.Add(user);

        user.GetInputActions().Push(action);

        // Make sure user is passive by default.
        Assert.That(user.IsInputActive(), Is.False);

        InputSystem.QueueStateEvent(gamepad, new GamepadState {
            leftTrigger = 0.124f
        });
        InputSystem.Update();

        Assert.That(actionWasTriggered, Is.False);

        // Activate user input.
        user.ActivateInput();

        InputSystem.QueueStateEvent(gamepad, new GamepadState {
            leftTrigger = 0.234f
        });
        InputSystem.Update();

        Assert.That(actionWasTriggered, Is.True);
        actionWasTriggered = false;

        // Passivate user input again.
        user.PassivateInput();

        InputSystem.QueueStateEvent(gamepad, new GamepadState {
            leftTrigger = 0.234f
        });
        InputSystem.Update();

        Assert.That(actionWasTriggered, Is.False);
    }