docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct InputControlExtensions.InputEventControlEnumerator

    Iterates over the controls in a StateEvent or DeltaStateEvent while optionally applying certain filtering criteria.

    Implements
    IEnumerator<InputControl>
    IEnumerator
    IDisposable
    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    ValueType.ToString()
    Namespace: UnityEngine.InputSystem
    Assembly: Unity.InputSystem.dll
    Syntax
    public struct InputControlExtensions.InputEventControlEnumerator : IEnumerator<InputControl>, IEnumerator, IDisposable
    Remarks

    One problem with state events (that is, StateEvent and DeltaStateEvent) is that they contain raw blocks of memory which may contain state changes for arbitrary many controls on a device at the same time. Locating individual controls and determining which have changed state and how can thus be quite inefficient.

    This helper aims to provide an easy and efficient way to iterate over controls relevant to a given state event. Instead of iterating over the controls of a device looking for the ones relevant to a given event, enumeration is done the opposite by efficiently searching through the memory contained in an event and then mapping data found in the event back to controls on a given device.

    // Inefficient:
    foreach (var control in device.allControls)
    {
        // Skip control if it is noisy, synthetic, or not a leaf control.
        if (control.synthetic || control.noisy || control.children.Count > 0)
            continue;
    
    // Locate the control in the event.
    var statePtr = eventPtr.GetStatePtrFromStateEvent(eventPtr);
    if (statePtr == null)
        continue; // Control not included in event.
    
    // See if the control is actuated beyond a minimum threshold.
    if (control.EvaluateMagnitude(statePtr) < 0.001f)
        continue;
    
    Debug.Log($"Found actuated control {control}");
    

    }

    // Much more efficient: foreach (var control in eventPtr.EnumerateControls( InputControlExtensions.Enumerate.IgnoreControlsInDefaultState, device: device, magnitudeThreshold: 0.001f)) { Debug.Log($"Found actuated control {control}"); }

    Properties

    Current

    Declaration
    public InputControl Current { get; }
    Property Value
    Type Description
    InputControl
    See Also
    EnumerateControls(InputEventPtr, Enumerate, InputDevice, float)
    EnumerateChangedControls(InputEventPtr, InputDevice, float)

    Methods

    Dispose()

    Declaration
    public void Dispose()
    See Also
    EnumerateControls(InputEventPtr, Enumerate, InputDevice, float)
    EnumerateChangedControls(InputEventPtr, InputDevice, float)

    MoveNext()

    Declaration
    public bool MoveNext()
    Returns
    Type Description
    bool
    See Also
    EnumerateControls(InputEventPtr, Enumerate, InputDevice, float)
    EnumerateChangedControls(InputEventPtr, InputDevice, float)

    Reset()

    Declaration
    public void Reset()
    See Also
    EnumerateControls(InputEventPtr, Enumerate, InputDevice, float)
    EnumerateChangedControls(InputEventPtr, InputDevice, float)

    Implements

    IEnumerator<T>
    IEnumerator
    IDisposable

    See Also

    EnumerateControls(InputEventPtr, Enumerate, InputDevice, float)
    EnumerateChangedControls(InputEventPtr, InputDevice, float)
    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)