docs.unity3d.com
    Show / Hide Table of Contents

    Class InputProcessor<TValue>

    A processor that conditions/transforms input values.

    Inheritance
    Object
    InputProcessor
    InputProcessor<TValue>
    AxisDeadzoneProcessor
    ClampProcessor
    EditorWindowSpaceProcessor
    InvertProcessor
    InvertVector2Processor
    InvertVector3Processor
    NormalizeProcessor
    NormalizeVector2Processor
    NormalizeVector3Processor
    ScaleProcessor
    ScaleVector2Processor
    ScaleVector3Processor
    StickDeadzoneProcessor
    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.

    // 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(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.

    Process(Void*, Int32, InputControl)

    Declaration
    public override void Process(void *buffer, int bufferSize, InputControl control)
    Parameters
    Type Name Description
    Void* buffer
    Int32 bufferSize
    InputControl control
    Overrides
    InputProcessor.Process(Void*, Int32, InputControl)

    ProcessAsObject(Object, InputControl)

    Declaration
    public override object ProcessAsObject(object value, InputControl control)
    Parameters
    Type Name Description
    Object value
    InputControl control
    Returns
    Type Description
    Object
    Overrides
    InputProcessor.ProcessAsObject(Object, InputControl)

    See Also

    RegisterProcessor(Type, String)
    In This Article
    • Methods
      • Process(TValue, InputControl)
      • Process(Void*, Int32, InputControl)
      • ProcessAsObject(Object, InputControl)
    • See Also
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023