#Is there a way to have an abstract Baker?

1 messages · Page 1 of 1 (latest)

dull valley
#

I would love to be able to do something like this:

public abstract class BakeDataAuthoring<T> : MonoBehaviour where T : unmanaged, IComponentData {
public T data;

public class ComponentDataBaker : Baker<BakeDataAuthoring<T>> {

    public override void Bake(BakeDataAuthoring<T> authoring) {
        var entity = GetEntity(TransformUsageFlags.Dynamic);

        AddComponent(entity, authoring.data);
    }
}

}

So I can do like:

public class MoveDataAuthoring : BakeDataAuthoring<MoveData> {}

ArgumentException: Cannot create an instance of BakeDataAuthoring`1+ComponentDataBaker[T]
because Type.ContainsGenericParameters is true.

long jackal
#

I think you'd need to explicitly implement the baker as well

#
    public T data;

    public abstract class ComponentDataBaker : Baker<BakeDataAuthoring<T>> {

        public override void Bake(BakeDataAuthoring<T> authoring) {
            var entity = GetEntity(TransformUsageFlags.Dynamic);

            AddComponent(entity, authoring.data);
        }
    }
}```
```public class MoveDataAuthoring : BakeDataAuthoring<MoveData> {}
public class MoveDataBaker : MoveDataAuthoring.ComponentDataBaker {}```