コード例 #1
0
ファイル: UserTests.cs プロジェクト: kuriharaan/InputSystem
    public void Users_CanAssignActionAssetToUser()
    {
        var asset = ScriptableObject.CreateInstance <InputActionAsset>();

        var user = new TestUser();

        InputUser.Add(user);

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

        user.AssignInputActions(asset);

        Assert.That(user.GetInputActions(), Is.SameAs(asset));
    }
コード例 #2
0
    public void Users_CanAssignActionsToUsers()
    {
        var action = new InputAction();

        var user = new TestUser();

        InputUser.Add(user);

        Assert.That(user.GetInputActions(), Is.Empty);

        user.GetInputActions().Push(action);

        Assert.That(user.GetInputActions(), Is.EquivalentTo(new[] { action }));

        user.GetInputActions().Clear();

        Assert.That(user.GetInputActions(), Is.Empty);
    }
コード例 #3
0
    public void TODO_Users_CanAssignActionsToUsers()
    {
        var user = new TestUser();

        InputUser.Add(user);

        var action = new InputAction();

        user.GetInputActions().Push(action);

        Assert.Fail();
    }
コード例 #4
0
    public void Users_CanAssignActionMapsToUsers()
    {
        var map = new InputActionMap();

        var action1 = map.AddAction("action1");
        var action2 = map.AddAction("action2");

        var user = new TestUser();

        InputUser.Add(user);

        user.SetInputActions(map);

        Assert.That(user.GetInputActions(), Is.EquivalentTo(new[] { action1, action2 }));
    }
コード例 #5
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);
    }