ECS Framework API / Scene
Class: Scene
Defined in: ECS/Scene.ts:19
游戏场景默认实现类
实现IScene接口,提供场景的基础功能。 推荐使用组合而非继承的方式来构建自定义场景。
Implements
Constructors
Constructor
new Scene(
config?
):Scene
Defined in: ECS/Scene.ts:85
创建场景实例
Parameters
config?
Returns
Scene
Properties
name
name:
string
=""
Defined in: ECS/Scene.ts:25
场景名称
用于标识和调试的友好名称。
Implementation of
entities
readonly
entities:EntityList
Defined in: ECS/Scene.ts:32
场景中的实体集合
管理场景内所有实体的生命周期。
Implementation of
entityProcessors
readonly
entityProcessors:EntityProcessorList
Defined in: ECS/Scene.ts:39
实体系统处理器集合
管理场景内所有实体系统的执行。
Implementation of
identifierPool
readonly
identifierPool:IdentifierPool
Defined in: ECS/Scene.ts:46
实体ID池
用于分配和回收实体的唯一标识符。
Implementation of
componentStorageManager
readonly
componentStorageManager:ComponentStorageManager
Defined in: ECS/Scene.ts:53
组件存储管理器
高性能的组件存储和查询系统。
Implementation of
IScene
.componentStorageManager
querySystem
readonly
querySystem:QuerySystem
Defined in: ECS/Scene.ts:60
查询系统
基于位掩码的高性能实体查询系统。
Implementation of
eventSystem
readonly
eventSystem:TypeSafeEventSystem
Defined in: ECS/Scene.ts:67
事件系统
类型安全的事件系统。
Implementation of
Accessors
systems
Get Signature
get systems():
EntitySystem
[]
Defined in: ECS/Scene.ts:77
获取系统列表(兼容性属性)
Returns
获取系统列表
Implementation of
Methods
initialize()
initialize():
void
Defined in: ECS/Scene.ts:119
初始化场景
在场景创建时调用,子类可以重写此方法来设置初始实体和组件。
Returns
void
Implementation of
onStart()
onStart():
void
Defined in: ECS/Scene.ts:127
场景开始运行时的回调
在场景开始运行时调用,可以在此方法中执行场景启动逻辑。
Returns
void
Implementation of
unload()
unload():
void
Defined in: ECS/Scene.ts:135
场景卸载时的回调
在场景被销毁时调用,可以在此方法中执行清理工作。
Returns
void
Implementation of
begin()
begin():
void
Defined in: ECS/Scene.ts:143
开始场景,启动实体处理器等
这个方法会启动场景。它将启动实体处理器等,并调用onStart方法。
Returns
void
Implementation of
end()
end():
void
Defined in: ECS/Scene.ts:158
结束场景,清除实体、实体处理器等
这个方法会结束场景。它将移除所有实体,结束实体处理器等,并调用unload方法。
Returns
void
Implementation of
update()
update():
void
Defined in: ECS/Scene.ts:182
更新场景
Returns
void
Implementation of
createEntity()
createEntity(
name
):Entity
Defined in: ECS/Scene.ts:202
将实体添加到此场景,并返回它
Parameters
name
string
实体名称
Returns
Implementation of
clearSystemEntityCaches()
clearSystemEntityCaches():
void
Defined in: ECS/Scene.ts:214
清除所有EntitySystem的实体缓存 当实体或组件发生变化时调用
Returns
void
Implementation of
IScene
.clearSystemEntityCaches
addEntity()
addEntity(
entity
,deferCacheClear
):Entity
Defined in: ECS/Scene.ts:225
在场景的实体列表中添加一个实体
Parameters
entity
要添加的实体
deferCacheClear
boolean
= false
是否延迟缓存清理(用于批量操作)
Returns
Implementation of
createEntities()
createEntities(
count
,namePrefix
):Entity
[]
Defined in: ECS/Scene.ts:249
批量创建实体(高性能版本)
Parameters
count
number
要创建的实体数量
namePrefix
string
= "Entity"
实体名称前缀
Returns
Entity
[]
创建的实体列表
Implementation of
destroyAllEntities()
destroyAllEntities():
void
Defined in: ECS/Scene.ts:277
从场景中删除所有实体
Returns
void
Implementation of
findEntity()
findEntity(
name
):null
|Entity
Defined in: ECS/Scene.ts:288
搜索并返回第一个具有名称的实体
Parameters
name
string
实体名称
Returns
null
| Entity
Implementation of
findEntityById()
findEntityById(
id
):null
|Entity
Defined in: ECS/Scene.ts:296
根据ID查找实体
Parameters
id
number
实体ID
Returns
null
| Entity
findEntitiesByTag()
findEntitiesByTag(
tag
):Entity
[]
Defined in: ECS/Scene.ts:304
根据标签查找实体
Parameters
tag
number
实体标签
Returns
Entity
[]
Implementation of
getEntityByName()
getEntityByName(
name
):null
|Entity
Defined in: ECS/Scene.ts:318
根据名称查找实体(别名方法)
Parameters
name
string
实体名称
Returns
null
| Entity
getEntitiesByTag()
getEntitiesByTag(
tag
):Entity
[]
Defined in: ECS/Scene.ts:326
根据标签查找实体(别名方法)
Parameters
tag
number
实体标签
Returns
Entity
[]
addEntityProcessor()
addEntityProcessor(
processor
):EntitySystem
Defined in: ECS/Scene.ts:334
在场景中添加一个EntitySystem处理器
Parameters
processor
处理器
Returns
Implementation of
addSystem()
addSystem(
system
):EntitySystem
Defined in: ECS/Scene.ts:350
添加系统到场景(addEntityProcessor的别名)
Parameters
system
系统
Returns
removeEntityProcessor()
removeEntityProcessor(
processor
):void
Defined in: ECS/Scene.ts:358
从场景中删除EntitySystem处理器
Parameters
processor
要删除的处理器
Returns
void
Implementation of
removeSystem()
removeSystem(
system
):void
Defined in: ECS/Scene.ts:367
从场景中删除系统(removeEntityProcessor的别名)
Parameters
system
系统
Returns
void
getEntityProcessor()
getEntityProcessor<
T
>(type
):null
|T
Defined in: ECS/Scene.ts:375
获取指定类型的EntitySystem处理器
Type Parameters
T
T
extends EntitySystem
Parameters
type
(...args
) => T
处理器类型
Returns
null
| T
Implementation of
getStats()
getStats():
object
Defined in: ECS/Scene.ts:382
获取场景统计信息
Returns
object
entityCount
entityCount:
number
processorCount
processorCount:
number
componentStorageStats
componentStorageStats:
Map
<string
,any
>
getDebugInfo()
getDebugInfo():
object
Defined in: ECS/Scene.ts:398
获取场景的调试信息
Returns
object
name
name:
string
entityCount
entityCount:
number
processorCount
processorCount:
number
isRunning
isRunning:
boolean
entities
entities:
object
[]
processors
processors:
object
[]
componentStats
componentStats:
Map
<string
,any
>