Exemplo n.º 1
0
        private void InitGenerators()
        {
            var       generators    = new List <ObjectSpawner>();
            Transform terrainCenter = terrainSettings.infiniteTerrain ? player.transform : transform;

            treeSpawnSettings.resources.RemoveAll(t => t.prefab == null);
            if (treeSpawnSettings.resources.Count > 0)
            {
                MultipleObjectPool spawnTreePool = CreateTreePool();

                treeSpawnSettings.chunkSize          = terrainSettings.chunkSize;
                treeSpawnSettings.viewDistance       = terrainSettings.viewDistance;
                treeSpawnSettings.maxHeight          = terrainSettings.maxHeight;
                treeSpawnSettings.seaLevel           = terrainSettings.seaLevel;
                treeSpawnSettings.noiseSettings.seed = terrainSettings.noiseSettings.seed;

                var treeGenerator = new ObjectSpawner(spawnTreePool, treeSpawnSettings, terrainCenter);
                generators.Add(treeGenerator);
            }

            objectSpawnSettings.resources.RemoveAll(t => t.prefab == null);
            if (objectSpawnSettings.resources.Count > 0)
            {
                MultipleObjectPool spawnObjectPool = CreateSpawnObjectPool();
                objectSpawnSettings.chunkSize          = terrainSettings.chunkSize;
                objectSpawnSettings.viewDistance       = terrainSettings.viewDistance;
                objectSpawnSettings.maxHeight          = terrainSettings.maxHeight;
                objectSpawnSettings.noiseSettings.seed = terrainSettings.noiseSettings.seed;

                var objectGenerator = new ObjectSpawner(spawnObjectPool, objectSpawnSettings, terrainCenter);
                generators.Add(objectGenerator);
            }

            ObjectPool     chunkPool = CreateChunkPool();
            TerrainDensity density   = GetTerrainDensity();

            chunkGenerator = new ChunkGenerator(terrainSettings, density, chunkPool, generators, maxChunksPerFrame)
            {
                visualizeBounds = visualizeChunkBounds
            };

            if (waterPrefab != null)
            {
                ObjectPool waterPool = CreateWaterPool();
                waterGenerator = new WaterGenerator(waterPool, terrainSettings.seaLevel);
            }
        }
Exemplo n.º 2
0
        private MultipleObjectPool CreateSpawnObjectPool()
        {
            var objectContainer = new GameObject("ObjectPool");

            objectContainer.transform.SetParent(transform);

            int objectTypes   = objectSpawnSettings.resources.Count;
            var objectPrefabs = new List <GameObject>();

            for (int i = 0; i < objectTypes; i++)
            {
                GameObject objectPrefab = objectSpawnSettings.resources[i].prefab;
                objectPrefabs.Add(objectPrefab);
            }

            var objectPool = new MultipleObjectPool(objectPrefabs, objectContainer.transform, 300);

            objectPool.CreatePool();

            return(objectPool);
        }
Exemplo n.º 3
0
        private MultipleObjectPool CreateTreePool()
        {
            var treeContainer = new GameObject("TreePool");

            treeContainer.transform.SetParent(transform);

            int treeTypes   = treeSpawnSettings.resources.Count;
            var treePrefabs = new List <GameObject>();

            for (int i = 0; i < treeTypes; i++)
            {
                GameObject treePrefab = treeSpawnSettings.resources[i].prefab;
                treePrefabs.Add(treePrefab);
            }

            var treePool = new MultipleObjectPool(treePrefabs, treeContainer.transform, 300);

            treePool.CreatePool();

            return(treePool);
        }