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

handleMessage

方法描述

此方法用于处理 Vehicle 对象收到的消息。

方法参数

参数名 类型 描述
message Object 收到的消息内容

方法返回值

无返回值。

方法示例

以下示例展示了如何使用 handleMessage 方法处理 Vehicle 收到的名为 "move" 的消息。

const vehicle = new Vehicle();
const message = {
  type: "move",
  payload: { x: 5, y: 10 }
};
vehicle.handleMessage(message);

方法实现

Vehicle.prototype.handleMessage = function(message) {
  switch (message.type) {
    case "move":
      this.move(message.payload.x, message.payload.y);
      break;
    case "stop":
      this.stop();
      break;
    default:
      console.error("Unrecognized message type:", message.type);
  }
};

实现说明

handleMessage 方法根据收到的消息类型来调用对应的 Vehicle 方法。如果收到一个未定义的消息类型,则会将一条错误消息记录到控制台。