Ejemplo n.º 1
0
        /// <summary>
        /// AddVegetationItem will add a new instance of a Vegetation Item to the persistent storage. Position, scale and rotation is in worldspace. The Optional clearCellCache will refresh the area where the item is added.
        /// </summary>
        /// <param name="vegetationItemID"></param>
        /// <param name="worldPosition"></param>
        /// <param name="scale"></param>
        /// <param name="rotation"></param>
        /// <param name="applyMeshRotation"></param>
        /// <param name="vegetationSourceID"></param>
        /// <param name="distanceFalloff"></param>
        /// <param name="clearCellCache"></param>
        public void AddVegetationItemInstance(string vegetationItemID, Vector3 worldPosition, Vector3 scale, Quaternion rotation, bool applyMeshRotation, byte vegetationSourceID, float distanceFalloff, bool clearCellCache = false)
        {
            if (!VegetationSystemPro || !PersistentVegetationStoragePackage)
            {
                return;
            }
            Rect positionRect = new Rect(new Vector2(worldPosition.x, worldPosition.z), Vector2.zero);

            VegetationItemInfoPro vegetationItemInfo = VegetationSystemPro.GetVegetationItemInfo(vegetationItemID);

            if (applyMeshRotation)
            {
                rotation *= Quaternion.Euler(vegetationItemInfo.RotationOffset);
            }

            List <VegetationCell> overlapCellList = new List <VegetationCell>();

            VegetationSystemPro.VegetationCellQuadTree.Query(positionRect, overlapCellList);

            for (int i = 0; i <= overlapCellList.Count - 1; i++)
            {
                int cellIndex = overlapCellList[i].Index;
                if (clearCellCache)
                {
                    VegetationItemIndexes indexes = VegetationSystemPro.GetVegetationItemIndexes(vegetationItemID);
                    VegetationSystemPro.ClearCache(overlapCellList[i], indexes.VegetationPackageIndex, indexes.VegetationItemIndex);
                }
                PersistentVegetationStoragePackage.AddVegetationItemInstance(cellIndex, vegetationItemID, worldPosition - VegetationSystemPro.VegetationSystemPosition, scale, rotation, vegetationSourceID, distanceFalloff);
            }
        }
Ejemplo n.º 2
0
        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
        }