Skip to content

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

EntityQueryBuilder class

实体查询构建器

提供流式API来构建复杂的实体查询条件。支持组件过滤、标签过滤、状态过滤和自定义条件。

Signature:

typescript
export declare class EntityQueryBuilder

Example

typescript
const results = entityManager.query()
    .withAll(PositionComponent, HealthComponent)
    .without(VelocityComponent)
    .withTag(1)
    .active()
    .where(entity => entity.name.startsWith("Player"))
    .execute();

Constructors

Constructor

Modifiers

Description

(constructor)(entityManager)

创建查询构建器实例

Methods

Method

Modifiers

Description

active()

添加激活状态过滤条件

返回的实体必须处于激活状态(active = true)。

count()

执行查询并返回匹配实体的数量

enabled()

添加启用状态过滤条件

返回的实体必须处于启用状态(enabled = true)。

execute()

执行查询并返回所有匹配的实体

first()

执行查询并返回第一个匹配的实体

forEach(action)

对所有匹配的实体执行指定操作

where(predicate)

添加自定义过滤条件

允许用户定义复杂的过滤逻辑。

withAll(componentTypes)

添加必须包含的组件条件

返回的实体必须包含所有指定的组件类型。

withAny(componentTypes)

添加至少包含一个的组件条件

返回的实体必须至少包含其中一个指定的组件类型。

without(componentTypes)

添加不能包含的组件条件

返回的实体不能包含任何指定的组件类型。

withoutTag(tag)

添加不能包含的标签条件

返回的实体不能具有指定的标签。

withTag(tag)

添加必须包含的标签条件

返回的实体必须具有指定的标签。

基于 MIT 许可证发布