public static void UpdateSourceSystem(VegetationSystemPro srcSystem, Terrain terrain) { //erasing legacy settings on copyVS change //returning extents after using per-terrain systems VegetationSystemPro copySystem = VSProOps.GetCopyVegetationSystem(terrain); if (srcSystem.VegetationSystemBounds.extents.x < 1) { srcSystem.VegetationSystemBounds = new Bounds( terrain.transform.position + terrain.terrainData.size / 2, terrain.terrainData.size * 3.4f); srcSystem.RefreshVegetationSystem(); } if (copySystem != null && srcSystem.PersistentVegetationStorage != null && srcSystem.PersistentVegetationStorage.PersistentVegetationStoragePackage == copySystem.PersistentVegetationStorage.PersistentVegetationStoragePackage) { srcSystem.PersistentVegetationStorage.InitializePersistentStorage(); } if (copySystem != null) { GameObject.DestroyImmediate(copySystem.gameObject); } //unityterrain UnityTerrain unityTerrain = terrain.GetComponent <UnityTerrain>(); //VS Pro component added to terrain if (unityTerrain == null) { unityTerrain = VSProOps.AddUnityTerrain(terrain); } unityTerrain.TerrainPosition = terrain.transform.position; if (srcSystem != null && !srcSystem.VegetationStudioTerrainList.Contains(unityTerrain)) //check if already added since AddTerrain is long operation { srcSystem.AddTerrain(terrain.gameObject); } //refresh system (takes >100 ms) UnityEngine.Profiling.Profiler.BeginSample("VegetationSystemPro.RefreshVegetationSystem"); srcSystem.RefreshVegetationSystem(); UnityEngine.Profiling.Profiler.EndSample(); }
/// <summary> /// Iterate through all items of the selected biome /// </summary> /// <param name="selectedBiomeTypes"></param> /// <returns></returns> public int Process(BiomeType[] selectedBiomeTypes) { int itemChangeCount = 0; List <VegetationSystemPro> VegetationSystemList = VegetationStudioInstance.VegetationSystemList; for (int i = 0; i <= VegetationSystemList.Count - 1; i++) { VegetationSystemPro vegetationSystemPro = VegetationSystemList[i]; foreach (VegetationPackagePro vegetationPackagePro in vegetationSystemPro.VegetationPackageProList) { // filter biome type if (!ArrayUtility.Contains(selectedBiomeTypes, vegetationPackagePro.BiomeType)) { continue; } // note: the delete mechanism operates on the list itself => we have to use a clone => using ToArray() on the list foreach (VegetationItemInfoPro vegetationItemInfoPro in vegetationPackagePro.VegetationInfoList.ToArray()) { // perform the actual action OnActionPerformed(vegetationPackagePro, vegetationItemInfoPro); // clear cache vegetationSystemPro.ClearCache(vegetationItemInfoPro.VegetationItemID); itemChangeCount++; } EditorUtility.SetDirty(vegetationPackagePro); } vegetationSystemPro.RefreshVegetationSystem(); VegetationStudioProUtils.SetSceneDirty(vegetationSystemPro); } return(itemChangeCount); }
public static VegetationSystemPro UpdateCopySystem(VegetationSystemPro copySystem, Terrain terrain, VegetationPackagePro package, VegetationSystemPro srcSystem) { Transform tileTfm = terrain.transform.parent; //erasing legacy settings on copyVS change //checking if src system has any extents, and resetting them - otherwise refreshing clone systems will take too long if (srcSystem.VegetationSystemBounds.extents.x > 1) { srcSystem.VegetationSystemBounds = new Bounds(Vector3.zero, Vector3.zero); srcSystem.RefreshVegetationSystem(); } if (srcSystem.VegetationStudioTerrainObjectList.Count != 0) { srcSystem.RemoveAllTerrains(); } //unityterrain UnityTerrain unityTerrain = terrain.GetComponent <UnityTerrain>(); //VS Pro component added to terrain if (unityTerrain == null) { unityTerrain = VSProOps.AddUnityTerrain(terrain); } unityTerrain.TerrainPosition = terrain.transform.position; //resetting clone package just in case if (copySystem.VegetationPackageProList.Count == 0 || copySystem.VegetationPackageProList[0] != package) { copySystem.VegetationPackageProList.Clear(); copySystem.AddVegetationPackage(package); } //reset bounds copySystem.AutomaticBoundsCalculation = false; copySystem.VegetationSystemBounds = new Bounds( //or use unityTerrain.TerrainBounds; terrain.terrainData.bounds.center + terrain.transform.position, terrain.terrainData.bounds.extents * 2); //add terrain if (copySystem.VegetationStudioTerrainObjectList.Count != 1 || copySystem.VegetationStudioTerrainObjectList[0] != terrain.gameObject) { if (copySystem.VegetationStudioTerrainObjectList.Count != 0) { copySystem.RemoveAllTerrains(); } copySystem.AddTerrain(terrain.gameObject); //will call RefreshVegetationStudioTerrains and RefreshVegetationStudioTerrains } //clearing storage if (copySystem.PersistentVegetationStorage.PersistentVegetationStoragePackage == null) { copySystem.PersistentVegetationStorage.PersistentVegetationStoragePackage = ScriptableObject.CreateInstance <PersistentVegetationStoragePackage>(); //new PersistentVegetationStoragePackage(); //changed on feedback from forum } //clearing is done in apply //refresh system (takes >100 ms) UnityEngine.Profiling.Profiler.BeginSample("VegetationSystemPro.RefreshVegetationSystem"); // copySystem.RefreshVegetationSystem(); if (copySystem != null) //re-initializing { copySystem.enabled = false; copySystem.enabled = true; //to call private OnEnable } UnityEngine.Profiling.Profiler.EndSample(); return(copySystem); }