docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class InputTestFixture

    A test fixture for writing tests that use the input system. Can be derived from or simply instantiated from another test fixture.

    Inheritance
    object
    InputTestFixture
    Namespace: UnityEngine.InputSystem
    Assembly: Unity.InputSystem.TestFramework.dll
    Syntax
    public class InputTestFixture
    Remarks

    The fixture will put the input system into a known state where it has only the built-in set of basic layouts and no devices. The state of the system before starting a test is recorded and restored when the test finishes.

    public class MyInputTests : InputTestFixture
    {
        public override void Setup()
        {
            base.Setup();
    
        InputSystem.RegisterLayout<MyDevice>();
    }
    
    [Test]
    public void CanCreateMyDevice()
    {
        InputSystem.AddDevice<MyDevice>();
        Assert.That(InputSystem.devices, Has.Exactly(1).TypeOf<MyDevice>());
    }
    

    }

    The test fixture will also sever the tie of the input system to the Unity runtime. This means that while the test fixture is active, the input system will not receive input and device discovery or removal notifications from platform code. This ensures that while the test is running, input that may be generated on the machine running the test will not infer with it.

    Properties

    currentTime

    Get or set the current time used by the input system.

    Declaration
    public double currentTime { get; set; }
    Property Value
    Type Description
    double

    Current time used by the input system.

    Methods

    AssertButtonPress<TState>(InputDevice, TState, params ButtonControl[])

    Declaration
    public static void AssertButtonPress<TState>(InputDevice device, TState state, params ButtonControl[] buttons) where TState : struct, IInputStateTypeInfo
    Parameters
    Type Name Description
    InputDevice device
    TState state
    ButtonControl[] buttons
    Type Parameters
    Name Description
    TState

    AssertStickValues(StickControl, Vector2, float, float, float, float)

    Declaration
    public static void AssertStickValues(StickControl stick, Vector2 stickValue, float up, float down, float left, float right)
    Parameters
    Type Name Description
    StickControl stick
    Vector2 stickValue
    float up
    float down
    float left
    float right

    BeginTouch(int, Vector2, bool, Touchscreen, double, double, byte)

    Declaration
    public void BeginTouch(int touchId, Vector2 position, bool queueEventOnly = false, Touchscreen screen = null, double time = -1, double timeOffset = 0, byte displayIndex = 0)
    Parameters
    Type Name Description
    int touchId
    Vector2 position
    bool queueEventOnly
    Touchscreen screen
    double time
    double timeOffset
    byte displayIndex

    BeginTouch(int, Vector2, float, bool, Touchscreen, double, double)

    Declaration
    public void BeginTouch(int touchId, Vector2 position, float pressure, bool queueEventOnly = false, Touchscreen screen = null, double time = -1, double timeOffset = 0)
    Parameters
    Type Name Description
    int touchId
    Vector2 position
    float pressure
    bool queueEventOnly
    Touchscreen screen
    double time
    double timeOffset

    CancelTouch(int, Vector2, float, Vector2, bool, Touchscreen, double, double)

    Declaration
    public void CancelTouch(int touchId, Vector2 position, float pressure, Vector2 delta = default, bool queueEventOnly = false, Touchscreen screen = null, double time = -1, double timeOffset = 0)
    Parameters
    Type Name Description
    int touchId
    Vector2 position
    float pressure
    Vector2 delta
    bool queueEventOnly
    Touchscreen screen
    double time
    double timeOffset

    CancelTouch(int, Vector2, Vector2, bool, Touchscreen, double, double)

    Declaration
    public void CancelTouch(int touchId, Vector2 position, Vector2 delta = default, bool queueEventOnly = false, Touchscreen screen = null, double time = -1, double timeOffset = 0)
    Parameters
    Type Name Description
    int touchId
    Vector2 position
    Vector2 delta
    bool queueEventOnly
    Touchscreen screen
    double time
    double timeOffset

    Canceled(InputAction, InputControl, double?, double?, object)

    Declaration
    public InputTestFixture.ActionConstraint Canceled(InputAction action, InputControl control = null, double? time = null, double? duration = null, object value = null)
    Parameters
    Type Name Description
    InputAction action
    InputControl control
    double? time
    double? duration
    object value
    Returns
    Type Description
    InputTestFixture.ActionConstraint

    Canceled<TInteraction>(InputAction, InputControl, object, double?, double?)

    Declaration
    public InputTestFixture.ActionConstraint Canceled<TInteraction>(InputAction action, InputControl control = null, object value = null, double? time = null, double? duration = null) where TInteraction : IInputInteraction
    Parameters
    Type Name Description
    InputAction action
    InputControl control
    object value
    double? time
    double? duration
    Returns
    Type Description
    InputTestFixture.ActionConstraint
    Type Parameters
    Name Description
    TInteraction

    Canceled<TValue>(InputAction, InputControl<TValue>, TValue, double?, double?)

    Declaration
    public InputTestFixture.ActionConstraint Canceled<TValue>(InputAction action, InputControl<TValue> control, TValue value, double? time = null, double? duration = null) where TValue : struct
    Parameters
    Type Name Description
    InputAction action
    InputControl<TValue> control
    TValue value
    double? time
    double? duration
    Returns
    Type Description
    InputTestFixture.ActionConstraint
    Type Parameters
    Name Description
    TValue

    Click(ButtonControl, double, double, bool)

    Declaration
    public void Click(ButtonControl button, double time = -1, double timeOffset = 0, bool queueEventOnly = false)
    Parameters
    Type Name Description
    ButtonControl button
    double time
    double timeOffset
    bool queueEventOnly

    EndTouch(int, Vector2, float, Vector2, bool, Touchscreen, double, double)

    Declaration
    public void EndTouch(int touchId, Vector2 position, float pressure, Vector2 delta = default, bool queueEventOnly = false, Touchscreen screen = null, double time = -1, double timeOffset = 0)
    Parameters
    Type Name Description
    int touchId
    Vector2 position
    float pressure
    Vector2 delta
    bool queueEventOnly
    Touchscreen screen
    double time
    double timeOffset

    EndTouch(int, Vector2, Vector2, bool, Touchscreen, double, double, byte)

    Declaration
    public void EndTouch(int touchId, Vector2 position, Vector2 delta = default, bool queueEventOnly = false, Touchscreen screen = null, double time = -1, double timeOffset = 0, byte displayIndex = 0)
    Parameters
    Type Name Description
    int touchId
    Vector2 position
    Vector2 delta
    bool queueEventOnly
    Touchscreen screen
    double time
    double timeOffset
    byte displayIndex

    Move(InputControl<Vector2>, Vector2, Vector2?, double, double, bool)

    Declaration
    public void Move(InputControl<Vector2> positionControl, Vector2 position, Vector2? delta = null, double time = -1, double timeOffset = 0, bool queueEventOnly = false)
    Parameters
    Type Name Description
    InputControl<Vector2> positionControl
    Vector2 position
    Vector2? delta
    double time
    double timeOffset
    bool queueEventOnly

    MoveTouch(int, Vector2, float, Vector2, bool, Touchscreen, double, double)

    Declaration
    public void MoveTouch(int touchId, Vector2 position, float pressure, Vector2 delta = default, bool queueEventOnly = false, Touchscreen screen = null, double time = -1, double timeOffset = 0)
    Parameters
    Type Name Description
    int touchId
    Vector2 position
    float pressure
    Vector2 delta
    bool queueEventOnly
    Touchscreen screen
    double time
    double timeOffset

    MoveTouch(int, Vector2, Vector2, bool, Touchscreen, double, double)

    Declaration
    public void MoveTouch(int touchId, Vector2 position, Vector2 delta = default, bool queueEventOnly = false, Touchscreen screen = null, double time = -1, double timeOffset = 0)
    Parameters
    Type Name Description
    int touchId
    Vector2 position
    Vector2 delta
    bool queueEventOnly
    Touchscreen screen
    double time
    double timeOffset

    Performed(InputAction, InputControl, double?, double?, object)

    Declaration
    public InputTestFixture.ActionConstraint Performed(InputAction action, InputControl control = null, double? time = null, double? duration = null, object value = null)
    Parameters
    Type Name Description
    InputAction action
    InputControl control
    double? time
    double? duration
    object value
    Returns
    Type Description
    InputTestFixture.ActionConstraint

    Performed<TInteraction>(InputAction, InputControl, object, double?, double?)

    Declaration
    public InputTestFixture.ActionConstraint Performed<TInteraction>(InputAction action, InputControl control = null, object value = null, double? time = null, double? duration = null) where TInteraction : IInputInteraction
    Parameters
    Type Name Description
    InputAction action
    InputControl control
    object value
    double? time
    double? duration
    Returns
    Type Description
    InputTestFixture.ActionConstraint
    Type Parameters
    Name Description
    TInteraction

    Performed<TValue>(InputAction, InputControl<TValue>, TValue, double?, double?)

    Declaration
    public InputTestFixture.ActionConstraint Performed<TValue>(InputAction action, InputControl<TValue> control, TValue value, double? time = null, double? duration = null) where TValue : struct
    Parameters
    Type Name Description
    InputAction action
    InputControl<TValue> control
    TValue value
    double? time
    double? duration
    Returns
    Type Description
    InputTestFixture.ActionConstraint
    Type Parameters
    Name Description
    TValue

    Press(ButtonControl, double, double, bool)

    Declaration
    public void Press(ButtonControl button, double time = -1, double timeOffset = 0, bool queueEventOnly = false)
    Parameters
    Type Name Description
    ButtonControl button
    double time
    double timeOffset
    bool queueEventOnly

    PressAndRelease(ButtonControl, double, double, bool)

    Declaration
    public void PressAndRelease(ButtonControl button, double time = -1, double timeOffset = 0, bool queueEventOnly = false)
    Parameters
    Type Name Description
    ButtonControl button
    double time
    double timeOffset
    bool queueEventOnly

    Release(ButtonControl, double, double, bool)

    Declaration
    public void Release(ButtonControl button, double time = -1, double timeOffset = 0, bool queueEventOnly = false)
    Parameters
    Type Name Description
    ButtonControl button
    double time
    double timeOffset
    bool queueEventOnly

    SetKeyInfo(Key, string, int)

    Set the displayName of key on the current Keyboard to be displayName.

    Declaration
    public void SetKeyInfo(Key key, string displayName, int scanCode = 0)
    Parameters
    Type Name Description
    Key key

    Key to set the display name for.

    string displayName

    Display name for the key.

    int scanCode

    Optional scanCode to report for the key.

    Remarks

    Automatically adds a Keyboard if none has been added yet.

    SetKeyboardLayout(string, Keyboard)

    Set keyboardLayout of the given keyboard.

    Declaration
    public void SetKeyboardLayout(string name, Keyboard keyboard = null)
    Parameters
    Type Name Description
    string name

    Name of the keyboard layout to switch to.

    Keyboard keyboard

    Keyboard to switch layout on. If null, current is used.

    Remarks

    Also queues and immediately processes an DeviceConfigurationEvent for the keyboard.

    Exceptions
    Type Condition
    ArgumentException

    keyboard and current are both null.

    SetTouch(int, TouchPhase, Vector2, float, Vector2, bool, Touchscreen, double, double, byte)

    Declaration
    public void SetTouch(int touchId, TouchPhase phase, Vector2 position, float pressure, Vector2 delta = default, bool queueEventOnly = true, Touchscreen screen = null, double time = -1, double timeOffset = 0, byte displayIndex = 0)
    Parameters
    Type Name Description
    int touchId
    TouchPhase phase
    Vector2 position
    float pressure
    Vector2 delta
    bool queueEventOnly
    Touchscreen screen
    double time
    double timeOffset
    byte displayIndex

    SetTouch(int, TouchPhase, Vector2, Vector2, bool, Touchscreen, double, double)

    Declaration
    public void SetTouch(int touchId, TouchPhase phase, Vector2 position, Vector2 delta = default, bool queueEventOnly = true, Touchscreen screen = null, double time = -1, double timeOffset = 0)
    Parameters
    Type Name Description
    int touchId
    TouchPhase phase
    Vector2 position
    Vector2 delta
    bool queueEventOnly
    Touchscreen screen
    double time
    double timeOffset

    Set<TValue>(InputControl<TValue>, TValue, double, double, bool)

    Set the control to the given value by sending a state event with the value to the control's device.

    Declaration
    public void Set<TValue>(InputControl<TValue> control, TValue state, double time = -1, double timeOffset = 0, bool queueEventOnly = false) where TValue : struct
    Parameters
    Type Name Description
    InputControl<TValue> control

    An input control on a device that has been added to the system.

    TValue state

    New value for the input control.

    double time

    Timestamp to use for the state event. If -1 (default), current time is used (see currentTime).

    double timeOffset

    Offset to apply to the current time. This is an alternative to time. By default, no offset is applied.

    bool queueEventOnly

    If true, no Update() will be performed after queueing the event. This will only put the state event on the event queue and not do anything else. The default is to call Update() after queuing the event. Note that not issuing an update means the state of the device will not change yet. This may affect subsequent Set/Press/Release/etc calls as they will not yet see the state change.

     Note that this parameter will be ignored if the test is a <code>[UnityTest]</code>. Multi-frame
     playmode tests will automatically process input as part of the Unity player loop.
    
    Type Parameters
    Name Description
    TValue

    Value type of the given control.

    Examples
    var gamepad = InputSystem.AddDevice<Gamepad>();
    Set(gamepad.leftButton, 1);

    Set<TValue>(InputDevice, string, TValue, double, double, bool)

    Set the control with the given path on device to the given state by sending a state event with the value to the device.

    Declaration
    public void Set<TValue>(InputDevice device, string path, TValue state, double time = -1, double timeOffset = 0, bool queueEventOnly = false) where TValue : struct
    Parameters
    Type Name Description
    InputDevice device

    Device on which to find a control.

    string path

    Path of the control on the device.

    TValue state

    New state for the control.

    double time

    Timestamp to use for the state event. If -1 (default), current time is used (see currentTime).

    double timeOffset

    Offset to apply to the current time. This is an alternative to time. By default, no offset is applied.

    bool queueEventOnly

    If true, no Update() will be performed after queueing the event. This will only put the state event on the event queue and not do anything else. The default is to call Update() after queuing the event. Note that not issuing an update means the state of the device will not change yet. This may affect subsequent Set/Press/Release/etc calls as they will not yet see the state change.

     Note that this parameter will be ignored if the test is a <code>[UnityTest]</code>. Multi-frame
     playmode tests will automatically process input as part of the Unity player loop.
    
    Type Parameters
    Name Description
    TValue

    Value type of the control.

    Examples
    var device = InputSystem.AddDevice("TestDevice");
    Set<ButtonControl>(device, "button", 1);
    Set<AxisControl>(device, "{Primary2DMotion}/x", 123.456f);

    Setup()

    Put InputSystem into a known state where it only has a basic set of layouts and does not have any input devices.

    Declaration
    [SetUp]
    public virtual void Setup()
    Remarks

    If you derive your own test fixture directly from InputTestFixture, this method will automatically be called. If you embed InputTestFixture into your fixture, you have to explicitly call this method yourself.

    See Also
    TearDown()

    Started(InputAction, InputControl, double?, object)

    Declaration
    public InputTestFixture.ActionConstraint Started(InputAction action, InputControl control = null, double? time = null, object value = null)
    Parameters
    Type Name Description
    InputAction action
    InputControl control
    double? time
    object value
    Returns
    Type Description
    InputTestFixture.ActionConstraint

    Started<TInteraction>(InputAction, InputControl, object, double?)

    Declaration
    public InputTestFixture.ActionConstraint Started<TInteraction>(InputAction action, InputControl control = null, object value = null, double? time = null) where TInteraction : IInputInteraction
    Parameters
    Type Name Description
    InputAction action
    InputControl control
    object value
    double? time
    Returns
    Type Description
    InputTestFixture.ActionConstraint
    Type Parameters
    Name Description
    TInteraction

    Started<TValue>(InputAction, InputControl<TValue>, TValue, double?)

    Declaration
    public InputTestFixture.ActionConstraint Started<TValue>(InputAction action, InputControl<TValue> control, TValue value, double? time = null) where TValue : struct
    Parameters
    Type Name Description
    InputAction action
    InputControl<TValue> control
    TValue value
    double? time
    Returns
    Type Description
    InputTestFixture.ActionConstraint
    Type Parameters
    Name Description
    TValue

    TearDown()

    Restore the state of the input system it had when the test was started.

    Declaration
    [TearDown]
    public virtual void TearDown()
    See Also
    Setup()

    Trigger(InputAction)

    Perform the input action without having to know what it is bound to.

    Declaration
    public void Trigger(InputAction action)
    Parameters
    Type Name Description
    InputAction action

    An input action that is currently enabled and has controls it is bound to.

    Remarks

    Blindly triggering an action requires making a few assumptions. Actions are not built to be able to trigger without any input. This means that this method has to generate input on a control that the action is bound to.

    Note that this method has no understanding of the interactions that may be present on the action and thus does not know how they may affect the triggering of the action.

    Trigger<TValue>(InputAction, InputControl<TValue>, TValue)

    Declaration
    public void Trigger<TValue>(InputAction action, InputControl<TValue> control, TValue value) where TValue : struct
    Parameters
    Type Name Description
    InputAction action
    InputControl<TValue> control
    TValue value
    Type Parameters
    Name Description
    TValue
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)