/// <summary> /// Builds the entire NavMesh from the Data gathered by BuildGeometry through the Detail Mesh /// Then it creates a GameObject that has the RecastNavMesh. /// </summary> /// <returns></returns> public long BuildAllTiles(Config config, Geometry geom, int tileWidth, int tileHeight, int maxPolysPerTile, int maxTiles) { NavMesh = new Detour.NavMesh(); NavMeshParams param = new NavMeshParams() { Orig = geom.MinBounds.ToArray(), MaxPolys = maxPolysPerTile, MaxTiles = maxTiles, TileWidth = config.TileSize * config.CellSize, TileHeight = config.TileSize * config.CellSize }; NavMesh.Init(param); TileWidth = tileWidth; TileHeight = tileHeight; Config = config; Geometry = geom; Progress = 0; IsBuilding = true; Stopwatch timer = new Stopwatch(); timer.Start(); RecastVertex bmin = geom.MinBounds; RecastVertex bmax = geom.MaxBounds; float tcs = config.TileSize * config.CellSize; Total = TileWidth * TileHeight; bool canceled = false; for (int y = 0; y < TileHeight; y++) { YLoop(y, tcs, bmin, bmax); } if (!canceled) { while (Progress != Total) { canceled = EditorUtility.DisplayCancelableProgressBar("Generating...", "Generating Tile " + Progress + " of " + Total, Progress / (float)Total); if (canceled) { tokenSource.Cancel(); break; } } } Task.WaitAll(tasks.ToArray()); timer.Stop(); EditorUtility.ClearProgressBar(); IsBuilding = false; BuildGeometry(); return(timer.ElapsedMilliseconds); }
/// <summary> /// Builds the entire NavMesh from the Data gathered by BuildGeometry through the Detail Mesh /// Then it creates a GameObject that has the RecastNavMesh. /// </summary> /// <returns></returns> public long BuildAllTiles(Config config, Geometry geom, int tileWidth, int tileHeight, int maxPolysPerTile, int maxTiles) { NavMesh = new Detour.NavMesh(); NavMeshParams param = new NavMeshParams() { Orig = geom.MinBounds.ToArray(), MaxPolys = maxPolysPerTile, MaxTiles = maxTiles, TileWidth = config.TileSize*config.CellSize, TileHeight = config.TileSize*config.CellSize }; NavMesh.Init(param); TileWidth = tileWidth; TileHeight = tileHeight; Config = config; Geometry = geom; Progress = 0; IsBuilding = true; Stopwatch timer = new Stopwatch(); timer.Start(); RecastVertex bmin = geom.MinBounds; RecastVertex bmax = geom.MaxBounds; float tcs = config.TileSize * config.CellSize; Total = TileWidth * TileHeight; bool canceled = false; for (int y = 0; y < TileHeight; y++) { YLoop(y, tcs, bmin, bmax); } #if UNITY_EDITOR if (!canceled) { while (Progress != Total) { canceled = EditorUtility.DisplayCancelableProgressBar("Generating...", "Generating Tile " + Progress + " of " + Total, Progress/(float) Total); if (canceled) { tokenSource.Cancel(); break; } } } Task.WaitAll(tasks.ToArray()); timer.Stop(); EditorUtility.ClearProgressBar(); #endif IsBuilding = false; BuildGeometry(); return timer.ElapsedMilliseconds; }