Class InputProcessor<TValue>
A processor that conditions/transforms input values.
Inherited Members
Namespace: UnityEngine.InputSystem
Assembly: Unity.InputSystem.dll
Syntax
public abstract class InputProcessor<TValue> : InputProcessor where TValue : struct
Type Parameters
Name | Description |
---|---|
TValue | Type of value to be processed. Only InputControls that use the same value type will be compatible with the processor. |
Remarks
Each InputControl can have a stack of processors assigned to it.
Note that processors CANNOT be stateful. If you need processing that requires keeping mutating state over time, use InputActions. All mutable state needs to be kept in the central state buffers.
However, processors can have configurable parameters. Every public field on a processor object can be set using "parameters" in JSON or by supplying parameters through the processors field.
// To register the processor, call
//
// InputSystem.RegisterProcessor<ScalingProcessor>("scale");
//
public class ScalingProcessor : InputProcessor<float>
{
// This field can be set as a parameter. See examples below.
// If not explicitly configured, will have its default value.
public float factor = 2.0f;
public float Process(float value, InputControl control)
{
return value * factor;
}
}
// Use processor in JSON:
const string json = @"
{
""name"" : ""MyDevice"",
""controls"" : [
{ ""name"" : ""axis"", ""layout"" : ""Axis"", ""processors"" : ""scale(factor=4)"" }
]
}
";
// Use processor on C# state struct:
public struct MyDeviceState : IInputStateTypeInfo
{
[InputControl(layout = "Axis", processors = "scale(factor=4)"]
public float axis;
}
See InputParameterEditor<TObject> for how to define custom parameter editing UIs for processors.
Methods
Process(void*, int, InputControl)
Process an input value stored in the given memory buffer.
Declaration
public override void Process(void* buffer, int bufferSize, InputControl control)
Parameters
Type | Name | Description |
---|---|---|
void* | buffer | Memory buffer containing the input value. Must be at least large enough
to hold one full value as indicated by |
int | bufferSize | Size (in bytes) of the value inside |
InputControl | control | Optional control that the value originated from. Must have the same value type that the processor has. |
Overrides
Remarks
This method allows processing values of arbitrary size without allocating memory on the GC heap.
See Also
Process(TValue, InputControl)
Process the given value and return the result.
Declaration
public abstract TValue Process(TValue value, InputControl control)
Parameters
Type | Name | Description |
---|---|---|
TValue | value | Input value to process. |
InputControl | control | Control that the value originally came from. This can be null if the value did not originate from a control. This can be the case, for example, if the processor sits on a composite binding (InputBindingComposite) as composites are not directly associated with controls but rather source their values through their child bindings. |
Returns
Type | Description |
---|---|
TValue | Processed input value. |
Remarks
The implementation of this method must not be stateful.
See Also
ProcessAsObject(object, InputControl)
Process an input value, given as an object, and return the processed value as an object.
Declaration
public override object ProcessAsObject(object value, InputControl control)
Parameters
Type | Name | Description |
---|---|---|
object | value | A value matching the processor's value type. |
InputControl | control | Optional control that the value originated from. Must have the same value type that the processor has. |
Returns
Type | Description |
---|---|
object | A processed value based on |
Overrides
Remarks
This method allocates GC heap memory. To process values without allocating GC memory, it is necessary to either know the value type of a processor at compile time and call Process(TValue, InputControl) directly or to use Process(void*, int, InputControl) instead and process values in raw memory buffers.