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

Loop

loop方法即循环遍历Path中的元素,对每个元素执行给定的回调函数。

语法

Path.loop(callback[, context])

参数:

  • callback:回调函数,接收两个参数,分别是当前遍历到的元素和当前元素的索引值。
  • context:可选参数,指定回调函数中的this值,默认为Path本身。

示例

const myPath = new Path('#my-path');
myPath.loop(function(element, index) {
  console.log(`第 ${index+1} 个元素的id值是 ${element.id}`);
});

输出结果为:

1 个元素的id值是 element-12 个元素的id值是 element-23 个元素的id值是 element-3

注意事项

  • 回调函数内部的操作需要与具体业务逻辑相关,本库不提供具体实现代码。
  • 回调函数内部对元素进行的改动不会反馈到Path对象中。
  • 回调函数的执行顺序与元素在Path对象中的顺序相同。