Partager via


GKGraph.FindPath(GKGraphNode, GKGraphNode) Méthode

Définition

Renvoie un tableau de T:GamplayKit.GKGraphNode représentant le chemin d’accès dans l’ordre le plus bas coût. S’il n’existe aucun chemin d’accès, retourne un tableau vide.

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

Paramètres

startNode
GKGraphNode
endNode
GKGraphNode

Retours

Attributs

Remarques

L’exemple suivant illustre le pathfinding sur un graphique simple :

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 ]

S’applique à