Struct InputControlExtensions.InputEventControlEnumerator
Iterates over the controls in a State
Namespace: UnityEngine .InputSystem
Assembly: Unity.InputSystem.dll
Syntax
public struct InputControlExtensions.InputEventControlEnumerator : IEnumerator<InputControl>, IEnumerator, IDisposable
Remarks
One problem with state events (that is, State
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 ");
}
Properties
Current
Declaration
public InputControl Current { get; }
Property Value
Type | Description |
---|---|
Input |
See Also
Methods
Dispose()
Declaration
public void Dispose()
See Also
MoveNext()
Declaration
public bool MoveNext()
Returns
Type | Description |
---|---|
bool |
See Also
Reset()
Declaration
public void Reset()