Exemple #1
0
        public VegetationItemModelInfo GetVegetationItemModelInfo(string vegetationItemID)
        {
            VegetationItemIndexes vegetationItemIndexes = GetVegetationItemIndexes(vegetationItemID);

            return(GetVegetationItemModelInfo(vegetationItemIndexes.VegetationPackageIndex,
                                              vegetationItemIndexes.VegetationItemIndex));
        }
        /// <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);
            }
        }
        private static void AddVegetationMaskToVegetationSystem(VegetationSystemPro vegetationSystem, BaseMaskArea maskArea)
        {
            vegetationSystem.CompleteCellLoading();

            VegetationItemIndexes vegetationItemIndexes = new VegetationItemIndexes();

            if (maskArea.VegetationItemID != "")
            {
                vegetationItemIndexes = vegetationSystem.GetVegetationItemIndexes(maskArea.VegetationItemID);
            }
            else
            {
                vegetationItemIndexes.VegetationPackageIndex = -1;
                vegetationItemIndexes.VegetationItemIndex    = -1;
            }

            Rect maskRect = RectExtension.CreateRectFromBounds(maskArea.MaskBounds);

            if (vegetationSystem.VegetationCellQuadTree == null ||
                vegetationSystem.BillboardCellQuadTree == null)
            {
                return;
            }

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

            vegetationSystem.VegetationCellQuadTree.Query(maskRect, selectedCellList);

            if (vegetationItemIndexes.VegetationPackageIndex > -1)
            {
                for (int i = 0; i <= selectedCellList.Count - 1; i++)
                {
                    selectedCellList[i]
                    .AddVegetationMask(
                        maskArea, vegetationItemIndexes.VegetationPackageIndex, vegetationItemIndexes.VegetationItemIndex);
                }

                List <BillboardCell> selectedBillboardCellList = new List <BillboardCell>();
                vegetationSystem.BillboardCellQuadTree.Query(maskRect, selectedBillboardCellList);
                for (int i = 0; i <= selectedBillboardCellList.Count - 1; i++)
                {
                    selectedBillboardCellList[i].ClearCache(vegetationItemIndexes.VegetationPackageIndex, vegetationItemIndexes.VegetationItemIndex);
                }
            }
            else
            {
                for (int i = 0; i <= selectedCellList.Count - 1; i++)
                {
                    selectedCellList[i].AddVegetationMask(maskArea);
                }

                List <BillboardCell> selectedBillboardCellList = new List <BillboardCell>();
                vegetationSystem.BillboardCellQuadTree.Query(maskRect, selectedBillboardCellList);
                for (int i = 0; i <= selectedBillboardCellList.Count - 1; i++)
                {
                    selectedBillboardCellList[i].ClearCache();
                }
            }
        }
        private void OnVegetationItemVisible(ItemSelectorInstanceInfo itemSelectorInstanceInfo,
                                             VegetationItemIndexes vegetationItemIndexes, string vegetationItemID)
        {
            GameObject colliderObject = RuntimePrefabPool.GetObject(itemSelectorInstanceInfo);

            RuntimePrefabStorage.AddRuntimePrefab(colliderObject, itemSelectorInstanceInfo.VegetationCellIndex,
                                                  itemSelectorInstanceInfo.VegetationCellItemIndex);
        }
        public void ClearCache(VegetationCell vegetationCell, string vegetationItemID)
        {
            VegetationItemIndexes indexes = GetVegetationItemIndexes(vegetationItemID);

            if (indexes.VegetationPackageIndex >= 0)
            {
                ClearCache(vegetationCell, indexes.VegetationPackageIndex, indexes.VegetationItemIndex);
            }
        }
        public void ClearCache(string vegetationItemID)
        {
            CompleteCellLoading();
            VegetationItemIndexes indexes = GetVegetationItemIndexes(vegetationItemID);

            if (indexes.VegetationPackageIndex >= 0)
            {
                ClearCache(indexes.VegetationPackageIndex, indexes.VegetationItemIndex);
            }
        }
        public VegetationItemInfoPro GetVegetationItemInfo(string vegetationItemID)
        {
            VegetationItemIndexes indexes = GetVegetationItemIndexes(vegetationItemID);

            if (indexes.VegetationPackageIndex >= 0)
            {
                return(VegetationPackageProList[indexes.VegetationPackageIndex]
                       .VegetationInfoList[indexes.VegetationItemIndex]);
            }
            return(null);
        }
        public NativeList <MatrixInstance> GetVegetationItemInstances(VegetationCell vegetationCell,
                                                                      string vegetationItemID)
        {
            CompleteCellLoading();

            VegetationItemIndexes vegetationItemIndexes = GetVegetationItemIndexes(vegetationItemID);

            if (vegetationCell.Prepared)
            {
                return(vegetationCell.VegetationPackageInstancesList[vegetationItemIndexes.VegetationPackageIndex]
                       .VegetationItemMatrixList[vegetationItemIndexes.VegetationItemIndex]);
            }
            return(new NativeList <MatrixInstance>());
        }
