// This will send the path to the callback (if any) specified when calling StartPath
if(tmpPathCallback!=null){
tmpPathCallback(p);
}
// This will send the path to any script which has registered to the callback
if(pathCallback!=null){
pathCallback(p);
}
// Note: it is important that #prevPath is kept alive (i.e. not pooled)
// if we are drawing gizmos.
// It is also important that #path is kept alive since it can be returned
// from the GetCurrentPath method.
// Since #path will be copied to #prevPath it is sufficient that #prevPath
// is kept alive until it is replaced.
// Recycle the previous path to reduce the load on the GC
if(prevPath!=null){
prevPath.Release(this,true);
}
prevPath=p;
}
}
/// <summary>
/// Called for each path in a MultiTargetPath.
/// Only post processes the path, does not return it.
/// </summary>
voidOnPartialPathComplete(Pathp){
OnPathComplete(p,true,false);
}
/// <summary>Called once for a MultiTargetPath. Only returns the path, does not post process.</summary>
voidOnMultiPathComplete(Pathp){
OnPathComplete(p,false,true);
}
/// <summary>
/// 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 <see cref="StartPath(Path,OnPathDelegate,int)"/> with no change, but if no change is required <see cref="StartPath(Vector3,Vector3,OnPathDelegate)"/> does just that.
/// <code>
/// var seeker = GetComponent<Seeker>();
/// Path p = seeker.GetNewPath (transform.position, transform.position+transform.forward*100);
/// // Disable heuristics on just this path for example
/// p.heuristic = Heuristic.None;
/// seeker.StartPath (p, OnPathComplete);
/// </code>
/// Deprecated: Use ABPath.Construct(start, end, null) instead.
/// Call this function to start calculating a path.
///
/// The callback will be called when the path has been calculated (which may be several frames into the future).
/// Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed)
/// </summary>
/// <param name="start">The start point of the path</param>
/// <param name="end">The end point of the path</param>
/// <param name="callback">The function to call when the path has been calculated</param>
/// <param name="graphMask">Mask used to specify which graphs should be searched for close nodes. See #Pathfinding.NNConstraint.graphMask. This will override #graphMask for this path request.</param>
/// Call this function to start calculating a path.
///
/// The callback will be called when the path has been calculated (which may be several frames into the future).
/// The callback will not be called if a new path request is started before this path request has been calculated.
///
/// Version: Since 3.8.3 this method works properly if a MultiTargetPath is used.
/// It now behaves identically to the StartMultiTargetPath(MultiTargetPath) method.
///
/// Version: Since 4.1.x this method will no longer overwrite the graphMask on the path unless it is explicitly passed as a parameter (see other overloads of this method).
/// </summary>
/// <param name="p">The path to start calculating</param>
/// <param name="callback">The function to call when the path has been calculated</param>
/// Call this function to start calculating a path.
///
/// The callback will be called when the path has been calculated (which may be several frames into the future).
/// The callback will not be called if a new path request is started before this path request has been calculated.
///
/// Version: Since 3.8.3 this method works properly if a MultiTargetPath is used.
/// It now behaves identically to the StartMultiTargetPath(MultiTargetPath) method.
/// </summary>
/// <param name="p">The path to start calculating</param>
/// <param name="callback">The function to call when the path has been calculated</param>
/// <param name="graphMask">Mask used to specify which graphs should be searched for close nodes. See #Pathfinding.GraphMask. This will override #graphMask for this path request.</param>
path.FailWithError("Canceled path because a new one was requested.\n"+
"This happens when a new path is requested from the seeker when one was already being calculated.\n"+
"For example if a unit got a new order, you might request a new path directly instead of waiting for the now"+
" invalid path to be calculated. Which is probably what you want.\n"+
"If you are getting this a lot, you might want to consider how you are scheduling path requests.");
// No callback will be sent for the canceled path
}
// Set p as the active path
path=p;
tmpPathCallback=callback;
// Save the path id so we can make sure that if we cancel a path (see above) it should not have been recycled yet.
lastPathID=path.pathID;
// Pre process the path
RunModifiers(ModifierPass.PreProcess,path);
// Send the request to the pathfinder
AstarPath.StartPath(path);
}
/// <summary>
/// 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.
///
/// callback and <see cref="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)
///
/// See: Pathfinding.MultiTargetPath
/// See: MultiTargetPathExample.cs (view in online documentation for working links) "Example of how to use multi-target-paths"
/// </summary>
/// <param name="start">The start point of the path</param>
/// <param name="endPoints">The end points of the path</param>
/// <param name="pathsForAll">Indicates whether or not a path to all end points should be searched for or only to the closest one</param>
/// <param name="callback">The function to call when the path has been calculated</param>
/// <param name="graphMask">Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask.</param>
/// 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.
///
/// callback and <see cref="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)
///
/// See: Pathfinding.MultiTargetPath
/// See: MultiTargetPathExample.cs (view in online documentation for working links) "Example of how to use multi-target-paths"
/// </summary>
/// <param name="startPoints">The start points of the path</param>
/// <param name="end">The end point of the path</param>
/// <param name="pathsForAll">Indicates whether or not a path from all start points should be searched for or only to the closest one</param>
/// <param name="callback">The function to call when the path has been calculated</param>
/// <param name="graphMask">Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask.</param>
/// Takes a MultiTargetPath and wires everything up for it to send callbacks to the seeker for post-processing.
///
/// callback and <see cref="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)
///
/// See: Pathfinding.MultiTargetPath
/// See: MultiTargetPathExample.cs (view in online documentation for working links) "Example of how to use multi-target-paths"
///
/// Version: Since 3.8.3 calling this method behaves identically to calling StartPath with a MultiTargetPath.
/// Version: Since 3.8.3 this method also sets enabledTags and tagPenalties on the path object.
///
/// Deprecated: You can use StartPath instead of this method now. It will behave identically.
/// </summary>
/// <param name="p">The path to start calculating</param>
/// <param name="callback">The function to call when the path has been calculated</param>
/// <param name="graphMask">Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask.</param>
[System.Obsolete("You can use StartPath instead of this method now. It will behave identically.")]