public static NNInfo GetNearest(NavMeshGraph graph, GraphNode[] nodes, Vector3 position, NNConstraint constraint, bool accurateNearestNode)
{
if (nodes == null || nodes.Length == 0)
{
Debug.LogError("NavGraph hasn't been generated yet or does not contain any nodes");
return(default(NNInfo));
}
if (constraint == null)
{
constraint = NNConstraint.None;
}
Int3[] vertices = graph.vertices;
if (graph.bbTree == null)
{
return(NavMeshGraph.GetNearestForce(graph, graph, position, constraint, accurateNearestNode));
}
float num = (graph.bbTree.Size.width + graph.bbTree.Size.height) * 0.5f * 0.02f;
NNInfo result = graph.bbTree.QueryCircle(position, num, constraint);
if (result.node == null)
{
for (int i = 1; i <= 8; i++)
{
result = graph.bbTree.QueryCircle(position, (float)(i * i) * num, constraint);
if (result.node != null || (float)((i - 1) * (i - 1)) * num > AstarPath.active.maxNearestNodeDistance * 2f)
{
break;
}
}
}
if (result.node != null)
{
result.clampedPosition = NavMeshGraph.ClosestPointOnNode(result.node as TriangleMeshNode, vertices, position);
}
if (result.constrainedNode != null)
{
if (constraint.constrainDistance && ((Vector3)result.constrainedNode.position - position).sqrMagnitude > AstarPath.active.maxNearestNodeDistanceSqr)
{
result.constrainedNode = null;
}
else
{
result.constClampedPosition = NavMeshGraph.ClosestPointOnNode(result.constrainedNode as TriangleMeshNode, vertices, position);
}
}
return(result);
}