Advertisement
Pro_Unit

Range And Curve Extensions

Sep 1st, 2023
940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1.     public static bool InRange(this float current, float min, float max) => current >= min && current <= max;
  2.  
  3.     public static bool InRange(this int current, float min, float max) => current >= min && current <= max;
  4.  
  5.     public static RangeFloat AsRange(this float max) => new(0f, max);
  6.  
  7.     public static RangeFloat AsRange(this float min, float max) => new(min, max);
  8.  
  9.     public static RangeInt AsRange(this int max) => new(0, max);
  10.    
  11.     public static RangeInt AsRange(this int min, int max) => new(min, max);
  12.    
  13.     public static Keyframe First(this AnimationCurve curve) => curve[0];
  14.     public static Keyframe Last(this AnimationCurve curve) => curve[curve.length - 1];
  15.    
  16.     public static bool InRange(this AnimationCurve curve, float time)
  17.     {
  18.         if (curve == null || curve.length == 0 )
  19.             return false;
  20.        
  21.         Keyframe first = curve.First();
  22.         Keyframe last = curve.Last();
  23.        
  24.         return time.InRange(first.time, last.time);
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement