AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

getEdge

该函数返回由两个指定节点之间的边构成的对象。

语法

graph.getEdge(sourceNode, targetNode);

参数

  • sourceNode:表示边的起始节点。
  • targetNode:表示边的目标节点。

返回值

如果找到了两个指定节点之间的边,则返回表示边的对象。如果未找到,则返回null。

示例

// 创建一个有向图
var graph = new yuka.Graph(true);

// 添加节点
var node1 = graph.addNode('A');
var node2 = graph.addNode('B');
var node3 = graph.addNode('C');
var node4 = graph.addNode('D');

// 添加边
graph.addEdge(node1, node2);
graph.addEdge(node1, node3);
graph.addEdge(node2, node3);
graph.addEdge(node3, node4);

// 获得节点 "A" 和 "B" 之间的边
var edge = graph.getEdge(node1, node2);
console.log(edge); // 返回表示 "<A> -> <B>" 的边对象

注意事项

  • 如果该图是有向图,则边的方向从起始节点指向目标节点。因此,graph.getEdge(node1, node2)graph.getEdge(node2, node1) 返回的对象是不同的。
  • 如果该图是无向图,则起始节点和目标节点的顺序不是非常重要。即 graph.getEdge(node1, node2)graph.getEdge(node2, node1) 返回相同的对象。