void Start() { SetupConfig(); // --- RoadNetworkGenerator.DebugData debugData; RoadNetworkGenerator.Generate(out segments, out quadtree, out debugData); Debug.Log(segments.Count + " segments"); // --- mask = ((generateHighways) ? RoadNetworkTraversal.HIGHWAYS_MASK : 0) | ((generateStreets) ? RoadNetworkTraversal.STREETS_MASK : 0); float minX = float.MaxValue, maxX = -float.MaxValue, minY = float.MaxValue, maxY = -float.MaxValue; HashSet <Segment> visited = new HashSet <Segment>(); foreach (var segment in segments) { RoadNetworkTraversal.PreOrder(segment, (a) => { minX = Mathf.Min(Mathf.Min(a.Start.x, a.End.x), minX); minY = Mathf.Min(Mathf.Min(a.Start.y, a.End.y), minY); maxX = Mathf.Max(Mathf.Max(a.Start.x, a.End.x), maxX); maxY = Mathf.Max(Mathf.Max(a.Start.y, a.End.y), maxY); return(true); }, mask, ref visited); } Vector2 size = new Vector2(maxX - minX, maxY - minY); Vector2 center = new Vector2(minX, minY); boundingBox = new Rect(center, size); finished = true; }
void Update() { if (action == 0) { return; } if (action == 1) { if (!end) { end = Input.GetKeyDown(KeyCode.F5); } if (!step) { step = Input.GetKeyDown(KeyCode.F10); } if (!step && !end) { return; } if (end) { RoadNetworkGenerator.EndInteractiveGeneration(ref context); action = 0; } else { if (!RoadNetworkGenerator.InteractiveGenerationStep(speed, ref context)) { action = 0; } } foreach (Segment segment in context.segments) { RoadNetworkTraversal.PreOrder(segment, Visitor, mask, ref visited); } RemoveIcons(); if (context.debugData.intersections.Count > 0 || context.debugData.snaps.Count > 0 || context.debugData.intersectionsRadius.Count > 0) { foreach (Vector2 intersection in context.debugData.intersections) { iconGOs.Add(CreateIcon(intersection, iconSize, downscaleFactor, z, intersectionIcon)); } foreach (Vector2 snap in context.debugData.snaps) { iconGOs.Add(CreateIcon(snap, iconSize, downscaleFactor, z, snapIcon)); } foreach (Vector2 intersectionRadius in context.debugData.intersectionsRadius) { iconGOs.Add(CreateIcon(intersectionRadius, iconSize, downscaleFactor, z, intersectionRadiusIcon)); } context.debugData.intersections.Clear(); context.debugData.snaps.Clear(); context.debugData.intersectionsRadius.Clear(); } step = false; } }
void Start() { if (roadNetwork == null) { Debug.LogError("RandomSettlementsSpawner needs a reference to a RoadNetwork"); return; } if (!roadNetwork.Finished) { Debug.LogError("RandomSettlementsSpawner script can only execute after RoadNetwork (Configure execution order that in Edit > Project Settings > Script Execution Order)"); return; } if (heightmapGameObject != null) { heightmap = UnityEngineHelper.GetInterface <IHeightmap>(heightmapGameObject); } if (heightmap == null) { Debug.LogError("RandomSettlementsSpawner needs a reference to a game object containing at least one component that implements IHeightmap"); return; } if (!heightmap.Finished()) { Debug.LogError("RandomSettlementsSpawner script can only execute after the components that implements IHeightmap (Configure execution order that in Edit > Project Settings > Script Execution Order)"); return; } List <IAllotmentBuilder> allotmentBuilders = null; if (allotmentBuilderGameObject != null) { allotmentBuilders = UnityEngineHelper.GetInterfaces <IAllotmentBuilder>(allotmentBuilderGameObject); } if (allotmentBuilders == null) { Debug.LogError("RoadDensitySettlementSpawner needs a reference to a game object containing at least one component that implements IAllotmentBuilder"); return; } Context context = new Context(roadNetwork.Quadtree); HashSet <Segment> visited = new HashSet <Segment>(); foreach (var segment in roadNetwork.Segments) { RoadNetworkTraversal.PreOrder(segment, ref context, -1, SegmentVisitor, roadNetwork.Mask, ref visited); } GameObject allotmentsGO = new GameObject("Allotments"); allotmentsGO.transform.parent = transform; foreach (var allotment in context.allotments) { foreach (var allotmentBuilder in allotmentBuilders) { GameObject allotmentGO = allotmentBuilder.Build(allotment, heightmap); allotmentGO.transform.parent = allotmentsGO.transform; } } Debug.Log(context.allotments.Count + " allotments spawned"); }
void Start() { if (roadNetwork == null) { Debug.LogError("RoadDensityBasedSettlementSpawner needs a reference to a RoadNetwork"); return; } if (!roadNetwork.Finished) { Debug.LogError("RoadDensityBasedSettlementSpawner script can only execute after RoadNetwork (Configure execution order that in Edit > Project Settings > Script Execution Order)"); return; } if (roadDensityMap == null) { Debug.LogError("RoadDensityBasedSettlementSpawner needs a reference to a RoadDensityMap"); return; } if (!roadDensityMap.Finished()) { Debug.LogError("RoadDensityBasedSettlementSpawner script can only execute after RoadDensityMap (Configure execution order that in Edit > Project Settings > Script Execution Order)"); return; } if (heightmapGameObject != null) { heightmap = UnityEngineHelper.GetInterface <IHeightmap>(heightmapGameObject); } if (heightmap == null) { Debug.LogError("RoadDensityBasedSettlementSpawner needs a reference to a game object containing at least one component that implements IHeightmap"); return; } if (!heightmap.Finished()) { Debug.LogError("RoadDensityBasedSettlementSpawner script can only execute after the components that implements IHeightmap (Configure execution order that in Edit > Project Settings > Script Execution Order)"); return; } List <IAllotmentBuilder> allotmentBuilders = null; if (allotmentBuilderGameObject != null) { allotmentBuilders = UnityEngineHelper.GetInterfaces <IAllotmentBuilder>(allotmentBuilderGameObject); } if (allotmentBuilders == null) { Debug.LogError("RoadDensityBasedSettlementSpawner needs a reference to a game object containing at least one component that implements IAllotmentBuilder"); return; } { float minThreshold = -float.MaxValue; foreach (var densityTier in densityTiers) { if (densityTier.threshold < minThreshold) { Debug.LogError("Density tier has a threshold smaller than it's predecessor"); return; } minThreshold = densityTier.threshold; } } minAllotmentWidth = Allotment.GetWidth(Config.allotmentMinHalfDiagonal, Config.allotmentMinAspect); allotments = new List <Tuple <float, Allotment> >(); HashSet <Segment> visited = new HashSet <Segment>(); foreach (var segment in roadNetwork.Segments) { RoadNetworkTraversal.PreOrder(segment, SegmentVisitor, roadNetwork.Mask, ref visited); } if (maxNumAllotments > 0 && allotments.Count > maxNumAllotments) { allotments.Sort((a, b) => b.Item1.CompareTo(a.Item1)); allotments = allotments.GetRange(0, maxNumAllotments); } GameObject allotmentsGO = new GameObject("Allotments"); allotmentsGO.transform.parent = transform; { foreach (var allotment in allotments) { foreach (var allotmentBuilder in allotmentBuilders) { GameObject allotmentGO = allotmentBuilder.Build(allotment.Item2, heightmap); allotmentGO.transform.parent = allotmentsGO.transform; } } } Debug.Log(allotments.Count + " allotments spawned"); }