Class InputStateHistory<TValue>
Records value changes of a given control over time.
Implements
Inherited Members
Namespace: UnityEngine .InputSystem .LowLevel
Assembly: Unity.InputSystem.dll
Syntax
public class InputStateHistory<TValue> : InputStateHistory, IDisposable, IEnumerable<InputStateHistory.Record>, IInputStateChangeMonitor, IReadOnlyList<InputStateHistory<TValue>.Record>, IReadOnlyCollection<InputStateHistory<TValue>.Record>, IEnumerable<InputStateHistory<TValue>.Record>, IEnumerable where TValue : struct
Type Parameters
Name | Description |
---|---|
TValue | The type of the record being stored |
Remarks
This class makes it easy to track input values over time. It will automatically retain input state up to a given
maximum history depth (history
The class listens to changes on the given controls by adding change monitors (IInput
Constructors
InputStateHistory(int?)
Creates a new InputStateHistory class to record all control state changes.
Declaration
public InputStateHistory(int? maxStateSizeInBytes = null)
Parameters
Type | Name | Description |
---|---|---|
int? | maxStateSizeInBytes | Maximum size of control state in the record entries. Controls with larger state will not be recorded. |
Remarks
Creates a new InputStateHistory to record a history of control state changes.
New controls are automatically added into the state history if there state is smaller than the threshold.
InputStateHistory(string)
Creates a new InputStateHistory class to record state changes for a specified control.
Declaration
public InputStateHistory(string path)
Parameters
Type | Name | Description |
---|---|---|
string | path | Control path to identify which controls to monitor. |
Remarks
Creates a new InputStateHistory to record a history of state changes for the specified controls.
Examples
// Track all stick controls in the system.
var history = new InputStateHistory<Vector2>("*/<Stick>");
InputStateHistory(InputControl<TValue>)
Creates a new InputStateHistory class to record state changes for a specified control.
Declaration
public InputStateHistory(InputControl<TValue> control)
Parameters
Type | Name | Description |
---|---|---|
Input |
control | Control to monitor. |
Remarks
Creates a new InputStateHistory to record a history of state changes for the specified control.
Properties
this[int]
Returns an entry in the state history at the given index.
Declaration
public InputStateHistory<TValue>.Record this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
int | index | Index into the array. |
Property Value
Type | Description |
---|---|
Input |
Remarks
Returns a Input
Exceptions
Type | Condition |
---|---|
Index |
|
Methods
AddRecord(Record)
Add a record to the input state history.
Declaration
public InputStateHistory<TValue>.Record AddRecord(InputStateHistory<TValue>.Record record)
Parameters
Type | Name | Description |
---|---|---|
Input |
record | Record to add. |
Returns
Type | Description |
---|---|
Input |
The newly added record from the history array (as a copy is made). |
Remarks
Add a record to the input state history. Allocates an entry in the history array and returns this copy of the original data passed to the function.
~InputStateHistory()
InputStateHistory destructor.
Declaration
protected ~InputStateHistory()
GetEnumerator()
Enumerate all state history records.
Declaration
public IEnumerator<InputStateHistory<TValue>.Record> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<Input |
An enumerator going over the state history records. |
Remarks
Enumerate all state history records.
See Also
RecordStateChange(InputControl<TValue>, TValue, double)
Record a state change for a specific control.
Declaration
public InputStateHistory<TValue>.Record RecordStateChange(InputControl<TValue> control, TValue value, double time = -1)
Parameters
Type | Name | Description |
---|---|---|
Input |
control | The control to record the state change for. |
TValue | value | The value to record. |
double | time | Time stamp to apply (overriding the event timestamp) |
Returns
Type | Description |
---|---|
Input |
The newly added record. |
Remarks
Record a state change for a specific control.
Will call the on
Examples
using (var allTouchTaps = new InputStateHistory<float>(Gamepad.current.leftTrigger))
{
history.RecordStateChange(Gamepad.current.leftTrigger, 0.234f);
}