Class/Struct Info |
|---|
public readonly struct QueryEntities : IEnumerable<IEntity> 查询核心类,包括查询基础功能和泛型实现。 |
Qualifier and Type | Method Name and Description |
|---|---|
string | ToString() 返回查询实体数量字符串。 |
EntitySet | 返回查询实体的列表。 |
EntitySet | ToEntitySet(EntitySet set) 将查询实体放入输入的实体列表中。 |
EntitiesEnumerator | 获取实体枚举器,用于遍历查询结果的接口,foreach自动调用。 |
void | ProcessBatchOnAll(BatchProcessor processor) 将批处理应用到查询结果集中的所有实体。 |
Method |
|---|
string ToString() 返回查询实体数量字符串,打印的组件和标签名字均会带命名域。 |
Return
Type | Description |
|---|---|
string | 查询实体数量。 |
Sample Code
var world = new IECSWorld();
var query = world.Query();
// 打印查询实体数量。预设组件/标签命名域为"Pgd.",自定义组件/标签/共享组件根据实际情况而定
query.Entities.ToString(); // "Query: { Components:[], Tags:[Pgd.Inactive], SharedComponents:[]}" Method |
|---|
EntitySet ToEntitySet() 返回查询实体的列表。 |
Return
Type | Description |
|---|---|
EntitySet | 查询实体的列表。 |
Sample Code
var world = new IECSWorld(); // 创建一个Query var query = world.Query(); // 将QueryEntities匹配的所有实体转换成EntitySet var entitySet = query.Entities.ToEntitySet();
Method |
|---|
EntitySet ToEntitySet(EntitySet set) 将查询实体放入输入的实体列表中。 |
Parameters
Name | Type | Description |
|---|---|---|
list | EntitySet | 实体列表。 |
Return
Type | Description |
|---|---|
EntitySet | 查询实体的列表。 |
Sample Code
var world = new IECSWorld(); // 创建一个Query var query = world.Query(); // 将QueryEntities匹配的所有实体转换成EntitySet,指定输出集合 var entitySet = query.Entities.ToEntitySet(new EntitySet());
Method |
|---|
EntitiesEnumerator GetEnumerator() 获取实体枚举器,用于遍历查询结果的接口,foreach自动调用。 |
Return
Type | Description |
|---|---|
EntitiesEnumerator | 实体枚举器。 |
Sample Code
var world = new IECSWorld();
// 创建一个Query
var query = world.Query();
// foreach自动调用GetEnumerator(),用QueryEntities进行查询迭代,遍历实体
foreach(var entity in query.Entities)
{
/*处理逻辑*/
} Method |
|---|
void ProcessBatchOnAll(BatchProcessor processor) 将批处理应用到查询结果集中的所有实体。 |
Parameters
Name | Type | Description |
|---|---|---|
processor | BatchProcessor | 批处理器,包含一组组件和标签操作。 |
Sample Code
var world = new IECSWorld(); var query = world.Query(); var batch = new BatchProcessor(); batch.Inactive(); batch.AddComponent(new PgdPosition()); // 将批处理器中的指令批量应用到查询匹配的所有实体上 query.Entities.ProcessBatchOnAll(batch);