Пример #1
0
    public void EditMode_InputActions_TriggerInEditMode()
    {
#if ENABLE_XR_COMBINED_DEFINE
        runtime.isInPlayMode             = false;
        InputSystem.runUpdatesInEditMode = true;
        var counter = new InputUpdateCounter();
        counter.Start();

        var gamepad = InputSystem.AddDevice <Gamepad>();
        var action  = new InputAction(binding: "<Gamepad>/leftTrigger");

        int performedCallCount = 0;
        action.performed += context => performedCallCount++;
        action.Enable();

        Set(gamepad.leftTrigger, 0f);
        InputSystem.Update(InputUpdateType.Dynamic);

        Assert.That(performedCallCount, Is.EqualTo(0));
        Assert.That(action.ReadValue <float>(), Is.EqualTo(0));

        Set(gamepad.leftTrigger, 0.75f, queueEventOnly: true);
        InputSystem.Update(InputUpdateType.Dynamic);

        Assert.That(performedCallCount, Is.EqualTo(1));
        Assert.That(action.ReadValue <float>(), Is.EqualTo(0.75f).Within(0.00001f));

        InputSystem.RemoveDevice(gamepad);
        InputSystem.runUpdatesInEditMode = true;
        runtime.isInPlayMode             = true;
        counter.Stop();
#endif
    }
Пример #2
0
    public void EditMode_RunUpdatesInEditMode_AllowsNonEditorUpdates(InputSettings.UpdateMode updateMode, InputUpdateType updateType)
    {
#if ENABLE_XR_COMBINED_DEFINE
        runtime.isInPlayMode            = false;
        InputSystem.settings.updateMode = updateMode;
        var counter = new InputUpdateCounter();
        counter.Start();

        InputSystem.Update(InputUpdateType.Editor);
        InputSystem.Update(updateType);

        Assert.That(counter.updates.Count, Is.EqualTo(1));
        Assert.That(counter.updates[0], Is.EqualTo(InputUpdateType.Editor));
        counter.Reset();
        InputSystem.runUpdatesInEditMode = true;

        InputSystem.Update(InputUpdateType.Editor);
        InputSystem.Update(updateType);

        Assert.That(counter.updates.Count, Is.EqualTo(2));
        Assert.That(counter.updates[0], Is.EqualTo(InputUpdateType.Editor));
        Assert.That(counter.updates[1], Is.EqualTo(updateType));
        counter.Reset();

        InputSystem.runUpdatesInEditMode = false;

        runtime.isInPlayMode = true;
        counter.Stop();
#endif
    }