Exemple #1
0
        public static float SegmentProgressClamp(ref Spline3DData 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));
        }
Exemple #2
0
        public static int SegmentIndex(ref Spline3DData 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);
        }