Example #1
0
    void Start()
    {
        if (heightmapGameObject != null)
        {
            heightmap = UnityEngineHelper.GetInterface <IHeightmap>(heightmapGameObject);
        }

        if (heightmap == null)
        {
            Debug.LogError("MockAllotment needs a reference to a game object containing at least one component that implements IHeightmap");
            return;
        }

        if (!heightmap.Finished())
        {
            Debug.LogError("MockAllotment script can only execute after the components that implements IHeightmap (Configure execution order that in Edit > Project Settings > Script Execution Order)");
            return;
        }

        if (allotmentBuilderGameObject != null)
        {
            allotmentBuilders = UnityEngineHelper.GetInterfaces <IAllotmentBuilder>(allotmentBuilderGameObject);
        }
        if (allotmentBuilders == null)
        {
            Debug.LogError("MockAllotment needs a reference to a game object containing at least one component that implements IAllotmentBuilder");
            return;
        }

        Generate();
    }
    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");
    }