Пример #1
0
        private void GenerateRoads()
        {
            this.Roads.Clear();
            var spacing = 5f;

            for (var i = 0; i < this.RoadCount; i++)
            {
                var regen = true;
                var road  = new RoadData();
                while (regen)
                {
                    regen = false;
                    road  = this.GenerateRoad();
                    foreach (var r in this.Roads)
                    {
                        if (Mathf.Abs(road.Start.x - r.Start.x) < spacing ||
                            Mathf.Abs(road.Start.y - r.Start.y) < spacing ||
                            Mathf.Abs(road.End.x - r.End.x) < spacing ||
                            Mathf.Abs(road.End.y - r.End.y) < spacing)
                        {
                            regen = true;
                            break;
                        }
                    }
                }
                this.Roads.Add(road);
            }

            if (OnGenerationComplete != null)
            {
                OnGenerationComplete(this.Roads);
            }
        }
Пример #2
0
        private GameObject RenderRoad(RoadData road)
        {
            var slope = road.End.Slope(road.Start);
            var g     = new GameObject(string.Format("Road (Slope:{0})", slope));
            var l     = g.AddComponent <LineRenderer>();

            l.positionCount   = 2;
            l.material        = this.RoadMaterial;
            l.widthMultiplier = 3;
            l.SetPositions(new Vector3[]
            {
                new Vector3(road.Start.x, 0f, road.Start.y),
                new Vector3(road.End.x, 0f, road.End.y),
            });
            return(g);
        }