A* Pathfinding Project
4.1.6
The A* Pathfinding Project for Unity 3D
|
Base class for RecastGraph and NavMeshGraph. More...
Base class for RecastGraph and NavMeshGraph.
Public Member Functions | |
abstract GraphTransform | CalculateTransform () |
Returns a new transform which transforms graph space to world space. | |
void | EndBatchTileUpdate () |
End batch updating of tiles. | |
override NNInfoInternal | GetNearest (Vector3 position, NNConstraint constraint, GraphNode hint) |
Returns the nearest node to a position using the specified NNConstraint. | |
override NNInfoInternal | GetNearestForce (Vector3 position, NNConstraint constraint) |
Returns the nearest node to a position using the specified constraint . | |
override void | GetNodes (System.Action< GraphNode > action) |
Calls a delegate with all nodes in the graph. | |
NavmeshTile | GetTile (int x, int z) |
Tile at the specified x, z coordinate pair. | |
Bounds | GetTileBounds (IntRect rect) |
Returns an XZ bounds object with the bounds of a group of tiles. | |
Bounds | GetTileBounds (int x, int z, int width=1, int depth=1) |
Returns an XZ bounds object with the bounds of a group of tiles. | |
Bounds | GetTileBoundsInGraphSpace (IntRect rect) |
Bounds | GetTileBoundsInGraphSpace (int x, int z, int width=1, int depth=1) |
Returns an XZ bounds object with the bounds of a group of tiles in graph space. | |
void | GetTileCoordinates (int tileIndex, out int x, out int z) |
Tile coordinates from a tile index. | |
Int2 | GetTileCoordinates (Vector3 position) |
Returns the tile coordinate which contains the specified position. | |
NavmeshTile[] | GetTiles () |
All tiles. | |
IntRect | GetTouchingTiles (Bounds bounds) |
Returns a rect containing the indices of all tiles touching the specified bounds. | |
IntRect | GetTouchingTilesInGraphSpace (Rect rect) |
Returns a rect containing the indices of all tiles touching the specified bounds. | |
IntRect | GetTouchingTilesRound (Bounds bounds) |
Returns a rect containing the indices of all tiles by rounding the specified bounds to tile borders. | |
Int3 | GetVertex (int index) |
Vertex coordinate for the specified vertex index. | |
int | GetVertexArrayIndex (int index) |
Int3 | GetVertexInGraphSpace (int index) |
Vertex coordinate in graph space for the specified vertex index. | |
bool | Linecast (Vector3 origin, Vector3 end) |
Returns if there is an obstacle between origin and end on the graph. | |
bool | Linecast (Vector3 origin, Vector3 end, GraphNode hint, out GraphHitInfo hit) |
Returns if there is an obstacle between origin and end on the graph. | |
bool | Linecast (Vector3 origin, Vector3 end, GraphNode hint) |
Returns if there is an obstacle between origin and end on the graph. | |
bool | Linecast (Vector3 origin, Vector3 end, GraphNode hint, out GraphHitInfo hit, List< GraphNode > trace) |
Returns if there is an obstacle between origin and end on the graph. | |
override void | OnDrawGizmos (Pathfinding.Util.RetainedGizmos gizmos, bool drawNodes) |
GraphNode | PointOnNavmesh (Vector3 position, NNConstraint constraint) |
Finds the first node which contains position. | |
override void | RelocateNodes (Matrix4x4 deltaMatrix) |
Moves the nodes in this graph. | |
void | RelocateNodes (GraphTransform newTransform) |
Moves the nodes in this graph. | |
void | ReplaceTile (int x, int z, Int3[] verts, int[] tris) |
Replace tile at index with nodes created from specified navmesh. | |
void | ReplaceTile (int x, int z, int w, int d, Int3[] verts, int[] tris) |
Replaces a tile with a new mesh. | |
void | StartBatchTileUpdate () |
Start batch updating of tiles. | |
Public Member Functions inherited from NavGraph | |
virtual int | CountNodes () |
Number of nodes in the graph. | |
NNInfoInternal | GetNearest (Vector3 position) |
Returns the nearest node to a position using the default NNConstraint. | |
NNInfoInternal | GetNearest (Vector3 position, NNConstraint constraint) |
Returns the nearest node to a position using the specified NNConstraint. | |
void | GetNodes (System.Func< GraphNode, bool > action) |
Calls a delegate with all nodes in the graph until the delegate returns false. | |
virtual void | OnDrawGizmos (RetainedGizmos gizmos, bool drawNodes) |
Draw gizmos for the graph. | |
void | RelocateNodes (Matrix4x4 oldMatrix, Matrix4x4 newMatrix) |
Moves nodes in this graph. | |
void | Scan () |
Scan the graph. | |
void | ScanGraph () |
Scan the graph. | |
void | SetMatrix (Matrix4x4 m) |
Use to set both matrix and inverseMatrix at the same time. | |
Public Member Functions inherited from IGraphInternals | |
void | DeserializeExtraInfo (GraphSerializationContext ctx) |
void | DeserializeSettingsCompatibility (GraphSerializationContext ctx) |
void | DestroyAllNodes () |
void | OnDestroy () |
void | PostDeserialization (GraphSerializationContext ctx) |
IEnumerable< Progress > | ScanInternal () |
void | SerializeExtraInfo (GraphSerializationContext ctx) |
Public Member Functions inherited from INavmesh | |
void | GetNodes (System.Action< GraphNode > del) |
Public Member Functions inherited from INavmeshHolder | |
void | GetTileCoordinates (int tileIndex, out int x, out int z) |
Transforms coordinates from graph space to world space. | |
Int3 | GetVertex (int i) |
Position of vertex number i in the world. | |
int | GetVertexArrayIndex (int index) |
Int3 | GetVertexInGraphSpace (int i) |
Position of vertex number i in coordinates local to the graph. | |
Static Public Member Functions | |
static int | GetTileIndex (int index) |
Tile index from a vertex index. | |
static bool | Linecast (NavmeshBase graph, Vector3 origin, Vector3 end, GraphNode hint, out GraphHitInfo hit) |
Returns if there is an obstacle between origin and end on the graph. | |
static bool | Linecast (NavmeshBase graph, Vector3 origin, Vector3 end, GraphNode hint, out GraphHitInfo hit, List< GraphNode > trace) |
Returns if there is an obstacle between origin and end on the graph. | |
Public Attributes | |
Vector3 | forcedBoundsSize = new Vector3(100, 40, 100) |
Size of the bounding box. | |
bool | nearestSearchOnlyXZ |
Perform nearest node searches in XZ space only. | |
System.Action< NavmeshTile[]> | OnRecalculatedTiles |
Called when tiles have been completely recalculated. | |
bool | showMeshOutline = true |
Show an outline of the polygons in the Unity Editor. | |
bool | showMeshSurface |
Show the surface of the navmesh. | |
bool | showNodeConnections |
Show the connections between the polygons in the Unity Editor. | |
const int | TileIndexMask = 0x7FFFF |
const int | TileIndexOffset = 12 |
int | tileXCount |
Number of tiles along the X-axis. | |
int | tileZCount |
Number of tiles along the Z-axis. | |
GraphTransform | transform = new GraphTransform(Matrix4x4.identity) |
Determines how the graph transforms graph space to world space. | |
const int | VertexIndexMask = 0xFFF |
Public Attributes inherited from NavGraph | |
AstarPath | active |
Reference to the AstarPath object in the scene. | |
bool | drawGizmos = true |
Enable to draw gizmos in the Unity scene view. | |
uint | graphIndex |
Index of the graph, used for identification purposes. | |
Guid | guid |
Used as an ID of the graph, considered to be unique. | |
bool | infoScreenOpen |
Used in the editor to check if the info screen is open. | |
uint | initialPenalty |
Default penalty to apply to all nodes. | |
Matrix4x4 | inverseMatrix = Matrix4x4.identity |
Inverse of matrix. | |
Matrix4x4 | matrix = Matrix4x4.identity |
A matrix for translating/rotating/scaling the graph. | |
string | name |
Name of the graph. | |
bool | open |
Is the graph open in the editor. | |
Protected Member Functions | |
void | ClearTiles (int x, int z, int w, int d) |
Clear all tiles within the rectangle with one corner at (x,z), width w and depth d. | |
void | ConnectTiles (NavmeshTile tile1, NavmeshTile tile2) |
Generate connections between the two tiles. | |
void | ConnectTileWithNeighbours (NavmeshTile tile, bool onlyUnflagged=false) |
TriangleMeshNode[] | CreateNodes (int[] tris, int tileIndex, uint graphIndex) |
override void | DeserializeExtraInfo (GraphSerializationContext ctx) |
Deserializes graph type specific node data. | |
void | FillWithEmptyTiles () |
Fills graph with tiles created by NewEmptyTile. | |
NavmeshTile | NewEmptyTile (int x, int z) |
Creates a single new empty tile. | |
override void | OnDestroy () |
Function for cleaning up references. | |
override void | PostDeserialization (GraphSerializationContext ctx) |
Called after all deserialization has been done for all graphs. | |
void | RemoveConnectionsFromTile (NavmeshTile tile) |
void | RemoveConnectionsFromTo (NavmeshTile a, NavmeshTile b) |
override void | SerializeExtraInfo (GraphSerializationContext ctx) |
Serializes Node Info. | |
Protected Member Functions inherited from NavGraph | |
virtual void | DeserializeSettingsCompatibility (GraphSerializationContext ctx) |
An old format for serializing settings. | |
virtual void | DestroyAllNodes () |
Destroys all nodes in the graph. | |
void | DrawUnwalkableNodes (float size) |
abstract IEnumerable< Progress > | ScanInternal () |
Internal method to scan the graph. | |
Static Protected Member Functions | |
static void | CreateNodeConnections (TriangleMeshNode[] nodes) |
Create connections between all nodes. | |
Protected Attributes | |
NavmeshTile[] | tiles |
All tiles. | |
Properties | |
abstract float | MaxTileConnectionEdgeDistance [get] |
Maximum (vertical) distance between the sides of two nodes for them to be connected across a tile edge. | |
abstract float | TileWorldSizeX [get] |
Size of a tile in world units along the X axis. | |
abstract float | TileWorldSizeZ [get] |
Size of a tile in world units along the Z axis. | |
GraphTransform ITransformedGraph. | transform [get] |
Properties inherited from NavGraph | |
bool | exists [get] |
True if the graph exists, false if it has been destroyed. | |
Properties inherited from ITransformedGraph | |
GraphTransform | transform [get] |
Private Member Functions | |
void | CreateNavmeshSurfaceVisualization (NavmeshTile tile, GraphGizmoHelper helper) |
Creates a mesh of the surfaces of the navmesh for use in OnDrawGizmos in the editor. | |
Static Private Member Functions | |
static void | CreateNavmeshOutlineVisualization (NavmeshTile tile, GraphGizmoHelper helper) |
Creates an outline of the navmesh for use in OnDrawGizmos in the editor. | |
Private Attributes | |
bool | batchTileUpdate |
Currently updating tiles in a batch. | |
List< int > | batchUpdatedTiles = new List<int>() |
List of tiles updating during batch. | |
Static Private Attributes | |
static readonly NNConstraint | NNConstraintDistanceXZ = new NNConstraint { distanceXZ = true } |
|
pure virtual |
Returns a new transform which transforms graph space to world space.
Does not update the transform field.
Implemented in RecastGraph, and NavMeshGraph.
|
protected |
Clear all tiles within the rectangle with one corner at (x,z), width w and depth d.
|
protected |
Generate connections between the two tiles.
The tiles must be adjacent.
|
protected |
|
staticprivate |
Creates an outline of the navmesh for use in OnDrawGizmos in the editor.
|
private |
Creates a mesh of the surfaces of the navmesh for use in OnDrawGizmos in the editor.
|
staticprotected |
Create connections between all nodes.
|
protected |
|
protectedvirtual |
void EndBatchTileUpdate | ( | ) |
End batch updating of tiles.
During batch updating, tiles will not be connected if they are updating with ReplaceTile. When ending batching, all affected tiles will be connected. This is faster than not using batching.
|
protected |
Fills graph with tiles created by NewEmptyTile.
|
virtual |
Returns the nearest node to a position using the specified NNConstraint.
position | The position to try to find a close node to |
hint | Can be passed to enable some graph generators to find the nearest node faster. |
constraint | Can for example tell the function to try to return a walkable node. If you do not get a good node back, consider calling GetNearestForce. |
Reimplemented from NavGraph.
|
virtual |
Returns the nearest node to a position using the specified constraint .
Reimplemented from NavGraph.
|
virtual |
Calls a delegate with all nodes in the graph.
This is the primary way of iterating through all nodes in a graph.
Do not change the graph structure inside the delegate.
If you want to store all nodes in a list you can do this
Implements NavGraph.
NavmeshTile GetTile | ( | int | x, |
int | z | ||
) |
Tile at the specified x, z coordinate pair.
The first tile is at (0,0), the last tile at (tileXCount-1, tileZCount-1).
Bounds GetTileBounds | ( | IntRect | rect | ) |
Returns an XZ bounds object with the bounds of a group of tiles.
The bounds object is defined in world units.
Bounds GetTileBounds | ( | int | x, |
int | z, | ||
int | width = 1 , |
||
int | depth = 1 |
||
) |
Returns an XZ bounds object with the bounds of a group of tiles.
The bounds object is defined in world units.
Bounds GetTileBoundsInGraphSpace | ( | IntRect | rect | ) |
Bounds GetTileBoundsInGraphSpace | ( | int | x, |
int | z, | ||
int | width = 1 , |
||
int | depth = 1 |
||
) |
Returns an XZ bounds object with the bounds of a group of tiles in graph space.
void GetTileCoordinates | ( | int | tileIndex, |
out int | x, | ||
out int | z | ||
) |
Tile coordinates from a tile index.
Int2 GetTileCoordinates | ( | Vector3 | position | ) |
Returns the tile coordinate which contains the specified position.
It is not necessarily a valid tile (i.e it could be out of bounds).
|
static |
Tile index from a vertex index.
NavmeshTile [] GetTiles | ( | ) |
All tiles.
IntRect GetTouchingTiles | ( | Bounds | bounds | ) |
Returns a rect containing the indices of all tiles touching the specified bounds.
IntRect GetTouchingTilesInGraphSpace | ( | Rect | rect | ) |
Returns a rect containing the indices of all tiles touching the specified bounds.
rect | Graph space rectangle (in graph space all tiles are on the XZ plane regardless of graph rotation and other transformations, the first tile has a corner at the origin) |
IntRect GetTouchingTilesRound | ( | Bounds | bounds | ) |
Returns a rect containing the indices of all tiles by rounding the specified bounds to tile borders.
This is different from GetTouchingTiles in that the tiles inside the rectangle returned from this method may not contain the whole bounds, while that is guaranteed for GetTouchingTiles.
Int3 GetVertex | ( | int | index | ) |
Vertex coordinate for the specified vertex index.
IndexOutOfRangeException | if the vertex index is invalid. |
NullReferenceException | if the tile the vertex is in is not calculated. |
int GetVertexArrayIndex | ( | int | index | ) |
Int3 GetVertexInGraphSpace | ( | int | index | ) |
Vertex coordinate in graph space for the specified vertex index.
bool Linecast | ( | Vector3 | origin, |
Vector3 | end | ||
) |
Returns if there is an obstacle between origin and end on the graph.
This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions instead of checking for collider intersection.
bool Linecast | ( | Vector3 | origin, |
Vector3 | end, | ||
GraphNode | hint, | ||
out GraphHitInfo | hit | ||
) |
Returns if there is an obstacle between origin and end on the graph.
[in] | origin | Point to linecast from |
[in] | end | Point to linecast to |
[out] | hit | Contains info on what was hit, see GraphHitInfo |
[in] | hint | You need to pass the node closest to the start point |
This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions instead of checking for collider intersection.
bool Linecast | ( | Vector3 | origin, |
Vector3 | end, | ||
GraphNode | hint | ||
) |
Returns if there is an obstacle between origin and end on the graph.
[in] | origin | Point to linecast from |
[in] | end | Point to linecast to |
[in] | hint | You need to pass the node closest to the start point |
This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions instead of checking for collider intersection.
bool Linecast | ( | Vector3 | origin, |
Vector3 | end, | ||
GraphNode | hint, | ||
out GraphHitInfo | hit, | ||
List< GraphNode > | trace | ||
) |
Returns if there is an obstacle between origin and end on the graph.
[in] | origin | Point to linecast from |
[in] | end | Point to linecast to |
[out] | hit | Contains info on what was hit, see GraphHitInfo |
[in] | hint | You need to pass the node closest to the start point |
trace | If a list is passed, then it will be filled with all nodes the linecast traverses |
This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions instead of checking for collider intersection.
|
static |
Returns if there is an obstacle between origin and end on the graph.
[in] | graph | The graph to perform the search on |
[in] | origin | Point to start from |
[in] | end | Point to linecast to |
[out] | hit | Contains info on what was hit, see GraphHitInfo |
[in] | hint | You need to pass the node closest to the start point, if null, a search for the closest node will be done |
This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions instead of checking for collider intersection.
|
static |
Returns if there is an obstacle between origin and end on the graph.
[in] | graph | The graph to perform the search on |
[in] | origin | Point to start from |
[in] | end | Point to linecast to |
[out] | hit | Contains info on what was hit, see GraphHitInfo |
[in] | hint | You need to pass the node closest to the start point, if null, a search for the closest node will be done |
trace | If a list is passed, then it will be filled with all nodes the linecast traverses |
This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions instead of checking for collider intersection.
|
protected |
Creates a single new empty tile.
|
protectedvirtual |
Function for cleaning up references.
This will be called on the same time as OnDisable on the gameObject which the AstarPath script is attached to (remember, not in the editor). Use for any cleanup code such as cleaning up static variables which otherwise might prevent resources from being collected. Use by creating a function overriding this one in a graph class, but always call base.OnDestroy () in that function. All nodes should be destroyed in this function otherwise a memory leak will arise.
Reimplemented from NavGraph.
override void OnDrawGizmos | ( | Pathfinding.Util.RetainedGizmos | gizmos, |
bool | drawNodes | ||
) |
GraphNode PointOnNavmesh | ( | Vector3 | position, |
NNConstraint | constraint | ||
) |
Finds the first node which contains position.
"Contains" is defined as position is inside the triangle node when seen from above. So only XZ space matters. In case of a multilayered environment, which node of the possibly several nodes containing the point is undefined.
Returns null if there was no node containing the point. This serves as a quick check for "is this point on the navmesh or not".
Note that the behaviour of this method is distinct from the GetNearest method. The GetNearest method will return the closest node to a point, which is not necessarily the one which contains it in XZ space.
|
protectedvirtual |
Called after all deserialization has been done for all graphs.
Can be used to set up more graph data which is not serialized
Reimplemented from NavGraph.
|
virtual |
Moves the nodes in this graph.
Multiplies all node positions by deltaMatrix.
For example if you want to move all your nodes in e.g a point graph 10 units along the X axis from the initial position
Reimplemented from NavGraph.
void RelocateNodes | ( | GraphTransform | newTransform | ) |
Moves the nodes in this graph.
Moves all the nodes in such a way that the specified transform is the new graph space to world space transformation for the graph. You usually use this together with the CalculateTransform method.
So for example if you want to move and rotate all your nodes in e.g a recast graph you can do
This will move all the nodes to new positions as if the new graph settings had been there from the start.
|
protected |
|
protected |
void ReplaceTile | ( | int | x, |
int | z, | ||
Int3[] | verts, | ||
int[] | tris | ||
) |
Replace tile at index with nodes created from specified navmesh.
void ReplaceTile | ( | int | x, |
int | z, | ||
int | w, | ||
int | d, | ||
Int3[] | verts, | ||
int[] | tris | ||
) |
Replaces a tile with a new mesh.
This will create new nodes and link them to the adjacent tile (unless batching has been started in which case that will be done when batching ends).
The vertices are assumed to be in 'tile space', that is being in a rectangle with one corner at the origin and one at (TileWorldSizeX, 0, TileWorldSizeZ).
|
protectedvirtual |
Serializes Node Info.
Should serialize:
It is not necessary for this implementation to be forward or backwards compatible.
Reimplemented from NavGraph.
void StartBatchTileUpdate | ( | ) |
Start batch updating of tiles.
During batch updating, tiles will not be connected if they are updating with ReplaceTile. When ending batching, all affected tiles will be connected. This is faster than not using batching.
|
private |
Currently updating tiles in a batch.
|
private |
List of tiles updating during batch.
Vector3 forcedBoundsSize = new Vector3(100, 40, 100) |
Size of the bounding box.
bool nearestSearchOnlyXZ |
Perform nearest node searches in XZ space only.
Recomended for single-layered environments. Faster but can be inaccurate esp. in multilayered contexts. You should not use this if the graph is rotated since then the XZ plane no longer corresponds to the ground plane.
This can be important on sloped surfaces. See the image below:
You can also control this using a field on an NNConstraint object.
|
staticprivate |
System.Action<NavmeshTile[]> OnRecalculatedTiles |
Called when tiles have been completely recalculated.
This is called after scanning the graph and after performing graph updates that completely recalculate tiles (not ones that simply modify e.g penalties). It is not called after NavmeshCut updates.
bool showMeshOutline = true |
Show an outline of the polygons in the Unity Editor.
bool showMeshSurface |
Show the surface of the navmesh.
bool showNodeConnections |
Show the connections between the polygons in the Unity Editor.
const int TileIndexMask = 0x7FFFF |
const int TileIndexOffset = 12 |
|
protected |
All tiles.
int tileXCount |
Number of tiles along the X-axis.
int tileZCount |
Number of tiles along the Z-axis.
GraphTransform transform = new GraphTransform(Matrix4x4.identity) |
Determines how the graph transforms graph space to world space.
const int VertexIndexMask = 0xFFF |
|
getprotected |
Maximum (vertical) distance between the sides of two nodes for them to be connected across a tile edge.
When tiles are connected to each other, the nodes sometimes do not line up perfectly so some allowance must be made to allow tiles that do not match exactly to be connected with each other.
|
get |
Size of a tile in world units along the X axis.
|
get |
Size of a tile in world units along the Z axis.
|
getprivate |