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

execute

描述

execute方法是Yuka js库中Trigger触发器对象的方法之一。该方法用于调用该触发器的所有回调函数。

语法

trigger.execute( data );

参数

  • data: 可选,类型为任意数据类型。该数据将作为一个参数传递给每个回调函数。

示例

const trigger = new Trigger();

function callback1( data ) {
    console.log( "Callback 1 has been called with parameter: " + data );
}

function callback2( data ) {
    console.log( "Callback 2 has been called with parameter: " + data );
}

trigger.add( callback1 );
trigger.add( callback2 );

trigger.execute( "Hello, world!" );

该示例将创建一个Trigger对象,并向其添加两个回调函数。然后调用execute方法,将"Hello, world!"作为参数传递给这两个回调函数。执行结果为:

Callback 1 has been called with parameter: Hello, world!
Callback 2 has been called with parameter: Hello, world!

备注

  • 如果回调函数返回false,则该回调函数不会继续执行。