public void Execute() { Dictionary <int2, NavMeshTile> results = GCHandle.FromIntPtr(RebuiltTilesPtr).Target as Dictionary <int2, NavMeshTile>; NavMeshBuilder navMeshBuilder = new NavMeshBuilder(BuildSettings, AgentSettings); while (BuildInputs.TryDequeue(out NavMeshBuildInput buildInput)) { bool valid = navMeshBuilder.BuildSingleTile(buildInput); if (valid && navMeshBuilder.BuildResult.IsValidBuild) { if (navMeshBuilder.Tiles.TryGetValue(buildInput.TileBounds.Coord, out NavMeshTile tile)) { results[tile.Coord] = tile; } else { //UnityEngine.Debug.LogFormat("BuildResult no tile id:{0} bound:{1} vertices:{2} indices:{3}", // buildInput.TileBounds.Coord, buildInput.TileBounds.Bounds, buildInput.VerticesLength, buildInput.IndicesLength); } } else { UnityEngine.Debug.LogFormat("BuildResult: {0}", navMeshBuilder.BuildResult); } } }
public SurfaceController(SurfaceControllerConfig config, AiNavSystem system) { Config = config; AiNavSystem = system; Builder = new NavMeshBuilder(Config.BuildSettings, Config.AgentSettings); Colliders = new NativeList <PhysicsCollider>(Allocator.Persistent); TilesToBuild = new NativeQueue <NavMeshTileBounds>(Allocator.Persistent); BuildInputs = new NativeQueue <NavMeshBuildInput>(Allocator.Persistent); CurrentTileStatus = new NativeArray <int>(1, Allocator.Persistent); BoxFilters = new NativeList <BoxFilter>(Allocator.Persistent); MeshSourceMap = new MeshSourceMap(Builder.BuildSettings); TilesSavedStatus = new NativeArray <int>(1, Allocator.Persistent); TilesHandle = GCHandle.Alloc(Tiles); TilesPtr = GCHandle.ToIntPtr(TilesHandle); RebuiltTilesHandle = GCHandle.Alloc(RebuiltTiles); RebuiltTilesPtr = GCHandle.ToIntPtr(RebuiltTilesHandle); NavMesh = new AiNavMesh(Builder.BuildSettings.TileSize, Builder.BuildSettings.CellSize); bool loaded = NavMeshStoreSystem.Instance.LoadTiles(Config.SurfaceId, Tiles); foreach (NavMeshTile tile in Tiles.Values) { NavMesh.AddOrReplaceTile(tile.Data); } if (Config.CrowdEnabled) { CrowdController = new CrowdController(NavMesh, this); } HandlesToWaitFor = new NativeList <JobHandle>(Allocator.Persistent); SurfaceData.Load(this); }