Exemple #1
0
        public void RemoveForeignTerrainDetails(List <SpawnerSettings> biomeSpawnerSettings, List <string> validTerrainNames = null)
        {
            ProgressBar.Show(ProgressBarPriority.BiomeRemoval, "Removing Foreign Terrain Details", "Removing...");
            List <ResourceProtoDetail> knownTerrainDetails = new List <ResourceProtoDetail>();
            Terrain currentTerrain = GetCurrentTerrain();

            foreach (SpawnerSettings spawnerSettings in biomeSpawnerSettings)
            {
                foreach (SpawnRule sr in spawnerSettings.m_spawnerRules)
                {
                    if (sr.m_resourceType == GaiaConstants.SpawnerResourceType.TerrainDetail)
                    {
                        knownTerrainDetails.Add(spawnerSettings.m_resources.m_detailPrototypes[sr.m_resourceIdx]);
                    }
                }
            }

            GaiaMultiTerrainOperation operation = new GaiaMultiTerrainOperation(currentTerrain, transform, m_settings.m_range * 2f, false, validTerrainNames);

            operation.GetHeightmap();
            operation.GetNormalmap();
            operation.CollectTerrainDetails();
            operation.CollectTerrainTrees();
            operation.CollectTerrainGameObjects();
            operation.CollectTerrainBakedMasks();

            ProgressBar.Show(ProgressBarPriority.BiomeRemoval, "Removing Foreign Terrain Details", "Removing Terrain Details...");
            operation.RemoveForeignTerrainDetails(ApplyBrush(operation, MultiTerrainOperationType.TerrainDetail), knownTerrainDetails, m_settings.m_removeForeignTerrainDetailsStrength);

            operation.CloseOperation();
            ProgressBar.Clear(ProgressBarPriority.BiomeRemoval);
        }
Exemple #2
0
        public void RemoveForeignTrees(List <SpawnerSettings> biomeSpawnerSettings, List <string> validTerrainNames = null)
        {
            ProgressBar.Show(ProgressBarPriority.BiomeRemoval, "Removing Foreign Trees", "Removing...");
            //Collect the "allowed" tree prefabs in a list, any tree that is not in this list will be affected by the removal operation
            List <GameObject> domesticTreePrefabs = new List <GameObject>();
            //List<TreePrototype> treeProtosToRemove = new List<TreePrototype>();
            Terrain currentTerrain = GetCurrentTerrain();

            foreach (SpawnerSettings spawnerSettings in biomeSpawnerSettings)
            {
                foreach (SpawnRule sr in spawnerSettings.m_spawnerRules)
                {
                    if (sr.m_resourceType == GaiaConstants.SpawnerResourceType.TerrainTree)
                    {
                        domesticTreePrefabs.Add(spawnerSettings.m_resources.m_treePrototypes[sr.m_resourceIdx].m_desktopPrefab);
                    }
                }
            }

            GaiaMultiTerrainOperation operation = new GaiaMultiTerrainOperation(currentTerrain, transform, m_settings.m_range * 2f, false, validTerrainNames);

            operation.GetHeightmap();
            operation.GetNormalmap();
            operation.CollectTerrainDetails();
            operation.CollectTerrainTrees();
            operation.CollectTerrainGameObjects();
            operation.CollectTerrainBakedMasks();

            operation.RemoveForeignTrees(ApplyBrush(operation, MultiTerrainOperationType.Tree), domesticTreePrefabs, m_settings.m_removeForeignTreesStrength);
            ProgressBar.Clear(ProgressBarPriority.BiomeRemoval);
            operation.CloseOperation();
        }
Exemple #3
0
        public void RemoveForeignGameObjects(List <SpawnerSettings> biomeSpawnerSettings, List <string> validTerrainNames = null)
        {
            ProgressBar.Show(ProgressBarPriority.BiomeRemoval, "Removing Foreign GameObjects", "Removing...");
            List <ResourceProtoGameObjectInstance> knownProtoInstances      = new List <ResourceProtoGameObjectInstance>();
            List <ResourceProtoGameObjectInstance> GoProtoInstancesToRemove = new List <ResourceProtoGameObjectInstance>();
            Terrain currentTerrain = GetCurrentTerrain();

            foreach (SpawnerSettings spawnerSettings in biomeSpawnerSettings)
            {
                foreach (SpawnRule sr in spawnerSettings.m_spawnerRules)
                {
                    if (sr.m_resourceType == GaiaConstants.SpawnerResourceType.GameObject)
                    {
                        foreach (ResourceProtoGameObjectInstance instance in spawnerSettings.m_resources.m_gameObjectPrototypes[sr.m_resourceIdx].m_instances)
                        {
                            knownProtoInstances.Add(instance);
                        }
                    }
                }
            }

            GaiaMultiTerrainOperation operation = new GaiaMultiTerrainOperation(currentTerrain, transform, m_settings.m_range * 2f, false, validTerrainNames);

            operation.GetHeightmap();
            operation.GetNormalmap();
            operation.CollectTerrainDetails();
            operation.CollectTerrainTrees();
            operation.CollectTerrainGameObjects();
            operation.CollectTerrainBakedMasks();

            int protoIndex  = 0;
            var allSpawners = Resources.FindObjectsOfTypeAll <Spawner>();

            foreach (Spawner spawner in allSpawners)
            {
                //During the removal we have to put the spawn settings in remove mode
                SpawnMode originalMode = spawner.m_settings.m_spawnMode;
                spawner.m_settings.m_spawnMode = SpawnMode.Remove;

                ProgressBar.Show(ProgressBarPriority.BiomeRemoval, "Removing Foreign GameObjects", "Removing Game Objects...", protoIndex, allSpawners.Length);
                foreach (SpawnRule sr in spawner.m_settings.m_spawnerRules)
                {
                    if (sr.m_resourceType == GaiaConstants.SpawnerResourceType.GameObject)
                    {
                        ResourceProtoGameObject protoGO = spawner.m_settings.m_resources.m_gameObjectPrototypes[sr.m_resourceIdx];
                        foreach (ResourceProtoGameObjectInstance instance in protoGO.m_instances)
                        {
                            if (!knownProtoInstances.Contains(instance))
                            {
                                operation.SetTerrainGameObjects(ApplyBrush(operation, MultiTerrainOperationType.GameObject), protoGO, sr, spawner.m_settings, 0, ref sr.m_spawnedInstances, m_settings.m_removeForeignGameObjectStrength, false);
                                //no need to look at other instances if this one triggered the removal already
                                break;
                            }
                        }
                    }
                }

                spawner.m_settings.m_spawnMode = originalMode;
                protoIndex++;
            }
            operation.CloseOperation();

#if UNITY_EDITOR
            //need to dirty the scene when we remove game objects
            EditorSceneManager.MarkSceneDirty(gameObject.scene);
#endif
            ProgressBar.Clear(ProgressBarPriority.BiomeRemoval);
        }