/// <summary> /// Retrieve the endpoints of the offmesh connection at the specified polygon /// </summary> /// <param name="prevRef">The previous polygon reference</param> /// <param name="polyRef">The current polygon reference</param> /// <param name="startPos">The starting position</param> /// <param name="endPos">The ending position</param> /// <returns>True if endpoints found, false if not</returns> public bool GetOffMeshConnectionPolyEndPoints(NavPolyId prevRef, NavPolyId polyRef, ref Vector3 startPos, ref Vector3 endPos) { int salt = 0, indexTile = 0, indexPoly = 0; if (polyRef == NavPolyId.Null) { return(false); } //get current polygon idManager.Decode(ref polyRef, out indexPoly, out indexTile, out salt); if (indexTile >= maxTiles) { return(false); } if (tileList[indexTile].Salt != salt) { return(false); } NavTile tile = tileList[indexTile]; if (indexPoly >= tile.PolyCount) { return(false); } NavPoly poly = tile.Polys[indexPoly]; if (poly.PolyType != NavPolyType.OffMeshConnection) { return(false); } int idx0 = 0, idx1 = 1; //find the link that points to the first vertex foreach (Link link in poly.Links) { if (link.Edge == 0) { if (link.Reference != prevRef) { idx0 = 1; idx1 = 0; } break; } } startPos = tile.Verts[poly.Verts[idx0]]; endPos = tile.Verts[poly.Verts[idx1]]; return(true); }
/// <summary> /// Retrieve the tile and poly based off of a polygon reference /// </summary> /// <param name="reference">Polygon reference</param> /// <param name="tile">Resulting tile</param> /// <param name="poly">Resulting poly</param> /// <returns>True if tile and poly successfully retrieved</returns> public bool TryGetTileAndPolyByRef(NavPolyId reference, out NavTile tile, out NavPoly poly) { tile = null; poly = null; if (reference == NavPolyId.Null) { return(false); } //Get tile and poly indices int salt, polyIndex, tileIndex; idManager.Decode(ref reference, out polyIndex, out tileIndex, out salt); //Make sure indices are valid if (tileIndex >= maxTiles) { return(false); } NavTile foundTile; if (!tileIndices.TryGetValue(tileIndex, out foundTile)) { return(false); } if (foundTile.Salt != salt) { return(false); } if (polyIndex >= foundTile.PolyCount) { return(false); } //Retrieve tile and poly tile = tileIndices[tileIndex]; poly = tileIndices[tileIndex].Polys[polyIndex]; return(true); }