public Vector3 GetClosestPoint(Vector3 p, ref int closestSeg, out float distance, int searchRange = 5, int subdivisions = 50)
        {
            distance = float.MaxValue;
            Vector3 result = p;

            if (nodes.Length > 1)
            {
                int num  = Mathf.Max(closestSeg - searchRange, 1);
                int num2 = Mathf.Min(closestSeg + searchRange, nodes.Length - 1);
                for (int i = num; i <= num2; i++)
                {
                    Transform transform  = nodes[i - 1].transform;
                    Transform transform2 = nodes[i].transform;
                    Vector3   position   = transform.position;
                    Vector3   p2         = transform.position + transform.forward * nodes[i - 1].OutHandleLength;
                    Vector3   p3         = transform2.position - transform2.forward * nodes[i].InHandleLength;
                    Vector3   position2  = transform2.position;
                    float     distance2;
                    Vector3   vector = BezierMath.FindClosest(position, p2, p3, position2, p, out distance2, subdivisions);
                    if (distance2 < distance)
                    {
                        distance   = distance2;
                        result     = vector;
                        closestSeg = i;
                    }
                }
            }
            return(result);
        }
        public float EstimateSegmentLength(int segment, int subdivisions = 50)
        {
            float num = 0f;

            Debug.Assert(nodes.Length > segment, "Invalid segment number.");
            SmoothBezierNode smoothBezierNode  = nodes[segment];
            SmoothBezierNode smoothBezierNode2 = nodes[segment + 1];
            Transform        transform         = smoothBezierNode.transform;
            Transform        transform2        = smoothBezierNode2.transform;
            Vector3          position          = transform.position;
            Vector3          p         = transform.position + transform.forward * smoothBezierNode.OutHandleLength;
            Vector3          p2        = transform2.position - transform2.forward * smoothBezierNode2.InHandleLength;
            Vector3          position2 = transform2.position;
            Vector3          zero      = Vector3.zero;
            Vector3          vector    = BezierMath.Interpolate(position, p, p2, position2, 0f);
            float            num2      = 1f / (float)subdivisions;

            for (int i = 0; i < subdivisions; i++)
            {
                zero   = vector;
                vector = BezierMath.Interpolate(position, p, p2, position2, num2 * (float)(i + 1));
                num   += Vector3.Distance(zero, vector);
            }
            return(num);
        }
        public Vector3 InterpolateSegment(int segment, float u)
        {
            Debug.Assert(nodes.Length > segment, "Invalid segment number.");
            SmoothBezierNode smoothBezierNode  = nodes[segment];
            SmoothBezierNode smoothBezierNode2 = nodes[segment + 1];
            Transform        transform         = smoothBezierNode.transform;
            Transform        transform2        = smoothBezierNode2.transform;
            Vector3          position          = transform.position;
            Vector3          p         = transform.position + transform.forward * smoothBezierNode.OutHandleLength;
            Vector3          p2        = transform2.position - transform2.forward * smoothBezierNode2.InHandleLength;
            Vector3          position2 = transform2.position;

            return(BezierMath.Interpolate(position, p, p2, position2, u));
        }