Exemple #9
0
        private void OnVegetationItemInvisible(ItemSelectorInstanceInfo itemSelectorInstanceInfo,
                                               VegetationItemIndexes vegetationItemIndexes, string vegetationItemID)
        {
            if (OnBeforeDestroyColliderDelegate != null)
            {
                GameObject colliderObject = RuntimePrefabStorage.GetRuntimePrefab(
                    itemSelectorInstanceInfo.VegetationCellIndex,
                    itemSelectorInstanceInfo.VegetationCellItemIndex);
                OnBeforeDestroyColliderDelegate(colliderObject);
            }

            RuntimePrefabStorage.RemoveRuntimePrefab(itemSelectorInstanceInfo.VegetationCellIndex,
                                                     itemSelectorInstanceInfo.VegetationCellItemIndex, ColliderPool);
        }
        public VegetationItemSelector(VisibleVegetationCellSelector visibleVegetationCellSelector, VegetationSystemPro vegetationSystemPro, VegetationItemInfoPro vegetationItemInfoPro, bool useSpawnChance, float spawnChance, int spawnSeed)
        {
            _useSpawnChance = useSpawnChance;
            _spawnChance    = spawnChance;
            _spawnSeed      = spawnSeed;

            _visibleVegetationCellSelector = visibleVegetationCellSelector;
            _vegetationSystemPro           = vegetationSystemPro;

            VegetationItemID       = vegetationItemInfoPro.VegetationItemID;
            _vegetationItemIndexes = _vegetationSystemPro.GetVegetationItemIndexes(VegetationItemID);

            _visibleVegetationCellSelector.OnVegetationCellVisibleDelegate   += OnVegetationCellVisible;
            _visibleVegetationCellSelector.OnVegetationCellInvisibleDelegate += OnVegetationCellInvisible;

            _vegetationSystemPro.OnVegetationCellLoaded += OnVegetationCellLoaded;

            InstanceList = new NativeList <ItemSelectorInstanceInfo>(512, Allocator.Persistent);
            _removeVegetationCellIndexList = new NativeList <int>(64, Allocator.Persistent);
            _visibilityChangedIndexList    = new NativeList <int>(512, Allocator.Persistent);
        }
        public VegetationItemIndexes GetVegetationItemIndexes(string vegetationItemID)
        {
            VegetationItemIndexes indexes = new VegetationItemIndexes
            {
                VegetationItemIndex = -1, VegetationPackageIndex = -1
            };

            for (int i = 0; i <= VegetationPackageProList.Count - 1; i++)
            {
                for (int j = 0; j <= VegetationPackageProList[i].VegetationInfoList.Count - 1; j++)
                {
                    if (VegetationPackageProList[i].VegetationInfoList[j].VegetationItemID == vegetationItemID)
                    {
                        indexes.VegetationPackageIndex = i;
                        indexes.VegetationItemIndex    = j;
                        return(indexes);
                    }
                }
            }
            return(indexes);
        }
        public JobHandle SpawnVegetationCell(VegetationCell vegetationCell, string vegetationItemID,
                                             out bool hasInstancedIndirect)
        {
            hasInstancedIndirect = false;
            Rect vegetationCellRect = vegetationCell.Rectangle;

            VegetationItemIndexes vegetationItemIndexes = VegetationSystemPro.GetVegetationItemIndexes(vegetationItemID);

            if (vegetationItemIndexes.VegetationPackageIndex >= 0)
            {
                VegetationItemInfoPro vegetationItemInfoPro = VegetationPackageProList[vegetationItemIndexes.VegetationPackageIndex].VegetationInfoList[vegetationItemIndexes.VegetationItemIndex];

                if (vegetationItemInfoPro.VegetationRenderMode == VegetationRenderMode.InstancedIndirect)
                {
                    hasInstancedIndirect = true;
                }

                CompactMemoryCellList.Add(vegetationCell);
                return(ExecuteSpawnRules(vegetationCell, vegetationCellRect,
                                         vegetationItemIndexes.VegetationPackageIndex, vegetationItemIndexes.VegetationItemIndex));
            }

            return(default(JobHandle));
        }
        /// <summary>
        /// RepositionCellItems is used to check all instances of a VegetationItem in a cell and confirm that they are located in the correct cell.
        /// </summary>
        /// <param name="cellIndex"></param>
        /// <param name="vegetationItemID"></param>
        public void RepositionCellItems(int cellIndex, string vegetationItemID)
        {
            PersistentVegetationInfo persistentVegetationInfo = PersistentVegetationStoragePackage.PersistentVegetationCellList[cellIndex].GetPersistentVegetationInfo(vegetationItemID);

            if (persistentVegetationInfo == null)
            {
                return;
            }

            List <PersistentVegetationItem> origialItemList = new List <PersistentVegetationItem>();

            origialItemList.AddRange(persistentVegetationInfo.VegetationItemList);
            persistentVegetationInfo.ClearCell();

            for (int i = 0; i <= origialItemList.Count - 1; i++)
            {
                AddVegetationItemInstance(vegetationItemID, origialItemList[i].Position + VegetationSystemPro.VegetationSystemPosition, origialItemList[i].Scale,
                                          origialItemList[i].Rotation, false, origialItemList[i].VegetationSourceID, origialItemList[i].DistanceFalloff, true);
            }

            VegetationItemIndexes indexes = VegetationSystemPro.GetVegetationItemIndexes(vegetationItemID);

            VegetationSystemPro.ClearCache(VegetationSystemPro.VegetationCellList[cellIndex], indexes.VegetationPackageIndex, indexes.VegetationItemIndex);
        }
        public void RemoveVegetationItemInstance(string vegetationItemID, Vector3 worldPosition, float minimumDistance, bool clearCellCache = false)
        {
            if (!VegetationSystemPro || !PersistentVegetationStoragePackage)
            {
                return;
            }
            Rect positionRect = new Rect(new Vector2(worldPosition.x, worldPosition.z), Vector2.zero);

            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.RemoveVegetationItemInstance(cellIndex, vegetationItemID, worldPosition - VegetationSystemPro.VegetationSystemPosition, minimumDistance);
            }
        }
 private void OnVegetationItemInvisible(ItemSelectorInstanceInfo itemSelectorInstanceInfo,
                                        VegetationItemIndexes vegetationItemIndexes, string vegetationItemID)
 {
     RuntimePrefabStorage.RemoveRuntimePrefab(itemSelectorInstanceInfo.VegetationCellIndex, itemSelectorInstanceInfo.VegetationCellItemIndex, RuntimePrefabPool);
 }