unity C# Mathf类源码

梦想游戏人
目录:
Unity

从 变量命名和大量的goto可以看出 大部分源码看似是自动生成的,也可能是反编译工具的问题

1.Repeat

  • public static float Repeat(float t, float length)
  • {
  • return (t - (Floor(t / length) * length));
  • }
    public static float Repeat(float t, float length)
        {
            return (t - (Floor(t / length) * length));
        }

大部分可用整除%替代(C#整除支持float double)

2.Clamp

  • public static int Clamp(int value, int min, int max)
  • {
  • if (value >= min)
  • {
  • goto Label_000F;
  • }
  • value = min;
  • goto Label_0019;
  • Label_000F:
  • if (value <= max)
  • {
  • goto Label_0019;
  • }
  • value = max;
  • Label_0019:
  • return value;
  • }
     public static int Clamp(int value, int min, int max)
        {
            if (value >= min)
            {
                goto Label_000F;
            }
            value = min;
            goto Label_0019;
        Label_000F:
            if (value <= max)
            {
                goto Label_0019;
            }
            value = max;
        Label_0019:
            return value;
        }

3.Lerp,Linearly interpolates between a and b by t.

  • public static float Lerp(float a, float b, float t)
  • {
  • return (a + ((b - a) * Clamp01(t)));
  • }
 public static float Lerp(float a, float b, float t)
        {
            return (a + ((b - a) * Clamp01(t)));
        }
Scroll Up