A* Pathfinding Project
3.8.2
The A* Pathfinding Project for Unity 3D
|
Grid Graph, supports layered worlds. More...
Grid Graph, supports layered worlds.
The GridGraph is great in many ways, reliable, easily configured and updatable during runtime. But it lacks support for worlds which have multiple layers, such as a building with multiple floors.
That's where this graph type comes in. It supports basically the same stuff as the grid graph, but also multiple layers. It uses a more memory, and is probably a bit slower.
Public Member Functions | |
void | AddLayers (int count) |
Increases the capacity of the nodes array to hold more layers. | |
void | CalculateConnections (GraphNode[] nodes, GraphNode node, int x, int z, int layerIndex) |
Calculates the layered grid graph connections for a single node. | |
override int | CountNodes () |
Count nodes in the graph. | |
override void | DeserializeExtraInfo (GraphSerializationContext ctx) |
Deserializes graph type specific node data. | |
override void | ErodeWalkableArea (int xmin, int zmin, int xmax, int zmax) |
Erodes the walkable area. | |
override NNInfo | GetNearest (Vector3 position, NNConstraint constraint, GraphNode hint) |
Returns the nearest node to a position using the specified NNConstraint. | |
override NNInfo | GetNearestForce (Vector3 position, NNConstraint constraint) |
Returns the nearest node to a position using the specified constraint . | |
override void | GetNodes (GraphNodeDelegateCancelable del) |
Calls a delegate with all nodes in the graph. | |
override void | OnDestroy () |
This function will be called when this graph is destroyed. | |
override void | OnDrawGizmos (bool drawNodes) |
Draw gizmos for the graph. | |
override void | PostDeserialization () |
Called after all deserialization has been done for all graphs. | |
bool | RecalculateCell (int x, int z, bool preserveExistingNodes) |
Recalculates single cell. | |
override void | ScanInternal (OnScanStatus statusCallback) |
Scans the graph, called from AstarPath.ScanLoop. | |
override void | SerializeExtraInfo (GraphSerializationContext ctx) |
Serializes graph type specific node data. | |
new void | UpdateArea (GraphUpdateObject o) |
virtual void | UpdatePenalty (LevelGridNode node) |
Updates penalty for the node. | |
Public Member Functions inherited from GridGraph | |
GridGraph () | |
virtual void | CalculateConnections (GridNode[] nodes, int x, int z, GridNode node) |
Calculates the grid connections for a single node. | |
virtual void | CalculateConnections (int x, int z, GridNode node) |
Calculates the grid connections for a single node. | |
GraphUpdateThreading | CanUpdateAsync (GraphUpdateObject o) |
bool | CheckConnection (GridNode node, int dir) |
Returns if node is connected to it's neighbour in the specified direction. | |
virtual void | ErodeWalkableArea () |
Erodes the walkable area. | |
void | GenerateMatrix () |
Generates the matrix used for translating nodes from grid coordinates to world coordintes. | |
uint | GetConnectionCost (int dir) |
GridNode | GetNodeConnection (GridNode node, int dir) |
List< GraphNode > | GetNodesInArea (Bounds b) |
All nodes inside the bounding box. | |
List< GraphNode > | GetNodesInArea (GraphUpdateShape shape) |
All nodes inside the shape. | |
Int3 | GraphPointToWorld (int x, int z, float height) |
Transform a point in graph space to world space. | |
bool | HasNodeConnection (GridNode node, int dir) |
bool | HasNodeConnection (int index, int x, int z, int dir) |
virtual bool | IsValidConnection (GridNode n1, GridNode n2) |
Returns true if a connection between the adjacent nodes n1 and n2 is valid. | |
bool | Linecast (Vector3 _a, Vector3 _b) |
Returns if there is an obstacle between origin and end on the graph. | |
bool | Linecast (Vector3 _a, Vector3 _b, GraphNode hint) |
Returns if there is an obstacle between origin and end on the graph. | |
bool | Linecast (Vector3 _a, Vector3 _b, GraphNode hint, out GraphHitInfo hit) |
Returns if there is an obstacle between origin and end on the graph. | |
bool | Linecast (Vector3 _a, Vector3 _b, GraphNode hint, out GraphHitInfo hit, List< GraphNode > trace) |
Returns if there is an obstacle between _a and _b on the graph. | |
void | OnPostScan (AstarPath script) |
Auto links grid graphs together. | |
void | RelocateNodes (Vector3 center, Quaternion rotation, float nodeSize, float aspectRatio=1, float isometricAngle=0) |
Relocate the grid graph using new settings. | |
void | SetNodeConnection (GridNode node, int dir, bool value) |
void | SetNodeConnection (int index, int x, int z, int dir, bool value) |
Set if connection in the specified direction should be enabled. | |
virtual void | SetUpOffsetsAndCosts () |
Sets up neighbourOffsets with the current settings. | |
bool | SnappedLinecast (Vector3 a, Vector3 b, GraphNode hint, out GraphHitInfo hit) |
Returns if there is an obstacle between and on the graph. | |
void | UpdateArea (GraphUpdateObject o) |
Internal function to update an area of the graph. | |
void | UpdateAreaInit (GraphUpdateObject o) |
virtual void | UpdateNodePositionCollision (GridNode node, int x, int z, bool resetPenalty=true) |
Updates position, walkability and penalty for the node. | |
void | UpdateSizeFromWidthDepth () |
Updates size from width, depth and nodeSize values. | |
Public Member Functions inherited from NavGraph | |
virtual void | Awake () |
This will be called on the same time as Awake on the gameObject which the AstarPath script is attached to. | |
NNInfo | GetNearest (Vector3 position) |
Returns the nearest node to a position using the default NNConstraint. | |
NNInfo | GetNearest (Vector3 position, NNConstraint constraint) |
Returns the nearest node to a position using the specified NNConstraint. | |
virtual Color | NodeColor (GraphNode node, PathHandler data) |
virtual void | RelocateNodes (Matrix4x4 oldMatrix, Matrix4x4 newMatrix) |
Relocates the nodes in this graph. | |
void | Scan () |
void | ScanGraph () |
void | ScanInternal () |
Internal method for scanning graphs. | |
void | SetMatrix (Matrix4x4 m) |
Use to set both matrix and inverseMatrix at the same time. | |
Public Member Functions inherited from IUpdatableGraph | |
GraphUpdateThreading | CanUpdateAsync (GraphUpdateObject o) |
void | UpdateArea (GraphUpdateObject o) |
Updates an area using the specified GraphUpdateObject. | |
void | UpdateAreaInit (GraphUpdateObject o) |
Public Member Functions inherited from IRaycastableGraph | |
bool | Linecast (Vector3 start, Vector3 end) |
bool | Linecast (Vector3 start, Vector3 end, GraphNode hint) |
bool | Linecast (Vector3 start, Vector3 end, GraphNode hint, out GraphHitInfo hit) |
bool | Linecast (Vector3 start, Vector3 end, GraphNode hint, out GraphHitInfo hit, List< GraphNode > trace) |
Static Public Member Functions | |
static bool | CheckConnection (LevelGridNode node, int dir) |
Returns if node is connected to it's neighbour in the specified direction. | |
Static Public Member Functions inherited from GridGraph | |
static void | CalculateConnections (GridNode node) |
Calculates the grid connections for a single node. | |
Static Public Member Functions inherited from NavGraph | |
static bool | InSearchTree (GraphNode node, Path path) |
Returns if the node is in the search tree of the path. | |
Public Attributes | |
float | characterHeight = 0.4F |
Nodes with a short distance to the node above it will be set unwalkable. | |
int | layerCount |
Number of layers. | |
float | mergeSpanRange = 0.5F |
If two layered nodes are too close, they will be merged. | |
int[] | nodeCellIndices |
new LevelGridNode[] | nodes |
Public Attributes inherited from GridGraph | |
const int | getNearestForceOverlap = 2 |
In GetNearestForce, determines how far to search after a valid node has been found. | |
readonly uint[] | neighbourCosts = new uint[8] |
Costs to neighbour nodes. | |
readonly int[] | neighbourOffsets = new int[8] |
Index offset to get neighbour nodes. | |
readonly int[] | neighbourXOffsets = new int[8] |
Offsets in the X direction for neighbour nodes. | |
readonly int[] | neighbourZOffsets = new int[8] |
Offsets in the Z direction for neighbour nodes. | |
GridNode[] | nodes |
All nodes in this graph. | |
int | width |
Width of the grid in nodes. | |
int | depth |
Depth (height) of the grid in nodes. | |
float | aspectRatio = 1F |
Scaling of the graph along the X axis. | |
float | isometricAngle |
Angle to use for the isometric projection. | |
bool | uniformEdgeCosts |
If true, all edge costs will be set to the same value. | |
Vector3 | rotation |
Rotation of the grid in degrees. | |
Bounds | bounds |
Vector3 | center |
Center point of the grid. | |
Vector2 | unclampedSize |
Size of the grid. | |
float | nodeSize = 1 |
Size of one node in world units. | |
GraphCollision | collision |
Settings on how to check for walkability and height. | |
float | maxClimb = 0.4F |
The max position difference between two nodes to enable a connection. | |
int | maxClimbAxis = 1 |
The axis to use for maxClimb. | |
float | maxSlope = 90 |
The max slope in degrees for a node to be walkable. | |
int | erodeIterations |
Erosion of the graph. | |
bool | erosionUseTags |
Use tags instead of walkability for erosion. | |
int | erosionFirstTag = 1 |
Tag to start from when using tags for erosion. | |
bool | autoLinkGrids |
Auto link the graph's edge nodes together with other GridGraphs in the scene on Scan. | |
float | autoLinkDistLimit = 10F |
Distance limit for grid graphs to be auto linked. | |
NumNeighbours | neighbours = NumNeighbours.Eight |
Number of neighbours for each node. | |
bool | cutCorners = true |
If disabled, will not cut corners on obstacles. | |
float | penaltyPositionOffset |
Offset for the position when calculating penalty. | |
bool | penaltyPosition |
Use position (y-coordinate) to calculate penalty. | |
float | penaltyPositionFactor = 1F |
Scale factor for penalty when calculating from position. | |
bool | penaltyAngle |
float | penaltyAngleFactor = 100F |
How much penalty is applied depending on the slope of the terrain. | |
float | penaltyAnglePower = 1 |
How much extra to penalize very steep angles. | |
bool | useJumpPointSearch |
TextureData | textureData = new TextureData() |
Holds settings for using a texture as source for a grid graph. | |
Public Attributes inherited from NavGraph | |
byte[] | _sguid |
Used to store the guid value. | |
AstarPath | active |
Reference to the AstarPath object in the scene. | |
bool | drawGizmos = true |
uint | graphIndex |
Index of the graph, used for identification purposes. | |
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 | |
override GridNodeBase | GetNeighbourAlongDirection (GridNodeBase node, int direction) |
Utility method used by Linecast. | |
Protected Member Functions inherited from GridGraph | |
bool | ClipLineSegmentToBounds (Vector3 a, Vector3 b, out Vector3 outA, out Vector3 outB) |
Clips a line segment in graph space to the graph bounds. | |
Package Attributes | |
int | lastScannedDepth |
int | lastScannedWidth |
Properties | |
override bool | uniformWidthDepthGrid [get] |
Properties inherited from GridGraph | |
Matrix4x4 | boundsMatrix [get, set] |
int | Depth [get, set] |
Vector2 | size [get, set] |
Size of the grid. | |
virtual bool | uniformWidthDepthGrid [get] |
This is placed here so generators inheriting from this one can override it and set it to false. | |
int | Width [get, set] |
bool | useRaycastNormal [get] |
Use heigh raycasting normal for max slope calculation. | |
Properties inherited from NavGraph | |
Guid | guid [get, set] |
Used as an ID of the graph, considered to be unique. | |
Private Member Functions | |
LevelGridNode | GetNearestNode (Vector3 position, int x, int z, NNConstraint constraint) |
void | RemoveGridGraphFromStatic () |
Additional Inherited Members | |
Static Protected Member Functions inherited from GridGraph | |
static float | CrossMagnitude (Vector2 a, Vector2 b) |
Magnitude of the cross product a x b. | |
static void | GetBoundsMinMax (Bounds b, Matrix4x4 matrix, out Vector3 min, out Vector3 max) |
Calculates minimum and maximum points for bounds b when multiplied with the matrix. | |
Package Functions inherited from NavGraph | |
virtual void | UnloadGizmoMeshes () |
Called when temporary meshes used in OnDrawGizmos need to be unloaded to prevent memory leaks. | |
Static Package Attributes inherited from GridGraph | |
static readonly int[] | hexagonNeighbourIndices = { 0, 1, 2, 3, 5, 7 } |
Which neighbours are going to be used when neighbours=6. | |
void AddLayers | ( | int | count | ) |
Increases the capacity of the nodes array to hold more layers.
After this function has been called and new nodes have been set up, the AstarPath.DataUpdate function must be called.
Calculates the layered grid graph connections for a single node.
|
static |
Returns if node is connected to it's neighbour in the specified direction.
|
virtual |
|
virtual |
Deserializes graph type specific node data.
Reimplemented from GridGraph.
|
virtual |
|
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 GridGraph.
|
virtual |
Returns the nearest node to a position using the specified constraint .
Reimplemented from GridGraph.
|
private |
|
protectedvirtual |
Utility method used by Linecast.
Required since LevelGridNode does not inherit from GridNode. Lots of ugly casting but it was better than massive code duplication.
Returns null if the node has no connection in that direction
Reimplemented from GridGraph.
|
virtual |
Calls a delegate with all nodes in the graph.
This is the primary way of "looping" through all nodes in a graph.
This function should not change anything in the graph structure.
Reimplemented from GridGraph.
|
virtual |
This function will be called when this graph is destroyed.
Reimplemented from GridGraph.
|
virtual |
Draw gizmos for the graph.
Reimplemented from GridGraph.
|
virtual |
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 GridGraph.
bool RecalculateCell | ( | int | x, |
int | z, | ||
bool | preserveExistingNodes | ||
) |
Recalculates single cell.
x | X coordinate of the cell |
z | Z coordinate of the cell |
preserveExistingNodes | If true, nodes will be reused, this can be used to preserve e.g penalty when recalculating |
|
private |
|
virtual |
Scans the graph, called from AstarPath.ScanLoop.
Override this function to implement custom scanning logic The statusCallback may be optionally called to show progress info in the editor
Reimplemented from GridGraph.
|
virtual |
Serializes graph type specific node data.
This function can be overriden to serialize extra node information (or graph information for that matter) which cannot be serialized using the standard serialization. Serialize the data in any way you want and return a byte array. When loading, the exact same byte array will be passed to the DeserializeExtraInfo function.
These functions will only be called if node serialization is enabled.
Reimplemented from GridGraph.
new void UpdateArea | ( | GraphUpdateObject | o | ) |
|
virtual |
Updates penalty for the node.
This function sets penalty to zero (0) and then adjusts it if penaltyPosition is set to true.
float characterHeight = 0.4F |
Nodes with a short distance to the node above it will be set unwalkable.
|
package |
|
package |
int layerCount |
Number of layers.
float mergeSpanRange = 0.5F |
If two layered nodes are too close, they will be merged.
int [] nodeCellIndices |
new LevelGridNode [] nodes |
|
get |