public static void SetObjects(List <ObjectPool.Transition>[] allTransitions, string[] allIds) { if (system == null) { system = GameObject.FindObjectOfType <VegetationSystemPro>(); } if (system == null) { throw new System.Exception("MapMagic could not find Vegetation System in scene./n Add Window -> AwesomeTechnologies -> Vegetation System to scene"); } PersistentVegetationStorage storage = system.PersistentVegetationStorage; PersistentVegetationStoragePackage storagePackage = system.PersistentVegetationStorage.PersistentVegetationStoragePackage; if (storagePackage == null) { throw new System.Exception("Vegetation System has no storage package assigned to be used with MapMagic./nAssign a Persistent Vegetation Storage Package to Persistent Vegetation Storage component and initialize it."); } for (int i = 0; i < allTransitions.Length; i++) { if (allTransitions[i] == null) { continue; } var itemInfo = system.GetVegetationItemInfo(allIds[i]); if (itemInfo == null) { throw new System.Exception("Item applied by MapMagic is not present in Vegetation System storage"); } foreach (ObjectPool.Transition obj in allTransitions[i]) { storage.AddVegetationItemInstance( allIds[i], obj.pos, obj.scale, obj.rotation, applyMeshRotation: true, vegetationSourceID: VS_MM_id, distanceFalloff: 1, clearCellCache: true); } } //for (int i=0; i<system.VegetationCellList.Count; i++) // system.VegetationCellList[i].ClearCache(); //system.ClearCache(); system.RefreshBillboards(); #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(storagePackage); UnityEditor.EditorUtility.SetDirty(system); #endif }
public static void SetObjects(List <Transition>[] allTransitions, string[] allIds) { VegetationSystemPro system = GameObject.FindObjectOfType <VegetationSystemPro>(); PersistentVegetationStorage storage = system.PersistentVegetationStorage; for (int i = 0; i < allTransitions.Length; i++) { if (allTransitions[i] == null) { continue; } foreach (Transition obj in allTransitions[i]) { storage.AddVegetationItemInstance( allIds[i], obj.pos, obj.scale, obj.rotation, applyMeshRotation: true, vegetationSourceID: VS_MM_id, distanceFalloff: 1, clearCellCache: true); } } //for (int i=0; i<system.VegetationCellList.Count; i++) // system.VegetationCellList[i].ClearCache(); system.RefreshBillboards(); #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(storage.PersistentVegetationStoragePackage); UnityEditor.EditorUtility.SetDirty(system); #endif }
public static void FlushObjects(Rect terrainRect, bool clearCache = true) { VegetationSystemPro system = GameObject.FindObjectOfType <VegetationSystemPro>(); if (system == null) { return; } PersistentVegetationStorage storage = system.PersistentVegetationStorage; PersistentVegetationStoragePackage storagePackage = system.PersistentVegetationStorage.PersistentVegetationStoragePackage; if (storagePackage == null) { return; } List <VegetationCell> overlapCellList = new List <VegetationCell>(); system.VegetationCellQuadTree.Query(terrainRect, overlapCellList); for (int i = 0; i < overlapCellList.Count; i++) { int cellIndex = overlapCellList[i].Index; //storagePackage.PersistentVegetationCellList[cellIndex].ClearCell(); var infoList = storagePackage.PersistentVegetationCellList[cellIndex].PersistentVegetationInfoList; for (int j = 0; j < infoList.Count; j++) { var itemList = infoList[j].VegetationItemList; for (int k = itemList.Count - 1; k >= 0; k--) { Vector3 pos = itemList[k].Position + system.VegetationSystemPosition; Vector2 pos2 = pos.V2(); if (terrainRect.Contains(pos2)) { itemList.RemoveAt(k); //storage.RemoveVegetationItemInstance(infoList[j].VegetationItemID, pos, 1, clearCellCache:false); } } } //VegetationItemIndexes indexes = VegetationSystemPro.GetVegetationItemIndexes(vegetationItemID); //system.ClearCache(overlapCellList[i],indexes.VegetationPackageIndex,indexes.VegetationItemIndex); } //if (clearCache) //{ // for (int i=0; i<system.VegetationCellList.Count; i++) // system.VegetationCellList[i].ClearCache(); //} system.RefreshBillboards(); }
public static void SetObjects(VegetationSystemPro system, List <Transition>[] allTransitions, string[] allIds) { PersistentVegetationStorage storage = system.PersistentVegetationStorage; //if (system.VegetationCellQuadTree == null) //could happen on scene loading or playmode change // system.RefreshVegetationSystem(); if (!system.InitDone) { system.enabled = true; } byte VS_MM_id = 15; //15 for MapMagic, 18 for Voxeland for (int i = 0; i < allTransitions.Length; i++) { if (allTransitions[i] == null) { continue; } foreach (Transition obj in allTransitions[i]) { storage.AddVegetationItemInstance( allIds[i], obj.pos, obj.scale, obj.rotation, applyMeshRotation: true, vegetationSourceID: VS_MM_id, distanceFalloff: 1, clearCellCache: true); } } //for (int i=0; i<system.VegetationCellList.Count; i++) // system.VegetationCellList[i].ClearCache(); system.RefreshBillboards(); #if UNITY_EDITOR if (storage.PersistentVegetationStoragePackage != null) { UnityEditor.EditorUtility.SetDirty(storage.PersistentVegetationStoragePackage); } UnityEditor.EditorUtility.SetDirty(system); #endif }