docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class InputControl<TValue>

    Base class for input controls with a specific value type.

    Inheritance
    object
    InputControl
    InputControl<TValue>
    AxisControl
    DoubleControl
    IntegerControl
    QuaternionControl
    TouchControl
    TouchPhaseControl
    Vector2Control
    Vector3Control
    BoneControl
    EyesControl
    PoseControl
    Inherited Members
    InputControl.name
    InputControl.displayName
    InputControl.shortDisplayName
    InputControl.path
    InputControl.layout
    InputControl.variants
    InputControl.device
    InputControl.parent
    InputControl.children
    InputControl.usages
    InputControl.aliases
    InputControl.stateBlock
    InputControl.noisy
    InputControl.synthetic
    InputControl.this[string]
    InputControl.magnitude
    InputControl.ToString()
    InputControl.EvaluateMagnitude()
    InputControl.EvaluateMagnitude(void*)
    InputControl.TryGetChildControl(string)
    InputControl.TryGetChildControl<TControl>(string)
    InputControl.GetChildControl(string)
    InputControl.GetChildControl<TControl>(string)
    InputControl.RefreshConfigurationIfNeeded()
    InputControl.RefreshConfiguration()
    InputControl.m_StateBlock
    InputControl.currentStatePtr
    InputControl.previousFrameStatePtr
    InputControl.defaultStatePtr
    InputControl.noiseMaskPtr
    InputControl.stateOffsetRelativeToDeviceRoot
    InputControl.optimizedControlDataType
    InputControl.CalculateOptimizedControlDataType()
    InputControl.ApplyParameterChanges()
    Namespace: UnityEngine.InputSystem
    Assembly: Unity.InputSystem.dll
    Syntax
    public abstract class InputControl<TValue> : InputControl where TValue : struct
    Type Parameters
    Name Description
    TValue

    Type of value captured by the control. Note that this does not mean that the control has to store data in the given value format. A control that captures float values, for example, may be stored in state as byte values instead.

    Properties

    value

    Returns the current value of the control after processors have been applied.

    Declaration
    public ref readonly TValue value { get; }
    Property Value
    Type Description
    TValue

    The controls current value.

    Remarks

    This can only be called on devices that have been added to the system (added).

    If internal feature "USE_READ_VALUE_CACHING" is enabled, then this property implements caching to avoid applying processors when the underlying control has not changed. With this in mind, be aware of processors that use global state, such as the AxisDeadzoneProcessor. Unless the control unprocessed value has been changed, input system settings changed or ApplyParameterChanges() invoked, the processors will not run and calls to value will return the same result as previous calls.

    If a processor requires to be run on every read, override cachingPolicy property in the processor and set it to EvaluateOnEveryRead.

    To improve debugging try setting "PARANOID_READ_VALUE_CACHING_CHECKS" internal feature flag to check if cache value is still consistent.

    Also note that this property returns the result as ref readonly. If custom control states are in use, i.e. any controls not shipped with the Input System package, be careful of accidental defensive copies https://docs.microsoft.com/en-us/dotnet/csharp/write-safe-efficient-code#avoid-defensive-copies.

    See Also
    ReadValue()

    valueSizeInBytes

    Size in bytes of values that the control returns.

    Declaration
    public override int valueSizeInBytes { get; }
    Property Value
    Type Description
    int
    Overrides
    InputControl.valueSizeInBytes
    See Also
    valueType

    valueType

    Returns the underlying value type of this control.

    Declaration
    public override Type valueType { get; }
    Property Value
    Type Description
    Type

    Type of values produced by the control.

    Overrides
    InputControl.valueType
    Remarks

    This is the type of values that are returned when reading the current value of a control or when reading a value of a control from an event.

    See Also
    valueSizeInBytes
    ReadValueFromStateAsObject(void*)

    Methods

    CompareValue(void*, void*)

    Compare the value of the control as read from firstStatePtr to that read from secondStatePtr and return true if they are equal.

    Declaration
    public override bool CompareValue(void* firstStatePtr, void* secondStatePtr)
    Parameters
    Type Name Description
    void* firstStatePtr

    Memory containing the control's stateBlock.

    void* secondStatePtr

    Memory containing the control's stateBlock

    Returns
    Type Description
    bool

    True if the value of the control is equal in both firstStatePtr and secondStatePtr.

    Overrides
    InputControl.CompareValue(void*, void*)
    Remarks

    Unlike CompareValue(void*, void*), this method will have to do more than just compare the memory for the control in the two state buffers. It will have to read out state for the control and run the full processing machinery for the control to turn the state into a final, processed value. CompareValue is thus more costly than CompareValue(void*, void*).

    This method will apply epsilons (Epsilon) when comparing floats.

    See Also
    CompareValue(void*, void*)

    FinishSetup()

    Perform final initialization tasks after the control hierarchy has been put into place.

    Declaration
    protected override void FinishSetup()
    Overrides
    InputControl.FinishSetup()
    Remarks

    This method can be overridden to perform control- or device-specific setup work. The most common use case is for looking up child controls and storing them in local getters.

    public class MyDevice : InputDevice
    {
    public ButtonControl button { get; private set; }
    public AxisControl axis { get; private set; }

             protected override void OnFinishSetup()
             {
                 // Cache controls in getters.
                 button = GetChildControl("button");
                 axis = GetChildControl("axis");
             }
         }</code></pre></example>
    

    ProcessValue(TValue)

    Declaration
    public TValue ProcessValue(TValue value)
    Parameters
    Type Name Description
    TValue value
    Returns
    Type Description
    TValue

    ProcessValue(ref TValue)

    Applies all control processors to the passed value.

    Declaration
    public void ProcessValue(ref TValue value)
    Parameters
    Type Name Description
    TValue value
    Remarks

    Use this overload when your state struct is large to avoid creating copies of the state.

    ReadDefaultValue()

    Get the control's default value.

    Declaration
    public TValue ReadDefaultValue()
    Returns
    Type Description
    TValue

    The control's default value.

    Remarks

    This is not necessarily equivalent to default(TValue). A control's default value is determined by reading its value from the default state (defaultStatePtr) which in turn is determined from settings in the control's registered layout (defaultState).

    ReadUnprocessedValue()

    Declaration
    public TValue ReadUnprocessedValue()
    Returns
    Type Description
    TValue

    ReadUnprocessedValueFromState(void*)

    Declaration
    public abstract TValue ReadUnprocessedValueFromState(void* statePtr)
    Parameters
    Type Name Description
    void* statePtr
    Returns
    Type Description
    TValue

    ReadUnprocessedValueFromStateWithCaching(void*)

    Read value from provided statePtr. Try cache result if possible.

    Declaration
    public TValue ReadUnprocessedValueFromStateWithCaching(void* statePtr)
    Parameters
    Type Name Description
    void* statePtr

    State pointer to read from.

    Returns
    Type Description
    TValue

    The controls current value.

    Remarks

    If statePtr is "currentStatePtr", then read will be done via unprocessedValue property to improve performance.

    See Also
    value

    ReadValue()

    Returns the current value of the control after processors have been applied.

    Declaration
    public TValue ReadValue()
    Returns
    Type Description
    TValue

    The controls current value.

    Remarks

    This can only be called on devices that have been added to the system (added).

    If internal feature "USE_READ_VALUE_CACHING" is enabled, then this property implements caching to avoid applying processors when the underlying control has not changed. With this in mind, be aware of processors that use global state, such as the AxisDeadzoneProcessor. Unless the control unprocessed value has been changed, input system settings changed or ApplyParameterChanges() invoked, the processors will not run and calls to value will return the same result as previous calls.

    If a processor requires to be run on every read, override cachingPolicy property in the processor and set it to EvaluateOnEveryRead.

    To improve debugging try setting "PARANOID_READ_VALUE_CACHING_CHECKS" internal feature flag to check if cache value is still consistent. https://docs.microsoft.com/en-us/dotnet/csharp/write-safe-efficient-code#avoid-defensive-copies.

    See Also
    value

    ReadValueFromBufferAsObject(void*, int)

    Declaration
    public override object ReadValueFromBufferAsObject(void* buffer, int bufferSize)
    Parameters
    Type Name Description
    void* buffer
    int bufferSize
    Returns
    Type Description
    object
    Overrides
    InputControl.ReadValueFromBufferAsObject(void*, int)

    ReadValueFromPreviousFrame()

    Get the control's value from the previous frame (previousFrameStatePtr).

    Declaration
    public TValue ReadValueFromPreviousFrame()
    Returns
    Type Description
    TValue

    The control's value in the previous frame.

    ReadValueFromState(void*)

    Declaration
    public TValue ReadValueFromState(void* statePtr)
    Parameters
    Type Name Description
    void* statePtr
    Returns
    Type Description
    TValue

    ReadValueFromStateAsObject(void*)

    Read the control's final, processed value from the given state and return the value as an object.

    Declaration
    public override object ReadValueFromStateAsObject(void* statePtr)
    Parameters
    Type Name Description
    void* statePtr
    Returns
    Type Description
    object

    The control's value as stored in statePtr.

    Overrides
    InputControl.ReadValueFromStateAsObject(void*)
    Remarks

    This method allocates GC memory and should not be used during normal gameplay operation.

    Exceptions
    Type Condition
    ArgumentNullException

    statePtr is null.

    See Also
    ReadValueFromStateIntoBuffer(void*, void*, int)

    ReadValueFromStateIntoBuffer(void*, void*, int)

    Read the control's final, processed value from the given state and store it in the given buffer.

    Declaration
    public override void ReadValueFromStateIntoBuffer(void* statePtr, void* bufferPtr, int bufferSize)
    Parameters
    Type Name Description
    void* statePtr

    State to read the value for the control from.

    void* bufferPtr

    Buffer to store the value in.

    int bufferSize

    Size of bufferPtr in bytes. Must be at least valueSizeInBytes. If it is smaller, ArgumentException will be thrown.

    Overrides
    InputControl.ReadValueFromStateIntoBuffer(void*, void*, int)
    Exceptions
    Type Condition
    ArgumentNullException

    statePtr is null, or bufferPtr is null.

    ArgumentException

    bufferSize is smaller than valueSizeInBytes.

    See Also
    ReadValueFromStateAsObject(void*)
    WriteValueFromBufferIntoState(void*, int, void*)

    ReadValueFromStateWithCaching(void*)

    Read value from provided statePtr and apply processors. Try cache result if possible.

    Declaration
    public TValue ReadValueFromStateWithCaching(void* statePtr)
    Parameters
    Type Name Description
    void* statePtr

    State pointer to read from.

    Returns
    Type Description
    TValue

    The controls current value.

    Remarks

    If statePtr is "currentStatePtr", then read will be done via value property to improve performance.

    See Also
    value

    WriteValueFromBufferIntoState(void*, int, void*)

    Read a value from the given memory and store it as state.

    Declaration
    public override void WriteValueFromBufferIntoState(void* bufferPtr, int bufferSize, void* statePtr)
    Parameters
    Type Name Description
    void* bufferPtr

    Memory containing value.

    int bufferSize

    Size of bufferPtr in bytes. Must be at least valueSizeInBytes.

    void* statePtr

    State containing the control's stateBlock. Will receive the state as converted from the given value.

    Overrides
    InputControl.WriteValueFromBufferIntoState(void*, int, void*)
    Remarks

    Writing values will NOT apply processors to the given value. This can mean that when reading a value from a control after it has been written to its state, the resulting value differs from what was written.

    Exceptions
    Type Condition
    NotSupportedException

    The control does not support writing. This is the case, for example, that compute values (such as the magnitude of a vector).

    See Also
    ReadValueFromStateIntoBuffer(void*, void*, int)
    WriteValueFromObjectIntoState(object, void*)

    WriteValueFromObjectIntoState(object, void*)

    Read a value object and store it as state in the given memory.

    Declaration
    public override void WriteValueFromObjectIntoState(object value, void* statePtr)
    Parameters
    Type Name Description
    object value

    Value for the control.

    void* statePtr

    State containing the control's stateBlock. Will receive the state state as converted from the given value.

    Overrides
    InputControl.WriteValueFromObjectIntoState(object, void*)
    Remarks

    Writing values will NOT apply processors to the given value. This can mean that when reading a value from a control after it has been written to its state, the resulting value differs from what was written.

    Exceptions
    Type Condition
    NotSupportedException

    The control does not support writing. This is the case, for example, that compute values (such as the magnitude of a vector).

    See Also
    WriteValueFromBufferIntoState(void*, int, void*)

    WriteValueIntoState(TValue, void*)

    Declaration
    public virtual void WriteValueIntoState(TValue value, void* statePtr)
    Parameters
    Type Name Description
    TValue value
    void* statePtr

    Extension Methods

    InputControlExtensions.CheckStateIsAtDefault(InputControl)
    InputControlExtensions.CheckStateIsAtDefault(InputControl, void*, void*)
    InputControlExtensions.CheckStateIsAtDefaultIgnoringNoise(InputControl)
    InputControlExtensions.CheckStateIsAtDefaultIgnoringNoise(InputControl, void*)
    InputControlExtensions.CompareState(InputControl, void*, void*)
    InputControlExtensions.CompareState(InputControl, void*, void*, void*)
    InputControlExtensions.CompareStateIgnoringNoise(InputControl, void*)
    InputControlExtensions.FindControlsRecursive<TControl>(InputControl, IList<TControl>, Func<TControl, bool>)
    InputControlExtensions.FindInParentChain<TControl>(InputControl)
    InputControlExtensions.GetStatePtrFromStateEvent(InputControl, InputEventPtr)
    InputControlExtensions.HasValueChangeInEvent(InputControl, InputEventPtr)
    InputControlExtensions.HasValueChangeInState(InputControl, void*)
    InputControlExtensions.IsActuated(InputControl, float)
    InputControlExtensions.IsPressed(InputControl, float)
    InputControlExtensions.ReadDefaultValueAsObject(InputControl)
    InputControlExtensions.ReadValueAsObject(InputControl)
    InputControlExtensions.ReadValueFromEventAsObject(InputControl, InputEventPtr)
    InputControlExtensions.ReadValueIntoBuffer(InputControl, void*, int)
    InputControlExtensions.ResetToDefaultStateInEvent(InputControl, InputEventPtr)
    InputControlExtensions.WriteValueFromObjectIntoEvent(InputControl, InputEventPtr, object)
    InputControlExtensions.WriteValueIntoEvent<TValue>(InputControl, TValue, InputEventPtr)
    InputControlExtensions.WriteValueIntoState(InputControl, void*)
    InputControlExtensions.WriteValueIntoState<TValue>(InputControl, TValue, void*)
    InputControlExtensions.QueueValueChange<TValue>(InputControl<TValue>, TValue, double)
    InputControlExtensions.ReadUnprocessedValueFromEvent<TValue>(InputControl<TValue>, InputEventPtr)
    InputControlExtensions.ReadUnprocessedValueFromEvent<TValue>(InputControl<TValue>, InputEventPtr, out TValue)
    InputControlExtensions.ReadValueFromEvent<TValue>(InputControl<TValue>, InputEventPtr)
    InputControlExtensions.ReadValueFromEvent<TValue>(InputControl<TValue>, InputEventPtr, out TValue)
    InputControlExtensions.WriteValueIntoEvent<TValue>(InputControl<TValue>, TValue, InputEventPtr)
    InputControlExtensions.WriteValueIntoState<TValue>(InputControl<TValue>, void*)
    InputControlExtensions.WriteValueIntoState<TValue>(InputControl<TValue>, TValue, void*)
    InputControlExtensions.WriteValueIntoState<TValue, TState>(InputControl<TValue>, TValue, ref TState)
    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)