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

add

描述

在实体管理器中添加一个实体。

语法

entityManager.add(entity);

参数

  • entity:待添加的实体对象。

返回值

该方法没有返回值。

示例

var entityManager = new Yuka.EntityManager();

// 定义实体
class Box extends Yuka.Entity {
  constructor() {
    super();
    this.width = Math.random() * 10 + 10;
    this.height = Math.random() * 10 + 10;
    this.depth = Math.random() * 10 + 10;
  }
}

// 创建两个实体
var box1 = new Box();
var box2 = new Box();

// 将实体添加到实体管理器
entityManager.add(box1);
entityManager.add(box2);

// 获取实体管理器中的所有实体
var entities = entityManager.getEntities();
console.log(entities);  // [box1, box2]

异常

  • 如果传入的参数不是实体对象,则会抛出TypeError异常。
  • 如果实体已经添加到实体管理器中,则不会抛出异常,只是不会重复添加。