Game.Input.SmoothFloatProcessor
Assembly:
Assembly-CSharp
Namespace:
Game.Input
Type:
class
Base:
SmoothProcessor
Summary:
SmoothFloatProcessor is a concrete implementation of SmoothProcessor for float values. It applies an exponential-style smoothing step to the incoming value using Mathf.Pow(m_Smoothing, delta) to compute the interpolation factor, then linearly interpolates between the current value and the stored last value. Very small results (below a tiny threshold) are snapped to zero to avoid floating-point noise. If the inherited m_Time flag is set, the result is scaled by Time.deltaTime before being returned. The processor updates lastValue to the smoothed (but pre-time-scaled) result so the next smoothing step uses the unscaled smoothed value.
Fields
-
private const float kDelta = 1E-06f
A small threshold used to snap values whose absolute magnitude falls below ~1e-6 to exactly 0. This helps prevent persistent tiny non-zero values due to floating-point noise. -
(Inherited)
protected float m_Smoothing
(Declared in SmoothProcessor) Controls how aggressive the smoothing is. When m_Smoothing > 0, smoothing is applied. Typical expected range is [0,1], but behavior follows Mathf.Pow(m_Smoothing, delta). -
(Inherited)
protected bool m_Time
(Declared in SmoothProcessor) When true, the returned value is multiplied by Time.deltaTime. Note lastValue is updated before this time-scaling.
Properties
- None declared on this type.
(Smoothing configuration and time-scaling flag are provided by the base SmoothProcessorclass via protected fields.)
Constructors
public SmoothFloatProcessor()
The default parameterless constructor is provided by the compiler. No explicit construction logic is present in this class.
Methods
protected override float Smooth(float value, ref float lastValue, float delta)
: System.Single
Applies the smoothing algorithm to a float input.
Behavior details: - If m_Smoothing > 0: - Computes t = Mathf.Pow(m_Smoothing, delta). - Interpolates value toward lastValue using Mathf.Lerp(value, lastValue, t). (Note: Lerp is called with (value, lastValue, t) so the result is value(1-t) + lastValuet, moving the returned value toward lastValue.) - If the absolute value of the result is less than kDelta (1e-6), the result is set to 0f. - Updates lastValue to the smoothed value (this update occurs before any time-scaling). - If m_Time is true, multiplies the returned value by Time.deltaTime. - Returns the final value.
Notes: - The delta parameter is the time step used to compute the smoothing factor (commonly a frame delta). - Because lastValue is assigned before time-scaling, stored state remains in unscaled units even when m_Time is enabled. - If m_Smoothing <= 0, smoothing is skipped and value is only zero-snapped, lastValue updated, and possibly time-scaled.
Usage Example
(The Smooth method is protected — the following is a conceptual/internal example showing the algorithm and typical usage context.)
// Conceptual/internal usage example:
float lastValue = 0f;
float rawInput = 1f;
float delta = Time.deltaTime;
var processor = new SmoothFloatProcessor();
// Assume m_Smoothing and m_Time are configured in the base class
// Internally (conceptual) the processor applies:
float smoothed = processor /* internally */ .Smooth(rawInput, ref lastValue, delta);
// After call:
// - lastValue contains the smoothed (pre-time-scaled) value
// - smoothed is the returned value (possibly scaled by Time.deltaTime if m_Time == true)
If you want to observe the effect in practice, call the smoothing routine from within the same class context (or the base type) where protected access is available, or use whatever public API the SmoothProcessor base class exposes for applying the processor in your input pipeline.