using System;
using System.Collections.Generic;
using UnityEngine;
namespace OM
{
///
/// Provides static helper methods for working with the EasingFunction-related enums.
/// Primarily facilitates iterating through the different categories of easing functions (All, Idle, PingPong)
/// and includes convenience wrappers for Unity's unclamped Lerp functions.
///
public static class EasingHelper
{
// --- Cached Enum Value Lists ---
// These lists store the results of Enum.GetValues to avoid repeated reflection calls,
// improving performance when iterating through the enums multiple times.
/// Cached list of all values from the main EasingFunction enum.
private static List _easingFunctions;
/// Cached list of all values from the EasingFunctionPingPong enum.
private static List _easingFunctionsPingPong;
/// Cached list of all values from the EasingFunctionIdle enum.
private static List _easingFunctionsIdle;
// --- Enum Iteration Methods ---
///
/// Returns an enumerable collection of all values defined in the main EasingFunction enum.
/// Caches the result on the first call for subsequent efficiency.
///
/// An IEnumerable containing all EasingFunction enum values.
public static IEnumerable LoopThroughEasingFunctions()
{
// If the list is already populated, return the cached version.
if (_easingFunctions != null && _easingFunctions.Count != 0) return _easingFunctions;
// If not cached, create the list and populate it using reflection.
_easingFunctions = new List();
foreach (EasingFunction easingFunction in Enum.GetValues(typeof(EasingFunction)))
{
_easingFunctions.Add(easingFunction);
}
return _easingFunctions;
}
///
/// Returns an enumerable collection of all values defined in the EasingFunctionPingPong enum.
/// Caches the result on the first call for subsequent efficiency.
///
/// An IEnumerable containing all EasingFunctionPingPong enum values.
public static IEnumerable LoopThroughEasingFunctionsPingPong()
{
// Use cached list if available.
if (_easingFunctionsPingPong != null && _easingFunctionsPingPong.Count != 0) return _easingFunctionsPingPong;
// Create and populate the list on first call.
_easingFunctionsPingPong = new List();
foreach (EasingFunctionPingPong easingFunction in Enum.GetValues(typeof(EasingFunctionPingPong)))
{
_easingFunctionsPingPong.Add(easingFunction);
}
return _easingFunctionsPingPong;
}
///
/// Returns an enumerable collection of all values defined in the EasingFunctionIdle enum (non-PingPong functions).
/// Caches the result on the first call for subsequent efficiency.
///
/// An IEnumerable containing all EasingFunctionIdle enum values.
public static IEnumerable LoopThroughEasingFunctionsIdle()
{
// Use cached list if available.
if (_easingFunctionsIdle != null && _easingFunctionsIdle.Count != 0) return _easingFunctionsIdle;
// Create and populate the list on first call.
_easingFunctionsIdle = new List();
foreach (EasingFunctionIdle easingFunction in Enum.GetValues(typeof(EasingFunctionIdle)))
{
_easingFunctionsIdle.Add(easingFunction);
}
return _easingFunctionsIdle;
}
// --- Unclamped Lerp Wrappers ---
// These methods simply provide a consistent "Lerp" name while calling the
// corresponding "LerpUnclamped" methods from Unity. Unclamped versions allow
// the interpolation factor 't' to go outside the 0-1 range, which can be useful
// for effects like overshoot when combined with certain easing functions (though
// the main EaseData.Evaluate method usually clamps 't' beforehand).
/// Performs linear interpolation between two Vector2 values without clamping the factor 't'.
/// Start value. End value. Interpolation factor. Interpolated Vector2.
public static Vector2 Lerp(Vector2 a, Vector2 b, float t)
{
return Vector2.LerpUnclamped(a, b, t);
}
/// Performs linear interpolation between two Vector3 values without clamping the factor 't'.
/// Start value. End value. Interpolation factor. Interpolated Vector3.
public static Vector3 Lerp(Vector3 a, Vector3 b, float t)
{
return Vector3.LerpUnclamped(a, b, t);
}
/// Performs linear interpolation between two Quaternion values without clamping the factor 't'.
/// Start value. End value. Interpolation factor. Interpolated Quaternion.
public static Quaternion Lerp(Quaternion a, Quaternion b, float t)
{
return Quaternion.LerpUnclamped(a, b, t);
}
/// Performs linear interpolation between two Color values without clamping the factor 't'.
/// Start value. End value. Interpolation factor. Interpolated Color.
public static Color Lerp(Color a, Color b, float t)
{
return Color.LerpUnclamped(a, b, t);
}
/// Performs linear interpolation between two float values without clamping the factor 't'.
/// Start value. End value. Interpolation factor. Interpolated float.
public static float Lerp(float a, float b, float t)
{
return Mathf.LerpUnclamped(a, b, t);
}
/// Performs linear interpolation between two angles (in degrees) correctly handling wrapping. Uses Mathf.LerpAngle.
/// Start angle (degrees). End angle (degrees). Interpolation factor (clamped 0-1 by LerpAngle). Interpolated angle (degrees).
public static float LerpAngle(float a, float b, float t)
{
// Note: Mathf.LerpAngle inherently clamps 't' between 0 and 1.
return Mathf.LerpAngle(a, b, t);
}
/// Performs linear interpolation between two Vector4 values without clamping the factor 't'.
/// Start value. End value. Interpolation factor. Interpolated Vector4.
public static Vector4 Lerp(Vector4 a, Vector4 b, float t)
{
return Vector4.LerpUnclamped(a, b, t);
}
/// Performs linear interpolation between two Bounds values by interpolating their centers and sizes.
/// Start Bounds. End Bounds. Interpolation factor. Interpolated Bounds.
public static Bounds Lerp(Bounds a, Bounds b, float t)
{
// Interpolate center and size separately using the Vector3 Lerp wrapper.
return new Bounds(Lerp(a.center, b.center, t),
Lerp(a.size, b.size, t));
}
/// Performs linear interpolation between two Rect values by interpolating their positions and sizes.
/// Start Rect. End Rect. Interpolation factor. Interpolated Rect.
public static Rect Lerp(Rect a, Rect b, float t)
{
// Interpolate position and size separately using the Vector2 Lerp wrapper.
return new Rect(Lerp(a.position, b.position, t),
Lerp(a.size, b.size, t));
}
}
}