Class/Struct Info |
|---|
public sealed class BatchProcessor 批量处理器用于批量处理实体的组件和标签的添加、删除操作,以减少结构性更改的次数(结构性更改通常代价较高),重点通过Process或ProcessOn方法一次性对实体进行修改操作,从而减少结构性变更的次数,提高性能。 |
var world = new IECSWorld();
// 创建独立的批处理对象,可以应用到任意实体
var batch = new BatchProcessor();
// 配置批处理操作
batch.AddComponent(new Weapon { damage = 25.0f })
.AddComponent(new Inventory { capacity = 20 })
.AddTag<EquippedTag>()
.RemoveComponent<UnarmedTag>();
// 批量处理器中的指令数量
batch.BatchedCommandCount; // 4 Qualifier and Type | Method Name and Description |
|---|---|
string | ToString() 描述批量处理器信息。 |
void | 重置批量处理器中的指令,清除当前批处理中的所有命令,包括添加和删除的标签、组件。 |
void | Process() 将批量处理器中的指令提交应用到前一个操作的实体上。 |
BatchProcessor | ProcessOn(IEntity entity) 将批量处理器中的指令提交应用到指定的实体上。 |
BatchProcessor | AddComponent<T>(in T component) 向批量处理器中添加一个添加组件的指令,并设置组件的值。 |
BatchProcessor | 向批量处理器中添加一个添加标签的指令。 |
BatchProcessor | 向批量处理器中添加一个移除组件的指令。 |
BatchProcessor | 向批量处理器中添加一个移除标签的指令。 |
BatchProcessor | AddTags(in ITags iTags) 向批量处理器中添加多个添加标签的指令。 |
BatchProcessor | RemoveTags(in ITags iTags) 向批量处理器中添加多个移除标签的指令。 |
BatchProcessor | Active() 向批量处理器中添加一个激活实体的指令。 |
BatchProcessor | Inactive() 向批量处理器中添加一个禁用实体的指令。 |
Method |
|---|
string ToString() 描述批量处理器信息,打印的组件和标签名字均会带命名域。 |
Return
Type | Description |
|---|---|
string | 批量处理器信息。 |
Sample Code
var world = new IECSWorld();
// 创建独立的批处理对象,可以应用到任意实体
var batch = new BatchProcessor();
// 配置批处理操作
batch.AddComponent(new PgdPosition(1, 1, 1))
.AddComponent(new Name("test"))
.RemoveComponent<PgdRotation>()
.AddTag<TestTag>()
.RemoveTag<TestTag2>();
// 打印批量处理器信息,带命名域。预设组件/标签命名域为"Pgd.",自定义组件/标签/共享组件根据实际情况而定
batch.ToString(); // "EntityId: 1, AddOptions:{ ComponentOrTagCount: 3, Components: [Pgd.Name, Pgd.PgdPosition], Tags: [TestTag]}, RemoveOptions:{ ComponentOrTagCount: 2, Components: [Pgd.PgdRotation], Tags: [TestTag2]}" Method |
|---|
void ResetBatch() 重置批量处理器中的指令,清除当前批处理中的所有命令,包括添加和删除的标签、组件。 |
Sample Code
var world = new IECSWorld();
// 创建独立的批处理对象,可以应用到任意实体
var batch = new BatchProcessor();
// 配置批处理操作
batch.AddComponent(new PgdPosition(1, 1, 1))
.AddComponent(new Name("test"))
.RemoveComponent<PgdRotation>()
.AddTag<TestTag>()
.RemoveTag<TestTag2>();
// 重置批量处理器
batch.ResetBatch(); Method |
|---|
void Process() 将批量处理器中的指令提交应用到前一个操作的实体上。 |
Sample Code
var world = new IECSWorld();
var entity = world.CreateEntity();
// 批处理方式:一次结构性变化
entity.GetBatchProcessor()
.AddComponent(new PgdPosition(1, 2, 3))
.AddComponent<Velocity>()
.AddTag<PlayerTag>()
.RemoveComponent<Health>()
.Process(); // 所有变更在此时一次性应用 Method |
|---|
BatchProcessor ProcessOn(IEntity entity) 将批量处理器中的指令提交应用到指定的实体上。 支持链式调用。 |
Parameters
Name | Type | Description |
|---|---|---|
entity | IEntity | 实体。 |
Return
Type | Description |
|---|---|
BatchProcessor | 批量处理器。 |
Sample Code
var world = new IECSWorld();
var entity = world.CreateEntity();
// 创建独立的批处理对象,可以应用到任意实体
var batch = new BatchProcessor();
// 配置批处理操作
batch.AddComponent(new Weapon { damage = 25.0f })
.AddComponent(new Inventory { capacity = 20 })
.AddTag<EquippedTag>()
.RemoveComponent<UnarmedTag>();
// 应用到实体上
batch.ProcessOn(entity); Method |
|---|
BatchProcessor AddComponent<T>(in T component) 向批量处理器中添加一个添加组件的指令,并设置组件的值。 T为IComponent。支持链式调用。 |
Parameters
Name | Type | Description |
|---|---|---|
component | T | 添加组件。 |
Return
Type | Description |
|---|---|
BatchProcessor | 批量处理器。 |
Sample Code
var world = new IECSWorld();
var batch = new BatchProcessor();
// 配置批处理操作
batch.AddComponent(new Weapon { damage = 25.0f }); Method |
|---|
BatchProcessor AddTag<T>() 向批量处理器中添加一个添加标签的指令。 T为ITag。支持链式调用。 |
Return
Type | Description |
|---|---|
BatchProcessor | 批量处理器。 |
Sample Code
var world = new IECSWorld(); var batch = new BatchProcessor(); // 配置批处理操作 batch.AddTag<EquippedTag>();
Method |
|---|
BatchProcessor RemoveComponent<T>() 向批量处理器中添加一个移除组件的指令。 T为IComponent。支持链式调用。 |
Return
Type | Description |
|---|---|
BatchProcessor | 批量处理器。 |
Sample Code
var world = new IECSWorld(); var batch = new BatchProcessor(); // 配置批处理操作 batch.RemoveComponent<UnarmedTag>();
Method |
|---|
BatchProcessor RemoveTag<T>() 向批量处理器中添加一个移除标签的指令。 T为ITag。支持链式调用。 |
Return
Type | Description |
|---|---|
BatchProcessor | 批量处理器。 |
Sample Code
var world = new IECSWorld(); var batch = new BatchProcessor(); // 配置批处理操作 batch.RemoveTag<EquippedTag>();
Method |
|---|
BatchProcessor AddTags(in ITags iTags) 向批量处理器中添加多个添加标签的指令。 支持链式调用。 |
Parameters
Name | Type | Description |
|---|---|---|
iTags | ITags | 添加标签集合。 |
Return
Type | Description |
|---|---|
BatchProcessor | 批量处理器。 |
Sample Code
var world = new IECSWorld(); var batch = new BatchProcessor(); // 配置批处理操作 batch.AddTags(ITags.Get<TestTag1, TestTag2>());
Method |
|---|
BatchProcessor RemoveTags(in ITags iTags) 向批量处理器中添加多个移除标签的指令。 支持链式调用。 |
Parameters
Name | Type | Description |
|---|---|---|
iTags | ITags | 移除标签集合。 |
Return
Type | Description |
|---|---|
BatchProcessor | 批量处理器。 |
Sample Code
var world = new IECSWorld(); var batch = new BatchProcessor(); // 配置批处理操作 batch.RemoveTags(ITags.Get<TestTag1, TestTag2>());