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

children

Yuka中的GameEntity类代表一个拥有组件或子对象的游戏实体。该类可以包含一组子GameEntity对象,这些子对象可以通过children属性进行访问。

属性

children

  • 类型:Array
  • 默认值:[]

使用该属性可以访问GameEntity的所有子对象。例如:

const entity = new GameEntity();
console.log(entity.children); // 输出:[]

childCount

  • 类型:Number
  • 默认值:0

该属性代表GameEntity子对象的数量,可以通过该属性进行查询。例如:

const entity = new GameEntity();
console.log(entity.childCount); // 输出:0

方法

addChild(child)

  • 描述:将给定的GameEntity作为该实体的子对象添加到children数组中。
  • 参数:child - 要添加的GameEntity实例。
  • 返回值:无。

例如:

const parent = new GameEntity();
const child = new GameEntity();

parent.addChild(child);
console.log(parent.children); // 输出:[GameEntity]

removeChild(child)

  • 描述:从该实体的children数组中删除给定的子GameEntity,并返回布尔值指示操作是否成功。
  • 参数:child - 要删除的子GameEntity
  • 返回值:Boolean。

例如:

const parent = new GameEntity();
const child = new GameEntity();

parent.addChild(child);
console.log(parent.removeChild(child)); // 输出:true
console.log(parent.children); // 输出:[]

getChildAt(index)

  • 描述:获取指定索引处的子GameEntity,并返回它的值。
  • 参数:index - 子对象在children数组中的索引。
  • 返回值:对应子GameEntity

例如:

const parent = new GameEntity();

for (let i = 0; i < 3; i++) {
  const child = new GameEntity();
  parent.addChild(child);
}

console.log(parent.getChildAt(1)); // 输出:GameEntity

getChildByName(name)

  • 描述:从该实体的children数组中找到name属性与指定值相匹配的第一个子GameEntity并返回它的值。
  • 参数:name - 子对象的name属性值。
  • 返回值:对应子GameEntity

例如:

const parent = new GameEntity();

for (let i = 0; i < 3; i++) {
  const child = new GameEntity();
  child.name = `child${i}`;
  parent.addChild(child);
}

console.log(parent.getChildByName('child1')); // 输出:GameEntity

例子

创建一个GameEntity对象并将两个子对象添加到其中:

const parent = new GameEntity();
const child1 = new GameEntity();
const child2 = new GameEntity();

parent.addChild(child1);
parent.addChild(child2);

console.log(parent.children); // 输出:[GameEntity, GameEntity]

GameEntity的子对象中获取特定的子对象:

const parent = new GameEntity();

for (let i = 0; i < 3; i++) {
   const child = new GameEntity();
   child.name = `child${i}`;
   parent.addChild(child);
}

console.log(parent.getChildByName('child1')); // 输出:GameEntity

GameEntity中删除特定的子对象:

const parent = new GameEntity();
const child = new GameEntity();

parent.addChild(child);
console.log(parent.children); // 输出:[GameEntity]

parent.removeChild(child);
console.log(parent.children); // 输出:[]