Class InputTestFixture | Package Manager UI website
docs.unity3d.com
    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
    System.Object
    InputTestFixture
    Namespace: UnityEngine.InputSystem
    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.

    Examples
    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>());
        }
    }

    Properties

    runtime

    The input runtime used during testing.

    Declaration
    public InputTestRuntime runtime { get; }
    Property Value
    Type Description
    InputTestRuntime

    Methods

    AssertButtonPress<TState>(InputDevice, TState, 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

    BeginTouch(Int32, Vector2, Boolean, Touchscreen, Double, Double)

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

    Canceled(InputAction, InputControl, Nullable<Double>)

    Declaration
    public InputTestFixture.ActionConstraint Canceled(InputAction action, InputControl control = null, double? time = default(double? ))
    Parameters
    Type Name Description
    InputAction action
    InputControl control
    System.Nullable<System.Double> time
    Returns
    Type Description
    InputTestFixture.ActionConstraint

    Canceled<TInteraction>(InputAction, InputControl, Nullable<Double>)

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

    Canceled<TValue>(InputAction, InputControl<TValue>, TValue, Nullable<Double>)

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

    CancelTouch(Int32, Vector2, Vector2, Boolean, Touchscreen, Double, Double)

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

    Click(ButtonControl, Double, Double, Boolean)

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

    EndTouch(Int32, Vector2, Vector2, Boolean, Touchscreen, Double, Double)

    Declaration
    public void EndTouch(int touchId, Vector2 position, Vector2 delta = null, bool queueEventOnly = false, Touchscreen screen = null, double time = -1, double timeOffset = 0)
    Parameters
    Type Name Description
    System.Int32 touchId
    Vector2 position
    Vector2 delta
    System.Boolean queueEventOnly
    Touchscreen screen
    System.Double time
    System.Double timeOffset

    Move(InputControl<Vector2>, Vector2, Nullable<Vector2>, Double, Double, Boolean)

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

    MoveTouch(Int32, Vector2, Vector2, Boolean, Touchscreen, Double, Double)

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

    Performed(InputAction, InputControl, Nullable<Double>)

    Declaration
    public InputTestFixture.ActionConstraint Performed(InputAction action, InputControl control = null, double? time = default(double? ))
    Parameters
    Type Name Description
    InputAction action
    InputControl control
    System.Nullable<System.Double> time
    Returns
    Type Description
    InputTestFixture.ActionConstraint

    Performed<TInteraction>(InputAction, InputControl, Nullable<Double>)

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

    Performed<TValue>(InputAction, InputControl<TValue>, TValue, Nullable<Double>)

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

    Press(ButtonControl, Double, Double, Boolean)

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

    PressAndRelease(ButtonControl, Double, Double, Boolean)

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

    Release(ButtonControl, Double, Double, Boolean)

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

    Set<TValue>(InputControl<TValue>, TValue, Double, Double, Boolean)

    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.

    System.Double time
    System.Double timeOffset
    System.Boolean queueEventOnly
    Type Parameters
    Name Description
    TValue

    Value type of the given control.

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

    SetTouch(Int32, TouchPhase, Vector2, Vector2, Boolean, Touchscreen, Double, Double)

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

    Setup()

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

    Declaration
    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.

    Started(InputAction, InputControl, Nullable<Double>)

    Declaration
    public InputTestFixture.ActionConstraint Started(InputAction action, InputControl control = null, double? time = default(double? ))
    Parameters
    Type Name Description
    InputAction action
    InputControl control
    System.Nullable<System.Double> time
    Returns
    Type Description
    InputTestFixture.ActionConstraint

    Started<TInteraction>(InputAction, InputControl, Nullable<Double>)

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

    Started<TValue>(InputAction, InputControl<TValue>, TValue, Nullable<Double>)

    Declaration
    public InputTestFixture.ActionConstraint Started<TValue>(InputAction action, InputControl<TValue> control, TValue value, double? time = default(double? ))
        where TValue : struct
    Parameters
    Type Name Description
    InputAction action
    InputControl<TValue> control
    TValue value
    System.Nullable<System.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
    public virtual void TearDown()

    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
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023