Skip to content

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

EntitySystem class

实体系统的基类

用于处理一组符合特定条件的实体。系统是ECS架构中的逻辑处理单元, 负责对拥有特定组件组合的实体执行业务逻辑。

Signature:

typescript
export declare abstract class EntitySystem implements ISystemBase

Implements: ISystemBase

Example

typescript
class MovementSystem extends EntitySystem {
    constructor() {
        super(Transform, Velocity);
    }

    protected process(entities: Entity[]): void {
        for (const entity of entities) {
            const transform = entity.getComponent(Transform);
            const velocity = entity.getComponent(Velocity);
            transform.position.add(velocity.value);
        }
    }
}

Constructors

Constructor

Modifiers

Description

(constructor)(matcher)

Constructs a new instance of the EntitySystem class

Properties

Property

Modifiers

Type

Description

enabled

boolean

获取系统的启用状态

entities

readonly

readonly Entity[]

获取系统处理的实体列表(动态查询)

matcher

readonly

Matcher

获取实体匹配器

scene

Scene | null

这个系统所属的场景

systemName

readonly

string

获取系统名称

updateOrder

number

获取系统的更新时序

Methods

Method

Modifiers

Description

getPerformanceData()

获取系统的性能数据

getPerformanceStats()

获取系统的性能统计

initialize()

系统初始化(框架调用)

在系统创建时调用。框架内部使用,用户不应直接调用。

lateProcess(_entities)

protected

后期处理实体列表

在主要处理逻辑之后执行,子类可以重写此方法。

lateUpdate()

后期更新系统

在所有系统的update方法执行完毕后调用。

onAdded(_entity)

protected

当实体被添加到系统时调用

子类可以重写此方法来处理实体添加事件。

onBegin()

protected

在系统处理开始前调用

子类可以重写此方法进行预处理操作。

onCheckProcessing()

protected

检查系统是否需要处理

在启用系统时有用,但仅偶尔需要处理。 这只影响处理,不影响事件或订阅列表。

onEnd()

protected

系统处理完毕后调用

子类可以重写此方法进行后处理操作。

onInitialize()

protected

系统初始化回调

子类可以重写此方法进行初始化操作。

onRemoved(_entity)

protected

当实体从系统中移除时调用

子类可以重写此方法来处理实体移除事件。

process(_entities)

protected

处理实体列表

系统的核心逻辑,子类必须实现此方法来定义具体的处理逻辑。

reset()

重置系统状态

当系统从场景中移除时调用,重置初始化状态以便重新添加时能正确初始化。

resetPerformanceData()

重置系统的性能数据

setUpdateOrder(order)

设置更新时序

toString()

获取系统信息的字符串表示

update()

更新系统

在每帧调用,处理系统的主要逻辑。

基于 MIT 许可证发布