示例#1
0
        void ApplyOffset()
        {
            if (isEngine)
            {
                ResetSegments();
                return;
            }
            float  totalMoved = 0f, moved = 0f;
            double start = front.tracer.UnclipPercent(front.tracer.result.percent);

            //Travel backwards along the front wagon's spline
            Spline.Direction inverseDirection = front.segment.direction;
            InvertDirection(ref inverseDirection);
            SplineComputer spline  = front.segment.spline;
            double         percent = front.segment.Travel(start, offset, inverseDirection, out moved, front.segment.spline.isClosed);

            totalMoved += moved;
            //Finalize if moved fully without reaching a spline end or a junction
            if (Mathf.Approximately(totalMoved, offset))
            {
                if (segment != front.segment)
                {
                    if (back != null)
                    {
                        back.segment = segment;
                    }
                }
                if (segment != front.segment)
                {
                    segment = front.segment;
                }
                ApplyTracer(spline, percent, front.tracer.direction);
                return;
            }

            //Otherwise, move along the current recorded spline segment
            if (segment != front.segment)
            {
                inverseDirection = segment.direction;
                InvertDirection(ref inverseDirection);
                spline      = segment.spline;
                percent     = segment.Travel(offset - totalMoved, inverseDirection, out moved, segment.spline.isClosed);
                totalMoved += moved;
            }
            ApplyTracer(spline, percent, segment.direction);
        }