internal bool InitializeBuild(BuildContext context, bool fromTarget) { Navmesh navmesh = null; if (fromTarget) { if (!CanLoadFromTarget(context, true)) { return(false); } navmesh = BuildTarget.GetNavmesh(); SetConfigFromTargetIntern(navmesh); } mIsDirty = true; // Note: If loading from the target, the tile size was already validated. // So it won't trigger this adjustment. if (mConfig.TileSize != 0 && mConfig.TileSize < MinAllowedTileSize) { string msg = string.Format("Tile size too small. Reverting tile size from" + " {0} to 0 (non-tiled). Minimum tile size is {1}" , mConfig.TileSize, MinAllowedTileSize); context.LogWarning(msg, this); mConfig.TileSize = 0; } if (mConfig.TileSize == 0) { mBuildData.Resize(1, 1); } else { // Need to check to see if the the build is truly tiled. int w; int d = 0; if (navmesh == null) { NMGen.DeriveSizeOfTileGrid(mBoundsMin.ToVector3(), mBoundsMax.ToVector3() , mConfig.XZCellSize, mConfig.TileSize , out w, out d); } else { // Existing navmesh will always be tiled. w = 2; } if (w > 1 || d > 1) { mTileSet = TileSetDefinition.Create(mBoundsMin.ToVector3(), mBoundsMax.ToVector3() , mConfig.GetConfig() , mInputGeom); if (mTileSet == null) { context.LogError("Create tile build definition: Unexpected error." + " Invalid input data or configuration." , this); return(false); } mBuildData.Resize(mTileSet.Width, mTileSet.Depth); } else { // Not really tiled. mBuildData.Resize(1, 1); } } if (navmesh != null) { // Need to load the tiles from existing navmesh. NavmeshTileExtract[] tiles; NavmeshParams meshConfig; NavStatus status = Navmesh.ExtractTileData(navmesh.GetSerializedMesh() , out tiles , out meshConfig); if ((status & NavStatus.Failure) != 0) { context.LogError("Could not extract the tile data from the target's" + " navigation mesh. (Can't initialize from build target.)" , this); return(false); } foreach (NavmeshTileExtract tile in tiles) { int polyCount = tile.header.polyCount; if (polyCount == 0) { continue; } int tx = tile.header.tileX; int tz = tile.header.tileZ; if (tx >= mBuildData.Width || tz >= mBuildData.Depth) { // Shouldn't happen. Probably indicates in internal error // of some type. string msg = string.Format("The existing navigation mesh" + " contains a tile outside the expected range. Ignoring" + " the tile. (Tile: [{0},{1}])" , tx, tz); context.LogWarning(msg, this); continue; } mBuildData.SetAsBaked(tx, tz, tile.data, polyCount); } } // Note: Dirty state was set earlier in the code. return(true); }