ECS:WriteGroup
定义:
使用WriteGroup标记了同一个component的components就属于一个WriteGroup:
public struct W : IComponentData { public int Value; } [WriteGroup(typeof(W))] public struct A : IComponentData { public int Value; } [WriteGroup(typeof(W))] public struct B : IComponentData { public int Value; }上面的代码中,W A B就属于同一个W Group。 使用: 让WriteGroup生效的方法:在Query中开启WriteGroup选项:
public class AddingSystem : JobComponentSystem { protected override JobHandle OnUpdate(JobHandle inputDeps) { return Entities .WithEntityQueryOptions(EntityQueryOptions.FilterWriteGroup) .ForEach((ref W w, in B b) => { }).Schedule(inputDeps);} }使用EntityQueryDesc:
public class AddingSystem : JobComponentSystem { private EntityQuery m_Query; protected override void OnCreate() { var queryDescription = new EntityQueryDesc { All = new ComponentType[] { ComponentType.ReadWrite这样,在Query的时候,WriteGroup就会影响查询的结果了。 规则: (1)同一个Group的components,查询时只会包含一个,同组的component相互是互斥的,比如上面的W A B,查询结果只会返回包含W A B任意一个的entity; (2)可以显示的要求包含同组的其他component。 以此规则计算,上面的例子中,query结果是包含W和B的,包含A的会被排除。 应用: (1)扩展或覆盖原有system功能的写入目标,可以保证原来的system正常工作,但是包含了自己的特殊component的entity按照覆盖的方式工作。 Unity.Transforms里面的每一个component都是用了write group的特性。 (2)提供system的可扩展性。(), ComponentType.ReadOnly() }, Options = EntityQueryOptions.FilterWriteGroup }; m_Query = GetEntityQuery(queryDescription); } // Define Job and schedule... }