using Svelto.ECS.Internal; namespace Svelto.ECS { /// /// Inherit from an ExtendibleEntityDescriptor to extend a base entity descriptor that can be used /// to swap and remove specialized entities from abstract engines /// /// Usage Example: /// /// class SpecialisedDescriptor : ExtendibleEntityDescriptor /// { /// public SpecialisedDescriptor() : base (new IComponentBuilder[] /// { /// new ComponentBuilder() //add more components to the base descriptor /// }) /// { /// ExtendWith(); //add extra components from descriptors that act as contract /// } /// } /// /// public abstract class ExtendibleEntityDescriptor : IDynamicEntityDescriptor where TType : IEntityDescriptor, new() { static ExtendibleEntityDescriptor() { //I am removing this check because in reality there is not a strong reason to forbid it and //furthermore it's already possible to extend a SerializableEntityDescriptor through DynamicEntityDescriptor // if (typeof(ISerializableEntityDescriptor).IsAssignableFrom(typeof(TType))) // throw new Exception( // $"SerializableEntityDescriptors cannot be used as base entity descriptor: {typeof(TType)}"); } protected ExtendibleEntityDescriptor(IComponentBuilder[] extraEntities) { _dynamicDescriptor = new DynamicEntityDescriptor(extraEntities); } protected ExtendibleEntityDescriptor() { _dynamicDescriptor = DynamicEntityDescriptor.CreateDynamicEntityDescriptor(); } protected ExtendibleEntityDescriptor ExtendWith() where T : IEntityDescriptor, new() { _dynamicDescriptor.ExtendWith(); return this; } protected ExtendibleEntityDescriptor ExtendWith(IComponentBuilder[] extraEntities) { _dynamicDescriptor.ExtendWith(extraEntities); return this; } protected void Add() where T : struct, _IInternalEntityComponent { _dynamicDescriptor.Add(); } protected void Add() where T : struct, _IInternalEntityComponent where U : struct, _IInternalEntityComponent { _dynamicDescriptor.Add(); } protected void Add() where T : struct, _IInternalEntityComponent where U : struct, _IInternalEntityComponent where V : struct, _IInternalEntityComponent { _dynamicDescriptor.Add(); } public IComponentBuilder[] componentsToBuild => _dynamicDescriptor.componentsToBuild; DynamicEntityDescriptor _dynamicDescriptor; } }