public NavPolyId AddTile(NavMeshBuilder data)
{
//make sure data is in right format
PathfindingCommon.NavMeshInfo header = data.Header;
//make sure location is free
if (GetTileAt(header.X, header.Y, header.Layer) != null)
return NavPolyId.Null;
NavPolyId newTileId = GetNextTileRef();
NavTile tile = new NavTile(new Vector2i(header.X, header.Y), header.Layer, idManager, newTileId);
tile.Salt = idManager.DecodeSalt(ref newTileId);
if (header.BvNodeCount == 0)
tile.BVTree = null;
//patch header
tile.Verts = data.NavVerts;
tile.Polys = data.NavPolys;
tile.PolyCount = header.PolyCount;
tile.DetailMeshes = data.NavDMeshes;
tile.DetailVerts = data.NavDVerts;
tile.DetailTris = data.NavDTris;
tile.BVTree = data.NavBvTree;
tile.OffMeshConnections = data.OffMeshCons;
tile.OffMeshConnectionCount = header.OffMeshConCount;
tile.BvQuantFactor = header.BvQuantFactor;
tile.BvNodeCount = header.BvNodeCount;
tile.Bounds = header.Bounds;
tile.WalkableClimb = header.WalkableClimb;
//create connections within tile
tile.ConnectIntLinks();
tile.BaseOffMeshLinks();
//create connections with neighbor tiles
//connect with layers in current tile
foreach (NavTile layerTile in GetTilesAt(header.X, header.Y))
{
if (layerTile != tile)
{
tile.ConnectExtLinks(layerTile, BoundarySide.Internal);
layerTile.ConnectExtLinks(tile, BoundarySide.Internal);
}
tile.ConnectExtOffMeshLinks(layerTile, BoundarySide.Internal);
layerTile.ConnectExtOffMeshLinks(tile, BoundarySide.Internal);
}
//connect with neighbor tiles
for (int i = 0; i < 8; i++)
{
BoundarySide b = (BoundarySide)i;
BoundarySide bo = b.GetOpposite();
foreach (NavTile neighborTile in GetNeighborTilesAt(header.X, header.Y, b))
{
tile.ConnectExtLinks(neighborTile, b);
neighborTile.ConnectExtLinks(tile, bo);
tile.ConnectExtOffMeshLinks(neighborTile, b);
neighborTile.ConnectExtOffMeshLinks(tile, bo);
}
}
AddTileAt(tile, GetNextTileRef());
return newTileId;
}