Skip to content

Home > @esengine/ecs-framework-monorepo > Scene

Scene class

游戏场景默认实现类

实现IScene接口,提供场景的基础功能。 推荐使用组合而非继承的方式来构建自定义场景。

Signature:

typescript
export declare class Scene implements IScene

Implements: IScene

Constructors

Constructor

Modifiers

Description

(constructor)(config)

创建场景实例

Properties

Property

Modifiers

Type

Description

componentStorageManager

readonly

ComponentStorageManager

组件存储管理器

高性能的组件存储和查询系统。

entities

readonly

EntityList

场景中的实体集合

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

entityProcessors

readonly

EntityProcessorList

实体系统处理器集合

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

eventSystem

readonly

TypeSafeEventSystem

事件系统

类型安全的事件系统。

identifierPool

readonly

IdentifierPool

实体ID池

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

name

string

场景名称

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

querySystem

readonly

QuerySystem

查询系统

基于位掩码的高性能实体查询系统。

systems

readonly

EntitySystem[]

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

Methods

Method

Modifiers

Description

addEntity(entity, deferCacheClear)

在场景的实体列表中添加一个实体

addEntityProcessor(processor)

在场景中添加一个EntitySystem处理器

addSystem(system)

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

begin()

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

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

createEntities(count, namePrefix)

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

createEntity(name)

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

destroyAllEntities()

从场景中删除所有实体

end()

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

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

findEntitiesByTag(tag)

根据标签查找实体

findEntity(name)

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

findEntityById(id)

根据ID查找实体

getDebugInfo()

获取场景的调试信息

getEntitiesByTag(tag)

根据标签查找实体(别名方法)

getEntityByName(name)

根据名称查找实体(别名方法)

getEntityProcessor(type)

获取指定类型的EntitySystem处理器

getStats()

获取场景统计信息

initialize()

初始化场景

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

onStart()

场景开始运行时的回调

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

removeEntityProcessor(processor)

从场景中删除EntitySystem处理器

unload()

场景卸载时的回调

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

update()

更新场景,更新实体组件、实体处理器等

基于 MIT 许可证发布