public static float SegmentProgress(ref Spline2DData spline, ref SplineProgress progress, int index) { if (index == 0) { return(progress.Progress / spline.Time[0]); } if (spline.Time.Length <= 1) { return(progress.Progress); } float aLn = spline.Time[index - 1]; float bLn = spline.Time[index]; return((progress.Progress - aLn) / (bLn - aLn)); }
public static float SegmentProgressClamp(ref Spline2DData spline, ref SplineProgress progress, int index) { float tempProgress = math.clamp(progress.Progress, 0f, 1f); if (index == 0) { return(tempProgress / spline.Time[0]); } if (spline.Time.Length <= 1) { return(tempProgress); } float aLn = spline.Time[index - 1]; float bLn = spline.Time[index]; return((tempProgress - aLn) / (bLn - aLn)); }
public static int SegmentIndex(ref Spline2DData spline, ref SplineProgress progress) { int seg = spline.Time.Length; for (int i = 0; i < seg; i++) { float time = spline.Time[i]; if (time >= progress.Progress) { return(i); } } #if UNITY_EDITOR && NO_BURST if (seg - 1 != Spline.Points.Length - 2) { // if the progress is greater than the spline time it should result in the last point being returned throw new IndexOutOfRangeException("Spline time has less data than expected for the requested point range!"); } #endif return(seg - 1); }