private void DisposeVegetationCells() { _prepareVegetationHandle.Complete(); for (int i = 0; i <= VegetationCellList.Count - 1; i++) { VegetationCellList[i].Dispose(); } VegetationCellList.Clear(); }
private void CreateVegetationCells() { DisposeVegetationCells(); Bounds expandedBounds = new Bounds(VegetationSystemBounds.center, VegetationSystemBounds.size); expandedBounds.Expand(new Vector3(VegetationCellSize * 2f, 0, VegetationCellSize * 2f)); Rect expandedRect = RectExtension.CreateRectFromBounds(expandedBounds); VegetationCellQuadTree = new QuadTree <VegetationCell>(expandedRect); int cellXCount = Mathf.CeilToInt(VegetationSystemBounds.size.x / VegetationCellSize); int cellZCount = Mathf.CeilToInt(VegetationSystemBounds.size.z / VegetationCellSize); Vector2 corner = new Vector2(VegetationSystemBounds.center.x - VegetationSystemBounds.size.x / 2f, VegetationSystemBounds.center.z - VegetationSystemBounds.size.z / 2f); for (int x = 0; x <= cellXCount - 1; x++) { for (int z = 0; z <= cellZCount - 1; z++) { VegetationCell vegetationCell = new VegetationCell(new Rect( new Vector2(VegetationCellSize * x + corner.x, VegetationCellSize * z + corner.y), new Vector2(VegetationCellSize, VegetationCellSize))); VegetationCellList.Add(vegetationCell); vegetationCell.Index = VegetationCellList.Count - 1; VegetationCellQuadTree.Insert(vegetationCell); } } LoadedVegetationCellList.Clear(); LoadedVegetationCellList.Capacity = VegetationCellList.Count; NativeArray <Bounds> vegetationCellBounds = new NativeArray <Bounds>(VegetationCellList.Count, Allocator.Persistent); for (int i = 0; i <= VegetationCellList.Count - 1; i++) { vegetationCellBounds[i] = VegetationCellList[i].VegetationCellBounds; } float minBoundsHeight = VegetationSystemBounds.center.y - VegetationSystemBounds.extents.y; float worldspaceSealevel = minBoundsHeight + SeaLevel; if (!ExcludeSeaLevelCells) { worldspaceSealevel = minBoundsHeight; } JobHandle jobHandle = default(JobHandle); for (int i = 0; i <= VegetationStudioTerrainList.Count - 1; i++) { jobHandle = VegetationStudioTerrainList[i] .SampleCellHeight(vegetationCellBounds, worldspaceSealevel, expandedRect, jobHandle); } jobHandle.Complete(); for (int i = 0; i <= VegetationCellList.Count - 1; i++) { VegetationCellList[i].VegetationCellBounds = vegetationCellBounds[i]; } vegetationCellBounds.Dispose(); PrepareVegetationCells(); VegetationStudioManager.OnVegetationCellRefresh(this); }