Search Results for

    Show / Hide Table of Contents

    Class LerpValue<T>

    A generic class for managing and interpolating a value towards a target value over time.

    Inheritance
    System.Object
    LerpValue<T>
    Inherited Members
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    Namespace: UniUtils.Data
    Assembly: cs.temp.dll.dll
    Syntax
    public sealed class LerpValue<T>
    Type Parameters
    Name Description
    T

    The type of the value to interpolate.

    Examples
    using UnityEngine;
    
    public class ExampleUsage : MonoBehaviour
    {
        private LerpValue<float> lerpAlpha;
    
        void Start()
        {
            // Start with 0, use Mathf.Lerp, and set speed to 2
            lerpAlpha = new LerpValue<float>(0f, Mathf.Lerp, 2f);
            lerpAlpha.SetTarget(1f); // Targeting full alpha
        }
    
        void Update()
        {
            lerpAlpha.Update(Time.deltaTime);
            float currentAlpha = lerpAlpha.Value;
            // Use currentAlpha for fading UI, etc.
        }
    }

    Constructors

    LerpValue(T, Func<T, T, Single, T>, Single)

    Initializes a new instance of the LerpValue<T> class.

    Declaration
    public LerpValue(T initialValue, Func<T, T, float, T> lerpFunction, float speed = 5F)
    Parameters
    Type Name Description
    T initialValue

    The initial value of the interpolation.

    Func<T, T, System.Single, T> lerpFunction

    The interpolation function to use.

    System.Single speed

    The speed of interpolation (default is 5f).

    Exceptions
    Type Condition
    System.ArgumentNullException

    Thrown if lerpFunction is null.

    Properties

    LerpSpeed

    Gets the speed at which the value interpolates towards the target.

    Declaration
    public float LerpSpeed { get; }
    Property Value
    Type Description
    System.Single

    The speed of interpolation.

    Target

    Gets the target value.

    Declaration
    public T Target { get; }
    Property Value
    Type Description
    T

    The target value.

    Value

    Gets the current interpolated value.

    Declaration
    public T Value { get; }
    Property Value
    Type Description
    T

    The current value.

    Methods

    ForceSet(T)

    Immediately sets the current and target values to a specified value.

    Declaration
    public void ForceSet(T newValue)
    Parameters
    Type Name Description
    T newValue

    The value to set.

    SetLerpSpeed(Single)

    Sets the speed at which the value interpolates towards the target.

    Declaration
    public void SetLerpSpeed(float newSpeed)
    Parameters
    Type Name Description
    System.Single newSpeed

    The new interpolation speed.

    SetTarget(T)

    Sets a new target value for interpolation.

    Declaration
    public void SetTarget(T newTarget)
    Parameters
    Type Name Description
    T newTarget

    The new target value.

    Update(Single)

    Updates the current value by interpolating towards the target value.

    Declaration
    public void Update(float deltaTime)
    Parameters
    Type Name Description
    System.Single deltaTime

    The time elapsed since the last update.

    In This Article
    Back to top UniUtils Documentation