Class InputProcessor<TValue>
A processor that conditions/transforms input values.
Namespace: UnityEngine.InputSystem
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.
Examples
// 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;
}
Properties
valueType
Declaration
public override Type valueType { get; }
Property Value
Type | Description |
---|---|
System.Type |
Overrides
Methods
Process(TValue, InputControl<TValue>)
Process the given value and return the result.
Declaration
public abstract TValue Process(TValue value, InputControl<TValue> control)
Parameters
Type | Name | Description |
---|---|---|
TValue | value | Input value to process. |
InputControl<TValue> | 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.
Process(Void*, Int32, InputControl)
Declaration
public override void Process(void *buffer, int bufferSize, InputControl control)
Parameters
Type | Name | Description |
---|---|---|
System.Void* | buffer | |
System.Int32 | bufferSize | |
InputControl | control |
Overrides
ProcessAsObject(Object, InputControl)
Declaration
public override object ProcessAsObject(object value, InputControl control)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value | |
InputControl | control |
Returns
Type | Description |
---|---|
System.Object |