本文整理匯總了C#中Pathfinding.NavGraph.GetNodes方法的典型用法代碼示例。如果您正苦於以下問題:C# NavGraph.GetNodes方法的具體用法?C# NavGraph.GetNodes怎麽用?C# NavGraph.GetNodes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Pathfinding.NavGraph
的用法示例。
在下文中一共展示了NavGraph.GetNodes方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetNearestForceBoth
/** This performs a linear search through all polygons returning the closest one.
* This will fill the NNInfo with .node for the closest node not necessarily complying with the NNConstraint, and .constrainedNode with the closest node
* complying with the NNConstraint.
* \see GetNearestForce(Node[],Int3[],Vector3,NNConstraint,bool)
*/
public static NNInfo GetNearestForceBoth (NavGraph graph, INavmeshHolder navmesh, Vector3 position, NNConstraint constraint, bool accurateNearestNode) {
Int3 pos = (Int3)position;
float minDist = -1;
GraphNode minNode = null;
float minConstDist = -1;
GraphNode minConstNode = null;
float maxDistSqr = constraint.constrainDistance ? AstarPath.active.maxNearestNodeDistanceSqr : float.PositiveInfinity;
GraphNodeDelegateCancelable del = delegate (GraphNode _node) {
TriangleMeshNode node = _node as TriangleMeshNode;
if (accurateNearestNode) {
Vector3 closest = node.ClosestPointOnNode (position);
float dist = ((Vector3)pos-closest).sqrMagnitude;
if (minNode == null || dist < minDist) {
minDist = dist;
minNode = node;
}
if (dist < maxDistSqr && constraint.Suitable (node)) {
if (minConstNode == null || dist < minConstDist) {
minConstDist = dist;
minConstNode = node;
}
}
} else {
if (!node.ContainsPoint ((Int3)position)) {
float dist = (node.position-pos).sqrMagnitude;
if (minNode == null || dist < minDist) {
minDist = dist;
minNode = node;
}
if (dist < maxDistSqr && constraint.Suitable (node)) {
if (minConstNode == null || dist < minConstDist) {
minConstDist = dist;
minConstNode = node;
}
}
} else {
#if ASTARDEBUG
Debug.DrawLine ((Vector3)vertices[node.v0],(Vector3)vertices[node.v1],Color.blue);
Debug.DrawLine ((Vector3)vertices[node.v1],(Vector3)vertices[node.v2],Color.blue);
Debug.DrawLine ((Vector3)vertices[node.v2],(Vector3)vertices[node.v0],Color.blue);
#endif
int dist = AstarMath.Abs (node.position.y-pos.y);
if (minNode == null || dist < minDist) {
minDist = dist;
minNode = node;
}
if (dist < maxDistSqr && constraint.Suitable (node)) {
if (minConstNode == null || dist < minConstDist) {
minConstDist = dist;
minConstNode = node;
}
}
}
}
return true;
};
graph.GetNodes (del);
NNInfo nninfo = new NNInfo (minNode);
//Find the point closest to the nearest triangle
if (nninfo.node != null) {
TriangleMeshNode node = nninfo.node as TriangleMeshNode;//minNode2 as MeshNode;
Vector3 clP = node.ClosestPointOnNode (position);
nninfo.clampedPosition = clP;
}
nninfo.constrainedNode = minConstNode;
if (nninfo.constrainedNode != null) {
TriangleMeshNode node = nninfo.constrainedNode as TriangleMeshNode;//minNode2 as MeshNode;
Vector3 clP = node.ClosestPointOnNode (position);
nninfo.constClampedPosition = clP;
//.........這裏部分代碼省略.........
示例2: SerializeGraphNodeReferences
/** Used to serialize references to other nodes e.g connections.
* Nodes use the GraphSerializationContext.GetNodeIdentifier and
* GraphSerializationContext.GetNodeFromIdentifier methods
* for serialization and deserialization respectively.
*/
static byte[] SerializeGraphNodeReferences (NavGraph graph) {
var stream = new MemoryStream();
var wr = new BinaryWriter(stream);
var ctx = new GraphSerializationContext(wr);
graph.GetNodes(node => {
node.SerializeReferences(ctx);
return true;
});
#if NETFX_CORE
wr.Dispose();
#else
wr.Close();
#endif
var bytes = stream.ToArray();
return bytes;
}
示例3: DeserializeNodeReferences
void DeserializeNodeReferences (NavGraph graph, GraphNode[] int2Node) {
var zipIndex = graphIndexInZip[graph];
var entry = zip["graph"+zipIndex+"_references"+binaryExt];
if (entry == null) throw new Exception("Node references for graph " + zipIndex + " not found in the data. Was this loaded from an older version of the A* Pathfinding Project?");
var reader = GetBinaryReader(entry);
var ctx = new GraphSerializationContext(reader, int2Node, graph.graphIndex);
graph.GetNodes(node => {
node.DeserializeReferences(ctx);
return true;
});
}
示例4: UpdateArea
public static void UpdateArea (GraphUpdateObject o, NavGraph graph) {
INavmesh navgraph = graph as INavmesh;
if (navgraph == null) { Debug.LogError ("Update Area on NavMesh must be called with a graph implementing INavmesh"); return; }
//System.DateTime startTime = System.DateTime.UtcNow;
Bounds bounds = o.bounds;
Rect r = Rect.MinMaxRect (bounds.min.x,bounds.min.z,bounds.max.x,bounds.max.z);
IntRect r2 = new IntRect(
Mathf.FloorToInt(bounds.min.x*Int3.Precision),
Mathf.FloorToInt(bounds.min.z*Int3.Precision),
Mathf.FloorToInt(bounds.max.x*Int3.Precision),
Mathf.FloorToInt(bounds.max.z*Int3.Precision)
);
/*Vector3 a = new Vector3 (r.xMin,0,r.yMin);// -1 -1
Vector3 b = new Vector3 (r.xMin,0,r.yMax);// -1 1
Vector3 c = new Vector3 (r.xMax,0,r.yMin);// 1 -1
Vector3 d = new Vector3 (r.xMax,0,r.yMax);// 1 1
*/
Int3 a = new Int3(r2.xmin,0,r2.ymin);
Int3 b = new Int3(r2.xmin,0,r2.ymax);
Int3 c = new Int3(r2.xmax,0,r2.ymin);
Int3 d = new Int3(r2.xmax,0,r2.ymax);
Int3 ia = (Int3)a;
Int3 ib = (Int3)b;
Int3 ic = (Int3)c;
Int3 id = (Int3)d;
//for (int i=0;i<nodes.Length;i++) {
graph.GetNodes (delegate (GraphNode _node) {
TriangleMeshNode node = _node as TriangleMeshNode;
bool inside = false;
int allLeft = 0;
int allRight = 0;
int allTop = 0;
int allBottom = 0;
for (int v=0;v<3;v++) {
Int3 p = node.GetVertex(v);
Vector3 vert = (Vector3)p;
//Vector2 vert2D = new Vector2 (vert.x,vert.z);
if (r2.Contains (p.x,p.z)) {
//Debug.DrawRay (vert,Vector3.up*10,Color.yellow);
inside = true;
break;
}
if (vert.x < r.xMin) allLeft++;
if (vert.x > r.xMax) allRight++;
if (vert.z < r.yMin) allTop++;
if (vert.z > r.yMax) allBottom++;
//if (!bounds.Contains (node[v]) {
// inside = false;
// break;
//}
}
if (!inside) {
if (allLeft == 3 || allRight == 3 || allTop == 3 || allBottom == 3) {
return true;
}
}
//Debug.DrawLine ((Vector3)node.GetVertex(0),(Vector3)node.GetVertex(1),Color.yellow);
//Debug.DrawLine ((Vector3)node.GetVertex(1),(Vector3)node.GetVertex(2),Color.yellow);
//Debug.DrawLine ((Vector3)node.GetVertex(2),(Vector3)node.GetVertex(0),Color.yellow);
for (int v=0;v<3;v++) {
int v2 = v > 1 ? 0 : v+1;
Int3 vert1 = node.GetVertex(v);
Int3 vert2 = node.GetVertex(v2);
if (Polygon.Intersects (a,b,vert1,vert2)) { inside = true; break; }
if (Polygon.Intersects (a,c,vert1,vert2)) { inside = true; break; }
if (Polygon.Intersects (c,d,vert1,vert2)) { inside = true; break; }
if (Polygon.Intersects (d,b,vert1,vert2)) { inside = true; break; }
}
if (node.ContainsPoint (ia) || node.ContainsPoint (ib) || node.ContainsPoint (ic) || node.ContainsPoint (id)) {
inside = true;
}
if (!inside) {
return true;
}
//.........這裏部分代碼省略.........