我正在为 C# 中 ECS 的自定义实现而苦苦挣扎。
我将组件存储在静态类中,如下所示:
internal static class ComponentStorage<T> where T : struct, IComponent
{
private static readonly T[] components = new T[capacity];
public static ref T Get(int index)
{
return ref components[index];
}
public static void Add(T component, int index)
{
components[index] = component;
}
}
我这样做有两个主要原因:
- 它允许我将我的组件(原样)存储在连续的结构数组中
- 我无需装箱/拆箱即可轻松获得组件
我用表格等管理管理器类中的组件。
到目前为止,我的实现运行良好,但基于这种方法我很紧张。
- 由于通用静力学,我是否缺少任何东西,例如隐藏拳击?性能测试按预期进行,但我还没有实现任何 SystemManager 类型的东西,因为这样做非常棘手,所以如果我一直都错了,我不想从那开始。
我找不到静态通用装箱问题的正确答案,而且我还没有看到任何 ecs 使用它。