// Animancer // https://kybernetik.com.au/animancer // Copyright 2018-2023 Kybernetik // using UnityEngine; namespace Animancer { /// https://kybernetik.com.au/animancer/api/Animancer/ControllerState partial class ControllerState { /************************************************************************************************************************/ /// /// A wrapper for to control float /// parameters in s similar to /// . /// public class DampedFloatParameter { /************************************************************************************************************************/ /// The name of this parameter. public ParameterID parameter; /// The amount of time allowed to smooth out a value change. public float smoothTime; /// The last value the parameter was set to. public float currentValue; /// The value that the parameter is moving towards. public float targetValue; /// The maximum speed that the current value can move towards the target. public float maxSpeed; /// The speed at which the value is currently moving. public float velocity; /************************************************************************************************************************/ /// Creates a new . public DampedFloatParameter( ParameterID parameter, float smoothTime, float defaultValue = 0, float maxSpeed = float.PositiveInfinity) { this.parameter = parameter; this.smoothTime = smoothTime; currentValue = targetValue = defaultValue; this.maxSpeed = maxSpeed; } /************************************************************************************************************************/ /// Updates the target parameter. public void Apply(ControllerState controller) => Apply(controller, UnityEngine.Time.deltaTime); /// Updates the target parameter. public void Apply(ControllerState controller, float deltaTime) { currentValue = Mathf.SmoothDamp(currentValue, targetValue, ref velocity, smoothTime, maxSpeed, deltaTime); controller.SetFloat(parameter, currentValue); } /************************************************************************************************************************/ } /************************************************************************************************************************/ } }