本文整理汇总了C#中Pathfinding.NNConstraint.SuitableGraph方法的典型用法代码示例。如果您正苦于以下问题:C# NNConstraint.SuitableGraph方法的具体用法?C# NNConstraint.SuitableGraph怎么用?C# NNConstraint.SuitableGraph使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pathfinding.NNConstraint
的用法示例。
在下文中一共展示了NNConstraint.SuitableGraph方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNearest
/** Returns the nearest node to a position using the specified NNConstraint.
Searches through all graphs for their nearest nodes to the specified position and picks the closest one.
The NNConstraint can be used to specify constraints on which nodes can be chosen such as only picking walkable nodes.
\see Pathfinding.NNConstraint
*/
public NNInfo GetNearest (Vector3 position, NNConstraint constraint, GraphNode hint) {
if (graphs == null) { return new NNInfo(); }
float minDist = float.PositiveInfinity;//Math.Infinity;
NNInfo nearestNode = new NNInfo ();
int nearestGraph = -1;
for (int i=0;i<graphs.Length;i++) {
NavGraph graph = graphs[i];
if (graph == null) continue;
//Check if this graph should be searched
if (!constraint.SuitableGraph (i,graph)) {
continue;
}
NNInfo nnInfo;
if (fullGetNearestSearch) {
nnInfo = graph.GetNearestForce (position, constraint);
} else {
nnInfo = graph.GetNearest (position, constraint);
}
GraphNode node = nnInfo.node;
if (node == null) {
continue;
}
float dist = ((Vector3)nnInfo.clampedPosition-position).magnitude;
if (prioritizeGraphs && dist < prioritizeGraphsLimit) {
//The node is close enough, choose this graph and discard all others
minDist = dist;
nearestNode = nnInfo;
nearestGraph = i;
break;
} else {
if (dist < minDist) {
minDist = dist;
nearestNode = nnInfo;
nearestGraph = i;
}
}
}
//No matches found
if (nearestGraph == -1) {
return nearestNode;
}
//Check if a constrained node has already been set
if (nearestNode.constrainedNode != null) {
nearestNode.node = nearestNode.constrainedNode;
nearestNode.clampedPosition = nearestNode.constClampedPosition;
}
if (!fullGetNearestSearch && nearestNode.node != null && !constraint.Suitable (nearestNode.node)) {
//Otherwise, perform a check to force the graphs to check for a suitable node
NNInfo nnInfo = graphs[nearestGraph].GetNearestForce (position, constraint);
if (nnInfo.node != null) {
nearestNode = nnInfo;
}
}
if (!constraint.Suitable (nearestNode.node) || (constraint.constrainDistance && (nearestNode.clampedPosition - position).sqrMagnitude > maxNearestNodeDistanceSqr)) {
return new NNInfo();
}
return nearestNode;
}