A* Pathfinding Project
3.6.6
The A* Pathfinding Project for Unity 3D
|
Handles path calls for a single unit. More...
Handles path calls for a single unit.
This is a component which is meant to be attached to a single unit (AI, Robot, Player, whatever) to handle it's pathfinding calls. It also handles post-processing of paths using modifiers.
Public Types | |
enum | ModifierPass { PreProcess, PostProcessOriginal, PostProcess } |
Public Member Functions | |
void | Awake () |
Initializes a few variables. | |
void | DeregisterModifier (IPathModifier mod) |
Called by modifiers when they are disabled or destroyed. | |
Path | GetCurrentPath () |
Returns path. | |
ABPath | GetNewPath (Vector3 start, Vector3 end) |
Returns a new path instance. | |
bool | IsDone () |
Is the current path done calculating. | |
void | OnDestroy () |
Cleans up some variables. | |
void | OnDrawGizmos () |
Draws gizmos for the Seeker. | |
void | PostProcess (Path p) |
Post Processes the path. | |
void | RegisterModifier (IPathModifier mod) |
Called by modifiers to register themselves. | |
void | ReleaseClaimedPath () |
Releases an eventual claimed path. | |
void | RunModifiers (ModifierPass pass, Path p) |
Runs modifiers on path p. | |
string | StackTrace () |
MultiTargetPath | StartMultiTargetPath (Vector3 start, Vector3[] endPoints, bool pathsForAll, OnPathDelegate callback=null, int graphMask=-1) |
Starts a Multi Target Path from one start point to multiple end points. | |
MultiTargetPath | StartMultiTargetPath (Vector3[] startPoints, Vector3 end, bool pathsForAll, OnPathDelegate callback=null, int graphMask=-1) |
Starts a Multi Target Path from multiple start points to a single target point. | |
MultiTargetPath | StartMultiTargetPath (MultiTargetPath p, OnPathDelegate callback=null, int graphMask=-1) |
Starts a Multi Target Path. | |
Path | StartPath (Vector3 start, Vector3 end) |
Call this function to start calculating a path. | |
Path | StartPath (Vector3 start, Vector3 end, OnPathDelegate callback) |
Call this function to start calculating a path. | |
Path | StartPath (Vector3 start, Vector3 end, OnPathDelegate callback, int graphMask) |
Call this function to start calculating a path. | |
Path | StartPath (Path p, OnPathDelegate callback=null, int graphMask=-1) |
Call this function to start calculating a path. | |
Public Attributes | |
bool | detailedGizmos = false |
Enables drawing of the non-postprocessed path using Gizmos. | |
bool | drawGizmos = true |
Enables drawing of the last calculated path using Gizmos. | |
OnPathDelegate | pathCallback |
Callback for when a path is completed. | |
OnPathDelegate | postProcessOriginalPath |
For anything which requires the original nodes (Node[]) (before modifiers) to work. | |
OnPathDelegate | postProcessPath |
Anything which only modifies the positions (Vector3[]) | |
OnPathDelegate | preProcessPath |
Called before pathfinding is started. | |
StartEndModifier | startEndModifier = new StartEndModifier () |
Path modifier which tweaks the start and end points of a path. | |
int[] | tagPenalties = new int[32] |
Penalties for each tag. | |
TagMask | traversableTags = new TagMask (-1,-1) |
The tags which the Seeker can traverse. | |
Protected Attributes | |
uint | lastPathID = 0 |
The path ID of the last path queried. | |
Path | path |
The current path. | |
Private Member Functions | |
void | OnMultiPathComplete (Path p) |
Called once for a MultiTargetPath. | |
void | OnPartialPathComplete (Path p) |
Called for each path in a MultiTargetPath. | |
void | OnPathComplete (Path p) |
Called when a path has completed. | |
void | OnPathComplete (Path p, bool runModifiers, bool sendCallbacks) |
Called when a path has completed. | |
Private Attributes | |
List< GraphNode > | lastCompletedNodePath |
List< Vector3 > | lastCompletedVectorPath |
List< IPathModifier > | modifiers = new List<IPathModifier> () |
Internal list of all modifiers. | |
OnPathDelegate | onPartialPathDelegate |
OnPathDelegate | onPathDelegate |
Path | prevPath |
Previous path. | |
OnPathDelegate | tmpPathCallback |
Temporary callback only called for the current path. | |
enum ModifierPass |
void Awake | ( | ) |
Initializes a few variables.
void DeregisterModifier | ( | IPathModifier | mod | ) |
Called by modifiers when they are disabled or destroyed.
ABPath GetNewPath | ( | Vector3 | start, |
Vector3 | end | ||
) |
Returns a new path instance.
The path will be taken from the path pool if path recycling is turned on.
This path can be sent to StartPath(Path,OnPathDelegate,int) with no change, but if no change is required StartPath(Vector3,Vector3,OnPathDelegate) does just that.
bool IsDone | ( | ) |
Is the current path done calculating.
Returns true if the current path has been returned or if the path is null.
void OnDestroy | ( | ) |
Cleans up some variables.
Releases any eventually claimed paths. Calls OnDestroy on the startEndModifier.
void OnDrawGizmos | ( | ) |
Draws gizmos for the Seeker.
|
private |
Called once for a MultiTargetPath.
Only returns the path, does not post process.
|
private |
Called for each path in a MultiTargetPath.
Only post processes the path, does not return it.
|
private |
Called when a path has completed.
This should have been implemented as optional parameter values, but that didn't seem to work very well with delegates (the values weren't the default ones)
|
private |
Called when a path has completed.
Will post process it and return it by calling tmpPathCallback and pathCallback
void PostProcess | ( | Path | p | ) |
Post Processes the path.
This will run any modifiers attached to this GameObject on the path. This is identical to calling RunModifiers(ModifierPass.PostProcess, path)
void RegisterModifier | ( | IPathModifier | mod | ) |
Called by modifiers to register themselves.
void ReleaseClaimedPath | ( | ) |
Releases an eventual claimed path.
The seeker keeps the latest path claimed so it can draw gizmos. In some cases this might not be desireable and you want it released. In that case, you can call this method to release it (not that path gizmos will then not be drawn).
If you didn't understand anything from the description above, you probably don't need to use this method.
void RunModifiers | ( | ModifierPass | pass, |
Path | p | ||
) |
Runs modifiers on path p.
string StackTrace | ( | ) |
MultiTargetPath StartMultiTargetPath | ( | Vector3 | start, |
Vector3[] | endPoints, | ||
bool | pathsForAll, | ||
OnPathDelegate | callback = null , |
||
int | graphMask = -1 |
||
) |
Starts a Multi Target Path from one start point to multiple end points.
A Multi Target Path will search for all the end points in one search and will return all paths if pathsForAll is true, or only the shortest one if pathsForAll is false.
start | The start point of the path |
endPoints | The end points of the path |
pathsForAll | Indicates whether or not a path to all end points should be searched for or only to the closest one |
callback | The function to call when the path has been calculated |
graphMask | Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask. |
callback and pathCallback will be called when the path has completed. Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed)
MultiTargetPath StartMultiTargetPath | ( | Vector3[] | startPoints, |
Vector3 | end, | ||
bool | pathsForAll, | ||
OnPathDelegate | callback = null , |
||
int | graphMask = -1 |
||
) |
Starts a Multi Target Path from multiple start points to a single target point.
A Multi Target Path will search from all start points to the target point in one search and will return all paths if pathsForAll is true, or only the shortest one if pathsForAll is false.
startPoints | The start points of the path |
end | The end point of the path |
pathsForAll | Indicates whether or not a path from all start points should be searched for or only to the closest one |
callback | The function to call when the path has been calculated |
graphMask | Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask. |
callback and pathCallback will be called when the path has completed. Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed)
MultiTargetPath StartMultiTargetPath | ( | MultiTargetPath | p, |
OnPathDelegate | callback = null , |
||
int | graphMask = -1 |
||
) |
Starts a Multi Target Path.
Takes a MultiTargetPath and wires everything up for it to send callbacks to the seeker for post-processing.
p | The path to start calculating |
callback | The function to call when the path has been calculated |
graphMask | Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask. |
callback and pathCallback will be called when the path has completed. Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed)
Path StartPath | ( | Vector3 | start, |
Vector3 | end | ||
) |
Call this function to start calculating a path.
start | The start point of the path |
end | The end point of the path |
Path StartPath | ( | Vector3 | start, |
Vector3 | end, | ||
OnPathDelegate | callback | ||
) |
Call this function to start calculating a path.
start | The start point of the path |
end | The end point of the path |
callback | The function to call when the path has been calculated |
callback will be called when the path has completed. Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed)
Path StartPath | ( | Vector3 | start, |
Vector3 | end, | ||
OnPathDelegate | callback, | ||
int | graphMask | ||
) |
Call this function to start calculating a path.
start | The start point of the path |
end | The end point of the path |
callback | The function to call when the path has been calculated |
graphMask | Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask. |
callback will be called when the path has completed. Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed)
Path StartPath | ( | Path | p, |
OnPathDelegate | callback = null , |
||
int | graphMask = -1 |
||
) |
Call this function to start calculating a path.
p | The path to start calculating |
callback | The function to call when the path has been calculated |
graphMask | Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask. |
callback will be called when the path has completed. Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed)
bool detailedGizmos = false |
Enables drawing of the non-postprocessed path using Gizmos.
The path will show up in orange.
Requires that drawGizmos is true.
This will show the path before any post processing such as smoothing is applied.
bool drawGizmos = true |
Enables drawing of the last calculated path using Gizmos.
The path will show up in green
|
private |
|
private |
|
protected |
The path ID of the last path queried.
|
private |
Internal list of all modifiers.
|
private |
|
private |
|
protected |
The current path.
OnPathDelegate pathCallback |
Callback for when a path is completed.
Movement scripts should register to this delegate.
A temporary callback can also be set when calling StartPath, but that delegate will only be called for that path
OnPathDelegate postProcessOriginalPath |
For anything which requires the original nodes (Node[]) (before modifiers) to work.
OnPathDelegate postProcessPath |
Anything which only modifies the positions (Vector3[])
OnPathDelegate preProcessPath |
Called before pathfinding is started.
|
private |
Previous path.
Used to draw gizmos
StartEndModifier startEndModifier = new StartEndModifier () |
Path modifier which tweaks the start and end points of a path.
int [] tagPenalties = new int[32] |
Penalties for each tag.
Tag 0 which is the default tag, will have added a penalty of tagPenalties[0]. These should only be positive values since the A* algorithm cannot handle negative penalties.
|
private |
Temporary callback only called for the current path.
This value is set by the StartPath functions
The tags which the Seeker can traverse.
The actual tags are stored in the tagsChange field, but it needed to be a class with some more fields to get it to work correctly in the editor.