NavmeshTile.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. namespace Pathfinding {
  2. using Pathfinding.Util;
  3. using UnityEngine;
  4. public class NavmeshTile : INavmeshHolder {
  5. /// <summary>Tile triangles</summary>
  6. public int[] tris;
  7. /// <summary>Tile vertices</summary>
  8. public Int3[] verts;
  9. /// <summary>Tile vertices in graph space</summary>
  10. public Int3[] vertsInGraphSpace;
  11. /// <summary>Tile X Coordinate</summary>
  12. public int x;
  13. /// <summary>Tile Z Coordinate</summary>
  14. public int z;
  15. /// <summary>
  16. /// Width, in tile coordinates.
  17. /// Warning: Widths other than 1 are not supported. This is mainly here for possible future features.
  18. /// </summary>
  19. public int w;
  20. /// <summary>
  21. /// Depth, in tile coordinates.
  22. /// Warning: Depths other than 1 are not supported. This is mainly here for possible future features.
  23. /// </summary>
  24. public int d;
  25. /// <summary>All nodes in the tile</summary>
  26. public TriangleMeshNode[] nodes;
  27. /// <summary>Bounding Box Tree for node lookups</summary>
  28. public BBTree bbTree;
  29. /// <summary>Temporary flag used for batching</summary>
  30. public bool flag;
  31. public NavmeshBase graph;
  32. #region INavmeshHolder implementation
  33. public void GetTileCoordinates (int tileIndex, out int x, out int z) {
  34. x = this.x;
  35. z = this.z;
  36. }
  37. public int GetVertexArrayIndex (int index) {
  38. return index & NavmeshBase.VertexIndexMask;
  39. }
  40. /// <summary>Get a specific vertex in the tile</summary>
  41. public Int3 GetVertex (int index) {
  42. int idx = index & NavmeshBase.VertexIndexMask;
  43. return verts[idx];
  44. }
  45. public Int3 GetVertexInGraphSpace (int index) {
  46. return vertsInGraphSpace[index & NavmeshBase.VertexIndexMask];
  47. }
  48. /// <summary>Transforms coordinates from graph space to world space</summary>
  49. public GraphTransform transform { get { return graph.transform; } }
  50. #endregion
  51. public void GetNodes (System.Action<GraphNode> action) {
  52. if (nodes == null) return;
  53. for (int i = 0; i < nodes.Length; i++) action(nodes[i]);
  54. }
  55. }
  56. }