From 8722a9920c1f6119bf6e769cba270e63097f8e25 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Thu, 23 May 2024 10:08:29 +0800 Subject: + astar project --- .../Graphs/Navmesh/NavmeshTile.cs | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Navmesh/NavmeshTile.cs (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Navmesh/NavmeshTile.cs') 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; + + /// + /// 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. + /// + public class NavmeshTile : INavmeshHolder { + /// + /// All vertices in the tile. + /// The vertices are in graph space. + /// + /// This represents an allocation using the Persistent allocator. + /// + public UnsafeSpan vertsInGraphSpace; + /// + /// All vertices in the tile. + /// The vertices are in world space. + /// + /// This represents an allocation using the Persistent allocator. + /// + public UnsafeSpan verts; + /// + /// All triangle indices in the tile. + /// One triangle is 3 indices. + /// The triangles are in the same order as the . + /// + /// This represents an allocation using the Persistent allocator. + /// + public UnsafeSpan tris; + + /// Tile X Coordinate + public int x; + + /// Tile Z Coordinate + public int z; + + /// + /// Width, in tile coordinates. + /// Warning: Widths other than 1 are not supported. This is mainly here for possible future features. + /// + public int w; + + /// + /// Depth, in tile coordinates. + /// Warning: Depths other than 1 are not supported. This is mainly here for possible future features. + /// + public int d; + + /// All nodes in the tile + public TriangleMeshNode[] nodes; + + /// Bounding Box Tree for node lookups + public BBTree bbTree; + + /// Temporary flag used for batching + public bool flag; + + /// The graph which contains this tile + 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; + } + + /// Get a specific vertex in the tile + public Int3 GetVertex (int index) { + int idx = index & NavmeshBase.VertexIndexMask; + + return verts[idx]; + } + + public Int3 GetVertexInGraphSpace (int index) { + return vertsInGraphSpace[index & NavmeshBase.VertexIndexMask]; + } + + /// Transforms coordinates from graph space to world space + public GraphTransform transform { get { return graph.transform; } } + + #endregion + + public void GetNodes (System.Action 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); + } + } + } +} -- cgit v1.1-26-g67d0