Add processors to controls
You can have any number of Processors directly on an InputControl, which then process the values read from the Control. Whenever you call ReadValue on a Control, all Processors on that Control process the value before it gets returned to you. You can use ReadUnprocessedValue on a Control to bypass the Processors.
The Input System adds Processors to a Control during device creation, if they're specified in the Control's layout. You can't add Processors to existing Controls after they've been created, so you can only add Processors to Controls when you're creating custom devices. The devices that the Input System supports out of the box already have some useful Processors added on their Controls. For instance, sticks on gamepads have a Stick Deadzone Processor.
If you're using a layout generated by the Input System from a state struct using InputControlAttributes, you can specify the Processors you want to use with the processors property of the attribute, like this:
/// <summary>
/// Example state struct for a custom device with a single deadzoned axis control.
/// </summary>
public struct MyDeviceState : IInputStateTypeInfo
{
/// <summary>
/// The memory format identifier for this state struct.
/// </summary>
public FourCC format => new FourCC('M', 'Y', 'D', 'V');
// Add an axis deadzone to the Control to ignore values
// smaller then 0.2, as our Control does not have a stable
// resting position.
/// <summary>
/// The axis control's raw value.
/// </summary>
[InputControl(layout = "Axis", processors = "AxisDeadzone(min=0.2)")]
public short axis;
}
If you create a layout from JSON, you can specify Processors on your Controls like this:
{
"name" : "MyDevice",
"extend" : "Gamepad",
"controls" : [
{
"name" : "axis",
"layout" : "Axis",
"offset" : 4,
"format" : "FLT",
"processors" : "AxisDeadzone(min=0.2)"
}
]
}
This example extends the Gamepad layout, but you can extend any existing layout.