private void DrawConnection(DrawMode mode)
        {
            var s = SplineComponent.CreateSpline(StartNode.transform, EndNode.transform, CurveIn);

            DrawSpline(mode, s);
        }
Пример #2
0
        private List <Entity> GenerateSegmentEntities(Dictionary <RoadNode, Entity> roadNodes)
        {
            List <Entity> segments = new List <Entity>();
            Dictionary <RoadSegment, Entity> roadSegmentsMap = new Dictionary <RoadSegment, Entity>();

            foreach (var roadPiece in roadPieces)
            {
                foreach (var segment in roadPiece.RoadSegments)
                {
                    var segmentEntity = dstManager.CreateEntity(typeof(SegmentConfigComponent), typeof(SplineComponent),
                                                                typeof(SegmentComponent), typeof(SegmentTrafficTypeComponent));

                    var splineComponent = SplineComponent.CreateSpline(segment.StartNode.transform, segment.EndNode.transform,
                                                                       segment.CurveIn);

                    var segmentComponent = dstManager.GetComponentData <SegmentConfigComponent>(segmentEntity);
                    segmentComponent.StartNode = roadNodes[segment.StartNode];
                    segmentComponent.EndNode   = roadNodes[segment.EndNode];
                    segmentComponent.Length    = splineComponent.TotalLength();

                    var nodeBuffer = dstManager.GetBuffer <ConnectedSegmentBufferElement>(segmentComponent.StartNode);
                    nodeBuffer.Add(new ConnectedSegmentBufferElement {
                        segment = segmentEntity
                    });

                    dstManager.SetComponentData(segmentEntity, segmentComponent);
                    dstManager.SetComponentData(segmentEntity, splineComponent);
                    dstManager.SetComponentData(segmentEntity,
                                                new SegmentComponent {
                        AvailableLength = segmentComponent.Length
                    });

                    segments.Add(segmentEntity);
                    roadSegmentsMap.Add(segment, segmentEntity);
                }
            }

            foreach (var roadPiece in roadPieces)
            {
                //is intersection
                if (roadPiece.intersectionGroups.Length > 0)
                {
                    var intersectionEntity = dstManager.CreateEntity(typeof(IntersectionComponent), typeof(IntersectionTimerComponent));
                    dstManager.AddBuffer <IntersectionSegmentsGroupBufferElement>(intersectionEntity);
                    var intersectionSegmentBufferElements       = dstManager.AddBuffer <IntersectionSegmentBufferElement>(intersectionEntity);
                    var intersectionSegmentsGroupBufferElements =
                        dstManager.GetBuffer <IntersectionSegmentsGroupBufferElement>(intersectionEntity);
                    var counter = 0;
                    for (int i = 0; i < roadPiece.intersectionGroups.Length; i++)
                    {
                        var group = roadPiece.intersectionGroups[i];
                        intersectionSegmentsGroupBufferElements.Add(new IntersectionSegmentsGroupBufferElement
                        {
                            StartIndex = counter,
                            EndIndex   = counter + group.Segments.Length - 1,
                            Time       = group.Time
                        });
                        foreach (var roadSegment in group.Segments)
                        {
                            var segmentEntity = roadSegmentsMap[roadSegment];
                            intersectionSegmentBufferElements.Add(new IntersectionSegmentBufferElement
                            {
                                Segment = segmentEntity
                            });
                            counter++;
                            dstManager.SetComponentData(segmentEntity, new SegmentTrafficTypeComponent {
                                TrafficType = ConnectionTrafficType.NoEntrance
                            });
                        }
                    }
                }
            }

            return(segments);
        }