// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) VRMADA, All rights reserved. // // -------------------------------------------------------------------------------------------------------------------- using UnityEngine; namespace UltimateXR.Animation.Interpolation { /// /// Base for interpolator classes that interpolate with optional smooth damping. /// Child classes provide interpolation for different variable types. /// public abstract class UxrVarInterpolator { #region Public Types & Data /// /// Gets whether to always return the first variable when interpolating. /// public bool UseStep { get; set; } /// /// Gets or sets the smoothing value [0.0, 1.0]. 0 means no smoothing. /// public float SmoothDamp { get => _smoothDamp; set => _smoothDamp = Mathf.Clamp01(value); } #endregion #region Constructors & Finalizer /// /// Constructor. /// /// Smooth damp value [0.0, 1.0] /// Whether to use step interpolation, where the interpolation will always return the start value protected UxrVarInterpolator(float smoothDamp = 0.0f, bool useStep = false) { SmoothDamp = smoothDamp; UseStep = useStep; } #endregion #region Public Methods /// /// Interpolates between 2 values. /// /// Start value /// End value /// Interpolation factor [0.0, 1.0] /// Interpolated value /// /// The interpolated value will be affected by smoothing if the object was initialized with a smoothDamp value /// greater than 0. /// public abstract object Interpolate(object a, object b, float t); /// /// Resets the "memory" of the smooth damp effect, so that the interpolation will restart from the next time /// is called. /// public void RestartSmoothDamp() { RequiresSmoothDampRestart = true; } #endregion #region Protected Methods /// /// Clears the smooth damp restart variable. /// protected void ClearSmoothDampRestart() { RequiresSmoothDampRestart = false; } #endregion #region Protected Types & Data /// /// Gets whether the smooth damp needs to be restarted the next time is called. /// protected bool RequiresSmoothDampRestart { get; private set; } #endregion #region Private Types & Data private float _smoothDamp; #endregion } }