protected override void Prepare () {
nnConstraint.tags = enabledTags;
var startNNInfo = AstarPath.active.GetNearest(startPoint, nnConstraint);
startNode = startNNInfo.node;
if (startNode == null) {
FailWithError("Could not find start node for multi target path");
return;
}
if (!CanTraverse(startNode)) {
FailWithError("The node closest to the start point could not be traversed");
return;
}
// Tell the NNConstraint which node was found as the start node if it is a PathNNConstraint and not a normal NNConstraint
var pathNNConstraint = nnConstraint as PathNNConstraint;
if (pathNNConstraint != null) {
pathNNConstraint.SetStart(startNNInfo.node);
}
vectorPaths = new List<Vector3>[targetPoints.Length];
nodePaths = new List<GraphNode>[targetPoints.Length];
targetNodes = new GraphNode[targetPoints.Length];
targetsFound = new bool[targetPoints.Length];
targetNodeCount = targetPoints.Length;
bool anyWalkable = false;
bool anySameArea = false;
bool anyNotNull = false;
for (int i = 0; i < targetPoints.Length; i++) {
var endNNInfo = AstarPath.active.GetNearest(targetPoints[i], nnConstraint);
targetNodes[i] = endNNInfo.node;
targetPoints[i] = endNNInfo.position;
if (targetNodes[i] != null) {
anyNotNull = true;
endNode = targetNodes[i];
}
bool notReachable = false;
if (endNNInfo.node != null && CanTraverse(endNNInfo.node)) {
anyWalkable = true;
} else {
notReachable = true;
}
if (endNNInfo.node != null && endNNInfo.node.Area == startNode.Area) {
anySameArea = true;
} else {
notReachable = true;
}
if (notReachable) {
// Signal that the pathfinder should not look for this node because we have already found it
targetsFound[i] = true;
targetNodeCount--;
}
}
startPoint = startNNInfo.position;
startIntPoint = (Int3)startPoint;
if (!anyNotNull) {
FailWithError("Couldn't find nodes close to the all of the end points");
return;
}
if (!anyWalkable) {
FailWithError("No target nodes could be traversed");
return;
}
if (!anySameArea) {
FailWithError("There are no valid paths to the targets");
return;
}
RecalculateHTarget(true);
}