Skip to content

ECS Framework API v2.1.50


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?

ISceneConfig

Returns

Scene

Properties

name

name: string = ""

Defined in: ECS/Scene.ts:25

场景名称

用于标识和调试的友好名称。

Implementation of

IScene.name


entities

readonly entities: EntityList

Defined in: ECS/Scene.ts:32

场景中的实体集合

管理场景内所有实体的生命周期。

Implementation of

IScene.entities


entityProcessors

readonly entityProcessors: EntityProcessorList

Defined in: ECS/Scene.ts:39

实体系统处理器集合

管理场景内所有实体系统的执行。

Implementation of

IScene.entityProcessors


identifierPool

readonly identifierPool: IdentifierPool

Defined in: ECS/Scene.ts:46

实体ID池

用于分配和回收实体的唯一标识符。

Implementation of

IScene.identifierPool


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

IScene.querySystem


eventSystem

readonly eventSystem: TypeSafeEventSystem

Defined in: ECS/Scene.ts:67

事件系统

类型安全的事件系统。

Implementation of

IScene.eventSystem

Accessors

systems

Get Signature

get systems(): EntitySystem[]

Defined in: ECS/Scene.ts:77

获取系统列表(兼容性属性)

Returns

EntitySystem[]

获取系统列表

Implementation of

IScene.systems

Methods

initialize()

initialize(): void

Defined in: ECS/Scene.ts:119

初始化场景

在场景创建时调用,子类可以重写此方法来设置初始实体和组件。

Returns

void

Implementation of

IScene.initialize


onStart()

onStart(): void

Defined in: ECS/Scene.ts:127

场景开始运行时的回调

在场景开始运行时调用,可以在此方法中执行场景启动逻辑。

Returns

void

Implementation of

IScene.onStart


unload()

unload(): void

Defined in: ECS/Scene.ts:135

场景卸载时的回调

在场景被销毁时调用,可以在此方法中执行清理工作。

Returns

void

Implementation of

IScene.unload


begin()

begin(): void

Defined in: ECS/Scene.ts:143

开始场景,启动实体处理器等

这个方法会启动场景。它将启动实体处理器等,并调用onStart方法。

Returns

void

Implementation of

IScene.begin


end()

end(): void

Defined in: ECS/Scene.ts:158

结束场景,清除实体、实体处理器等

这个方法会结束场景。它将移除所有实体,结束实体处理器等,并调用unload方法。

Returns

void

Implementation of

IScene.end


update()

update(): void

Defined in: ECS/Scene.ts:182

更新场景

Returns

void

Implementation of

IScene.update


createEntity()

createEntity(name): Entity

Defined in: ECS/Scene.ts:202

将实体添加到此场景,并返回它

Parameters

name

string

实体名称

Returns

Entity

Implementation of

IScene.createEntity


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

Entity

要添加的实体

deferCacheClear

boolean = false

是否延迟缓存清理(用于批量操作)

Returns

Entity

Implementation of

IScene.addEntity


createEntities()

createEntities(count, namePrefix): Entity[]

Defined in: ECS/Scene.ts:249

批量创建实体(高性能版本)

Parameters

count

number

要创建的实体数量

namePrefix

string = "Entity"

实体名称前缀

Returns

Entity[]

创建的实体列表

Implementation of

IScene.createEntities


destroyAllEntities()

destroyAllEntities(): void

Defined in: ECS/Scene.ts:277

从场景中删除所有实体

Returns

void

Implementation of

IScene.destroyAllEntities


findEntity()

findEntity(name): null | Entity

Defined in: ECS/Scene.ts:288

搜索并返回第一个具有名称的实体

Parameters

name

string

实体名称

Returns

null | Entity

Implementation of

IScene.findEntity


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

IScene.findEntitiesByTag


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

EntitySystem

处理器

Returns

EntitySystem

Implementation of

IScene.addEntityProcessor


addSystem()

addSystem(system): EntitySystem

Defined in: ECS/Scene.ts:350

添加系统到场景(addEntityProcessor的别名)

Parameters

system

EntitySystem

系统

Returns

EntitySystem


removeEntityProcessor()

removeEntityProcessor(processor): void

Defined in: ECS/Scene.ts:358

从场景中删除EntitySystem处理器

Parameters

processor

EntitySystem

要删除的处理器

Returns

void

Implementation of

IScene.removeEntityProcessor


removeSystem()

removeSystem(system): void

Defined in: ECS/Scene.ts:367

从场景中删除系统(removeEntityProcessor的别名)

Parameters

system

EntitySystem

系统

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

IScene.getEntityProcessor


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>

Released under the MIT License.