Struct StateEvent
A complete state snapshot for an entire input device.
Namespace: UnityEngine.InputSystem.LowLevel
Syntax
public struct StateEvent : IInputEventTypeInfo
Remarks
This is a variable-sized event.
Fields
baseEvent
Declaration
public InputEvent baseEvent
Field Value
| Type | Description |
|---|---|
| InputEvent |
stateFormat
Type code for the state stored in the event.
Declaration
public FourCC stateFormat
Field Value
| Type | Description |
|---|---|
| FourCC |
Type
Declaration
public const int Type = 1398030676
Field Value
| Type | Description |
|---|---|
| Int32 |
Properties
state
Declaration
public readonly void *state { get; }
Property Value
| Type | Description |
|---|---|
| Void* |
stateSizeInBytes
Declaration
public readonly uint stateSizeInBytes { get; }
Property Value
| Type | Description |
|---|---|
| UInt32 |
typeStatic
Declaration
public readonly FourCC typeStatic { get; }
Property Value
| Type | Description |
|---|---|
| FourCC |
Implements
Methods
From(InputDevice, out InputEventPtr, Allocator)
Read the current state of device and create a state event from it.
Declaration
public static NativeArray<byte> From(InputDevice device, out InputEventPtr eventPtr, Allocator allocator = Allocator.Temp)
Parameters
| Type | Name | Description |
|---|---|---|
| InputDevice | device | Device to grab the state from. Must be a device that has been added to the system. |
| InputEventPtr | eventPtr | Receives a pointer to the newly created state event. |
| Allocator | allocator | Which native allocator to allocate memory for the event from. By default, the buffer is allocated as temporary memory (Temp. Note that this means the buffer will not be valid past the current frame. Use Persistent if the buffer for the state event is meant to persist for longer. |
Returns
| Type | Description |
|---|---|
| NativeArray<Byte> | Buffer of unmanaged memory allocated for the event. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
| ArgumentNullException |
|
From(InputEventPtr)
Return the given InputEventPtr as a StateEvent pointer.
Declaration
public static StateEvent*From(InputEventPtr ptr)
Parameters
| Type | Name | Description |
|---|---|---|
| InputEventPtr | ptr | A pointer to an input event. The pointer is checked for |
Returns
| Type | Description |
|---|---|
| StateEvent* | Pointer |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| InvalidCastException |
|
FromDefaultStateFor(InputDevice, out InputEventPtr, Allocator)
Create a state event for the given device and copy the default state of the device
into the event.
Declaration
public static NativeArray<byte> FromDefaultStateFor(InputDevice device, out InputEventPtr eventPtr, Allocator allocator = Allocator.Temp)
Parameters
| Type | Name | Description |
|---|---|---|
| InputDevice | device | Device to create a state event for. Must be a device that has been added to the system. |
| InputEventPtr | eventPtr | Receives a pointer to the newly created state event. |
| Allocator | allocator | Which native allocator to allocate memory for the event from. By default, the buffer is allocated as temporary memory (Temp. Note that this means the buffer will not be valid past the current frame. Use Persistent if the buffer for the state event is meant to persist for longer. |
Returns
| Type | Description |
|---|---|
| NativeArray<Byte> | Buffer of unmanaged memory allocated for the event. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
| ArgumentNullException |
|
GetEventSizeWithPayload<TState>()
Declaration
public static int GetEventSizeWithPayload<TState>()
where TState : struct
Returns
| Type | Description |
|---|---|
| Int32 |
Type Parameters
| Name | Description |
|---|---|
| TState |
GetState<TState>()
Retrieve the state stored in the event.
Declaration
public TState GetState<TState>()
where TState : struct, IInputStateTypeInfo
Returns
| Type | Description |
|---|---|
| TState | Copy of the state stored in the event. |
Type Parameters
| Name | Description |
|---|---|
| TState | Type of state expected to be stored in the event. format must match stateFormat. |
Remarks
The event may contain less or more data than what is found in the struct. Only the data found in the event is copied. The remainder of the struct is left at default values.
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | stateFormat does not match format
of |
See Also
GetState<TState>(InputEventPtr)
Retrieve the state stored in the event.
Declaration
public static TState GetState<TState>(InputEventPtr ptr)
where TState : struct, IInputStateTypeInfo
Parameters
| Type | Name | Description |
|---|---|---|
| InputEventPtr | ptr | A pointer to an input event. The pointer is checked for |
Returns
| Type | Description |
|---|---|
| TState | Copy of the state stored in the event. |
Type Parameters
| Name | Description |
|---|---|
| TState | Type of state expected to be stored in the event. format must match stateFormat. |
Remarks
The event may contain less or more data than what is found in the struct. Only the data found in the event is copied. The remainder of the struct is left at default values.
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | stateFormat does not match format
of |
| ArgumentNullException |
|
| InvalidCastException |
|
See Also
ToEventPtr()
Declaration
public InputEventPtr ToEventPtr()
Returns
| Type | Description |
|---|---|
| InputEventPtr |