using System.Collections.Generic; using AwesomeTechnologies.Vegetation.PersistentStorage; using AwesomeTechnologies.VegetationSystem; using UnityEngine; namespace AwesomeTechnologies.VegetationStudio { public partial class VegetationStudioManager { /// /// Add a new vegetation item to all vegetation packages used in the scene. If multiple terrains is using the same package it will only be added once. /// Set includeInTerrain to false if item is to be used from a PersistentVegetationStorage /// /// The prefab containing the VegetationMesh with material you want to add to the VegetationPackage /// Type of vegetation. This will affect default rules and LOD behaviour. /// Set this to true in order to enable runtime spawning of the new Vegetation Item. /// /// Returns the ID of the new VegetaionItem added to the VegetationPackage public static string AddVegetationItem(GameObject prefab, VegetationType vegetationType, bool enableRuntimeSpawn, BiomeType biomeType = BiomeType.Default) { if (!Instance) FindInstance(); if (Instance) { string newVegetationItemID = System.Guid.NewGuid().ToString(); List vegetationPackageList = GetVegetationPackageList(biomeType); for (int i = 0; i <= vegetationPackageList.Count - 1; i++) { vegetationPackageList[i].AddVegetationItem(prefab, vegetationType, enableRuntimeSpawn, newVegetationItemID); } RefreshVegetationSystem(); return newVegetationItemID; } return ""; } public static void RefreshVegetationSystem() { if (!Instance) FindInstance(); if (Instance) { for (int i = 0; i <= Instance.VegetationSystemList.Count - 1; i++) { Instance.VegetationSystemList[i].RefreshVegetationSystem(); } } } /// /// Get the VegetationItemID from the assetGUID. an empty string will be returned if not found /// /// /// returns the VegetationItemID of the prefab/texture with matching assetGUID public static string GetVegetationItemID(string assetGuid) { if (!Instance) FindInstance(); if (Instance) { List vegetationPackageList = GetAllVegetationPackageList(); for (int i = 0; i <= vegetationPackageList.Count - 1; i++) { string vegetationitemID = vegetationPackageList[i].GetVegetationItemID(assetGuid); if (vegetationitemID != "") return vegetationitemID; } } return ""; } /// /// /// /// /// /// /// /// public static string AddVegetationItem(Texture2D texture, VegetationType vegetationType, bool enableRuntimeSpawn, BiomeType biomeType = BiomeType.Default) { if (!Instance) FindInstance(); if (Instance) { string newVegetationItemID = System.Guid.NewGuid().ToString(); List vegetationPackageList = GetVegetationPackageList(biomeType); for (int i = 0; i <= vegetationPackageList.Count - 1; i++) { vegetationPackageList[i] .AddVegetationItem(texture, vegetationType, enableRuntimeSpawn, newVegetationItemID); } RefreshVegetationSystem(); return newVegetationItemID; } return ""; } /// /// This will add a new instance of a vegetationItem to the PersistentVegetationStorage. The VegetationItemID is the one you get from the AddVegetationItem function or from an existing item in the VegetationPackage. You provide it with worldspace position and a vegetationSourceID. See PersistentVegetationStorageTools.cs for info about the vegetationSourceID. /// /// /// /// /// /// /// /// /// public static void AddVegetationItemInstance(string vegetationItemID, Vector3 worldPosition, Vector3 scale, Quaternion rotation,bool applyMeshRotation, byte vegetationSourceID,float distanceFalloff, bool clearCellCache = true) { if (!Instance) FindInstance(); if (Instance) { for (int i = 0; i <= Instance.VegetationSystemList.Count - 1; i++) { PersistentVegetationStorage persistentVegetationStorage = Instance.VegetationSystemList[i].PersistentVegetationStorage; if (persistentVegetationStorage) { persistentVegetationStorage.AddVegetationItemInstance(vegetationItemID, worldPosition, scale, rotation, applyMeshRotation, vegetationSourceID, distanceFalloff, clearCellCache); } } } } /// /// /// /// /// /// /// public static void RemoveVegetationItemInstance(string vegetationItemID, Vector3 worldPosition, float minimumDistance, bool clearCellCache = true) { if (!Instance) FindInstance(); if (Instance) { for (int i = 0; i <= Instance.VegetationSystemList.Count - 1; i++) { PersistentVegetationStorage persistentVegetationStorage = Instance.VegetationSystemList[i].PersistentVegetationStorage; if (persistentVegetationStorage) { persistentVegetationStorage.RemoveVegetationItemInstance(vegetationItemID, worldPosition, minimumDistance, clearCellCache); } } } } public static void RemoveVegetationItemInstance2D(string vegetationItemID, Vector3 worldPosition, float minimumDistance, bool clearCellCache = true) { if (!Instance) FindInstance(); if (Instance) { for (int i = 0; i <= Instance.VegetationSystemList.Count - 1; i++) { PersistentVegetationStorage persistentVegetationStorage = Instance.VegetationSystemList[i].PersistentVegetationStorage; if (persistentVegetationStorage) { persistentVegetationStorage.RemoveVegetationItemInstance2D(vegetationItemID, worldPosition, minimumDistance, clearCellCache); } } } } /// /// /// /// /// public static void RemoveVegetationItemInstances(string vegetationItemID, byte vegetationSourceID) { if (!Instance) FindInstance(); if (Instance) { for (int i = 0; i <= Instance.VegetationSystemList.Count - 1; i++) { PersistentVegetationStorage persistentVegetationStorage = Instance.VegetationSystemList[i].PersistentVegetationStorage; if (persistentVegetationStorage) { persistentVegetationStorage.RemoveVegetationItemInstances(vegetationItemID,vegetationSourceID); } } } } /// /// /// /// public static void RemoveVegetationItemInstances(string vegetationItemID) { if (!Instance) FindInstance(); if (Instance) { for (int i = 0; i <= Instance.VegetationSystemList.Count - 1; i++) { PersistentVegetationStorage persistentVegetationStorage = Instance.VegetationSystemList[i].PersistentVegetationStorage; if (persistentVegetationStorage) { persistentVegetationStorage.RemoveVegetationItemInstances(vegetationItemID); } } } } /// /// /// /// /// /// /// /// /// /// /// public static void AddVegetationItemInstanceEx(string vegetationItemID, Vector3 worldPosition, Vector3 scale, Quaternion rotation, byte vegetationSourceID, float minimumDistance, float distanceFalloff, bool clearCellCache = true) { if (!Instance) FindInstance(); if (Instance) { for (int i = 0; i <= Instance.VegetationSystemList.Count - 1; i++) { PersistentVegetationStorage persistentVegetationStorage = Instance.VegetationSystemList[i].PersistentVegetationStorage; if (persistentVegetationStorage) { persistentVegetationStorage.AddVegetationItemInstanceEx(vegetationItemID, worldPosition, scale, rotation, vegetationSourceID,minimumDistance, distanceFalloff, clearCellCache); } } } } /// /// Returns a unique list of all VegetationPackages used in the scene. /// /// public static List GetVegetationPackageList(BiomeType biomeType) { List vegetationPackageList = new List(); if (!Instance) FindInstance(); if (!Instance) return vegetationPackageList; for (int i = 0; i <= Instance.VegetationSystemList.Count - 1; i++) { VegetationSystemPro vegetationSystemPro = Instance.VegetationSystemList[i]; if (vegetationSystemPro) { VegetationPackagePro vegetationPackagePro = vegetationSystemPro.GetVegetationPackageFromBiome(biomeType); if (vegetationPackagePro) { vegetationPackageList.Add(vegetationPackagePro); } } } return vegetationPackageList; } /// /// Returns a unique list of all VegetationPackages used in the scene. /// /// public static List GetAllVegetationPackageList() { List vegetationPackageList = new List(); if (!Instance) FindInstance(); if (!Instance) return vegetationPackageList; for (int i = 0; i <= Instance.VegetationSystemList.Count - 1; i++) { VegetationSystemPro vegetationSystemPro = Instance.VegetationSystemList[i]; if (vegetationSystemPro) { vegetationPackageList.AddRange(vegetationSystemPro.VegetationPackageProList); } } return vegetationPackageList; } /// /// Will clear VegetationItemInstances of a VegetationType within an area. /// /// /// public static void ClearVegetationItemInstancesArea(string vegetationItemID, Bounds bounds) { Debug.Log("Not implemented"); } /// /// Will clear VegetationItemInstances of a VegetationType from a VegetationSource within an area. /// /// /// /// public static void ClearVegetationItemInstancesArea(string vegetationItemID, byte vegetationSourceID, Bounds bounds) { Debug.Log("Not implemented"); } } }