docs.unity3d.com
    Show / Hide Table of Contents

    Struct InputControlExtensions.InputEventControlEnumerator

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

    Namespace: UnityEngine.InputSystem
    Syntax
    public struct InputEventControlEnumerator : IEnumerator<InputControl>
    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

    Methods

    Dispose()

    Declaration
    public void Dispose()

    MoveNext()

    Declaration
    public bool MoveNext()
    Returns
    Type Description
    Boolean

    Reset()

    Declaration
    public void Reset()

    See Also

    EnumerateControls(InputEventPtr, InputControlExtensions.Enumerate, InputDevice, Single)
    EnumerateChangedControls(InputEventPtr, InputDevice, Single)
    In This Article
    • Properties
      • Current
    • Methods
      • Dispose()
      • MoveNext()
      • Reset()
    • See Also
    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