Math.cs 786 B

123456789101112131415161718192021222324252627
  1. using UnityEngine;
  2. using UnityEngine.Assertions;
  3. namespace UnityUIPlayables
  4. {
  5. internal static class Math
  6. {
  7. /// <summary>
  8. /// The Mathf.Repeat function in Unity returns zero when it hits the boundary value.
  9. /// This method returns the larger value.
  10. /// </summary>
  11. /// <param name="value"></param>
  12. /// <param name="length"></param>
  13. /// <returns></returns>
  14. public static float RepeatWithLargerBoundaryValue(float value, float length)
  15. {
  16. Assert.IsTrue(value >= 0);
  17. Assert.IsTrue(length > 0);
  18. if (value == 0.0f)
  19. return 0.0f;
  20. var result = Mathf.Repeat(value, length);
  21. return result == 0.0f ? length : result;
  22. }
  23. }
  24. }