GKGraph.FindPath(GKGraphNode, GKGraphNode) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回一个 T:GamplayKit.GKGraphNode ,表示成本最低的顺序路径。 如果不存在路径,则返回空数组。
[Foundation.Export("findPathFromNode:toNode:")]
public virtual GameplayKit.GKGraphNode[] FindPath (GameplayKit.GKGraphNode startNode, GameplayKit.GKGraphNode endNode);
abstract member FindPath : GameplayKit.GKGraphNode * GameplayKit.GKGraphNode -> GameplayKit.GKGraphNode[]
override this.FindPath : GameplayKit.GKGraphNode * GameplayKit.GKGraphNode -> GameplayKit.GKGraphNode[]
参数
- startNode
- GKGraphNode
- endNode
- GKGraphNode
返回
- 属性
注解
下面演示了在简单图形上查找路径:
var a = GKGraphNode2D.FromPoint (new Vector2 (0, 5));
var b = GKGraphNode2D.FromPoint (new Vector2 (3, 0));
var c = GKGraphNode2D.FromPoint (new Vector2 (2, 6));
var d = GKGraphNode2D.FromPoint (new Vector2 (4, 6));
var e = GKGraphNode2D.FromPoint (new Vector2 (2, 5));
var f = GKGraphNode2D.FromPoint (new Vector2 (2, 2));
a.AddConnections (new [] { b, c }, false);
b.AddConnections (new [] { e, f }, false);
c.AddConnections (new [] { d }, false);
d.AddConnections (new [] { e, f }, false);
var graph = GKGraph.FromNodes(new [] { a, b, c, d, e, f });
var a2e = graph.FindPath (a, e); // [ a, c, d, e ]
var a2f = graph.FindPath (a, f); // [ a, b, f ]