summaryrefslogtreecommitdiff
path: root/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Navmesh/NavmeshTile.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Navmesh/NavmeshTile.cs')
-rw-r--r--Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Navmesh/NavmeshTile.cs106
1 files changed, 106 insertions, 0 deletions
diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Navmesh/NavmeshTile.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Navmesh/NavmeshTile.cs
new file mode 100644
index 0000000..fd5adc7
--- /dev/null
+++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Navmesh/NavmeshTile.cs
@@ -0,0 +1,106 @@
+namespace Pathfinding.Graphs.Navmesh {
+ using Pathfinding.Util;
+ using Unity.Collections;
+
+ /// <summary>
+ /// A single tile in a recast or navmesh graph.
+ ///
+ /// A tile is a single rectangular (but usually square) part of the graph.
+ /// Tiles can be updated individually, which is great for large worlds where updating the whole graph would take a long time.
+ /// </summary>
+ public class NavmeshTile : INavmeshHolder {
+ /// <summary>
+ /// All vertices in the tile.
+ /// The vertices are in graph space.
+ ///
+ /// This represents an allocation using the Persistent allocator.
+ /// </summary>
+ public UnsafeSpan<Int3> vertsInGraphSpace;
+ /// <summary>
+ /// All vertices in the tile.
+ /// The vertices are in world space.
+ ///
+ /// This represents an allocation using the Persistent allocator.
+ /// </summary>
+ public UnsafeSpan<Int3> verts;
+ /// <summary>
+ /// All triangle indices in the tile.
+ /// One triangle is 3 indices.
+ /// The triangles are in the same order as the <see cref="nodes"/>.
+ ///
+ /// This represents an allocation using the Persistent allocator.
+ /// </summary>
+ public UnsafeSpan<int> tris;
+
+ /// <summary>Tile X Coordinate</summary>
+ public int x;
+
+ /// <summary>Tile Z Coordinate</summary>
+ public int z;
+
+ /// <summary>
+ /// Width, in tile coordinates.
+ /// Warning: Widths other than 1 are not supported. This is mainly here for possible future features.
+ /// </summary>
+ public int w;
+
+ /// <summary>
+ /// Depth, in tile coordinates.
+ /// Warning: Depths other than 1 are not supported. This is mainly here for possible future features.
+ /// </summary>
+ public int d;
+
+ /// <summary>All nodes in the tile</summary>
+ public TriangleMeshNode[] nodes;
+
+ /// <summary>Bounding Box Tree for node lookups</summary>
+ public BBTree bbTree;
+
+ /// <summary>Temporary flag used for batching</summary>
+ public bool flag;
+
+ /// <summary>The graph which contains this tile</summary>
+ public NavmeshBase graph;
+
+ #region INavmeshHolder implementation
+
+ public void GetTileCoordinates (int tileIndex, out int x, out int z) {
+ x = this.x;
+ z = this.z;
+ }
+
+ public int GetVertexArrayIndex (int index) {
+ return index & NavmeshBase.VertexIndexMask;
+ }
+
+ /// <summary>Get a specific vertex in the tile</summary>
+ public Int3 GetVertex (int index) {
+ int idx = index & NavmeshBase.VertexIndexMask;
+
+ return verts[idx];
+ }
+
+ public Int3 GetVertexInGraphSpace (int index) {
+ return vertsInGraphSpace[index & NavmeshBase.VertexIndexMask];
+ }
+
+ /// <summary>Transforms coordinates from graph space to world space</summary>
+ public GraphTransform transform { get { return graph.transform; } }
+
+ #endregion
+
+ public void GetNodes (System.Action<GraphNode> action) {
+ if (nodes == null) return;
+ for (int i = 0; i < nodes.Length; i++) action(nodes[i]);
+ }
+
+ public void Dispose () {
+ unsafe {
+ bbTree.Dispose();
+ vertsInGraphSpace.Free(Allocator.Persistent);
+ verts.Free(Allocator.Persistent);
+ tris.Free(Allocator.Persistent);
+ }
+ }
+ }
+}