protected virtual void OnCellExplored(ExploreCell cell) { if (cell == null) { return; } cell.Explored = true; // this is safe as explore cells cannot be added/removed now m_Navmesh.Log("[Nav] Explored cell " + cell.GlobalId + " [progress: " + GetExploredPercent() + "%]!"); }
public virtual void OnGridCellAdded(GridCell grid_cell) { using (new ReadLock(DataLock, true)) { // remove explore cells overlapping with grid cell var cells_to_validate = m_ExploreCells.Where(x => x.Overlaps2D(grid_cell)).ToList(); using (new WriteLock(DataLock)) { foreach (ExploreCell explore_cell in cells_to_validate) { explore_cell.Detach(); m_ExploreCells.Remove(explore_cell); } } // check if new explore cells should be added int x_min = (int)Math.Floor(grid_cell.Min.X / ExploreCellSize); int y_min = (int)Math.Floor(grid_cell.Min.Y / ExploreCellSize); int x_max = (int)Math.Ceiling(grid_cell.Max.X / ExploreCellSize); int y_max = (int)Math.Ceiling(grid_cell.Max.Y / ExploreCellSize); int explore_cells_generated = 0; for (int y_index = y_min; y_index < y_max; ++y_index) { for (int x_index = x_min; x_index < x_max; ++x_index) { AABB cell_aabb = new AABB(x_index * ExploreCellSize, y_index * ExploreCellSize, -10000, (x_index + 1) * ExploreCellSize, (y_index + 1) * ExploreCellSize, 10000); //using (new Profiler("[Nav] Explore cells generated [%t]")) { explore_cells_generated += GenerateExploreCells(cell_aabb); } } } if (explore_cells_generated > 0) { m_Navmesh.Log("[Nav] " + explore_cells_generated + " explore cell(s) generated"); } } }