Compartilhar via


GKGraph.FindPath(GKGraphNode, GKGraphNode) Método

Definição

Retorna uma matriz de T:GamplayKit.GKGraphNode representando o caminho em ordem de menor custo. Se nenhum caminho existir, retornará uma matriz vazia.

[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[]

Parâmetros

startNode
GKGraphNode
endNode
GKGraphNode

Retornos

Atributos

Comentários

O seguinte demonstra a definição de caminho em um grafo simples:

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 ]

Aplica-se a