我正在使用 Unity 实体组件系统。当我尝试编写以下代码时:
Entities.WithAll<SomeComponentData, SomeComponentData2, SomeBufferElementData>()
.ForEach((Entity entity, ref SomeComponentData componentData, ref SomeComponentData2 componentData2, DynamicBuffer<SomeBufferElementData> buffer) => {
});
我收到以下错误error CS0315: The type 'Unity.Entities.Entity' cannot be used as type parameter 'T0' in the generic type or method 'EntityQueryBuilder.ForEach<T0>(EntityQueryBuilder.F_D<T0>)'. There is no boxing conversion from 'Unity.Entities.Entity' to 'Unity.Entities.IComponentData'.
当我只使用一个 ComponentData 和一个 BufferElementData 时,它编译得很好,即以下工作:
Entities.WithAll<SomeComponentData, SomeBufferElementData>()
.ForEach((Entity entity, ref SomeComponentData componentData, DynamicBuffer<SomeBufferElementData> buffer) => {
});
我查看了 ForEach 代码,它是生成的代码,其中包含许多组件和动态缓冲区的排列,但我找不到这个。 (请参阅答案 - 我只是看的不够努力!)在不支持 ComponentData 和 BufferElementData 的排列的情况下会发生什么?