Skip to main content

LerpingFloatValue

A class in Root.Township, Alta.Utilities.

Helper that moves a float towards a target over time and pushes each new value to a setter. You call Update every frame yourself.

Constructors​

MemberWhat it is
LerpingFloatValue(Action<float> setValue)Creates a LerpingFloatValue from setValue.

Fields​

6 private and internal fields
MemberWhat it is
private float currentValue most recently pushed to the setter.
private Func<float> getTargetFunction giving the target, read each update so the target can move. Cleared when the lerp ends.
private float initialValue the current lerp started from.
private float lerpSpeedSeconds a full lerp takes (despite the name). Set by the Lerp(target, speed) overload.
private float progressLerp progress from 0 to 1.
private Action<float> setValueCallback that receives each new value.

Properties​

MemberWhat it is
float Current { get; }The value last pushed to the setter.
bool IsLerping { get; private set; }True while a lerp is running.

Events​

MemberWhat it is
event Action FinishedLerpFired when a lerp reaches its target.

Methods​

MemberWhat it is
void Kill()Stops the lerp where it is.
void Lerp(float target, float lerpSpeed)Starts a lerp from Current to a fixed or changing target. lerpSpeed is really the duration in seconds; the function overload reuses the last one.
void Lerp(Func<float> getTarget)Starts a lerp from Current to a fixed or changing target. lerpSpeed is really the duration in seconds; the function overload reuses the last one.
void Snap(float newTarget)Jumps straight to the value and stops any lerp.
void SnapIfNotLerping(float newTarget)Snaps only if no lerp is running.
void Update()Advances the lerp by Time.deltaTime and pushes the new value.
protected float Lerp(float initial, float target, float progress)Starts a lerp from Current to a fixed or changing target. lerpSpeed is really the duration in seconds; the function overload reuses the last one.

Used in​

Members of other types that take, return or hold a LerpingFloatValue: