fix: Add Clamp extension for pre-Unity 2021

This commit is contained in:
MrGadget1024 2023-03-12 09:27:43 -04:00
parent 53658a5886
commit 98b8227a63
2 changed files with 12 additions and 0 deletions

View File

@ -130,7 +130,11 @@ public static double TimelineClamp(
// outside of the area, we clamp.
double lowerBound = targetTime - bufferTime;
double upperBound = targetTime + bufferTime;
#if !UNITY_2021_OR_NEWER
return Extensions.Clamp(localTimeline, lowerBound, upperBound);
#else
return Math.Clamp(localTimeline, lowerBound, upperBound);
#endif
}
// call this for every received snapshot.

View File

@ -59,6 +59,14 @@ public static bool TryDequeue<T>(this Queue<T> source, out T element)
element = default;
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
{
if (val.CompareTo(min) < 0) return min;
else if (val.CompareTo(max) > 0) return max;
else return val;
}
#endif
}
}