Mathd.Clamp for Unity 2020 support

This commit is contained in:
vis2k 2023-03-12 22:50:13 +08:00
parent 53658a5886
commit cae12a43fc

View File

@ -5,6 +5,16 @@ namespace Mirror
{ {
public static class Mathd public static class Mathd
{ {
// Unity 2020 doesn't have Math.Clamp yet.
/// <summary>Clamps value between 0 and 1 and returns value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static double Clamp(double value, double min, double max)
{
if (value < min) return min;
if (value > max) return max;
return value;
}
/// <summary>Clamps value between 0 and 1 and returns value.</summary> /// <summary>Clamps value between 0 and 1 and returns value.</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static double Clamp01(double value) public static double Clamp01(double value)