Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.2KB

  1. using System;
  2. namespace Svelto.ECS
  3. {
  4. public struct DynamicEntityDescriptorInfo<TType>:IEntityDescriptor where TType : IEntityDescriptor, new()
  5. {
  6. public DynamicEntityDescriptorInfo(IEntityBuilder[] extraEntities)
  7. {
  8. DBC.ECS.Check.Require(extraEntities.Length > 0,
  9. "don't use a DynamicEntityDescriptorInfo if you don't need to use extra EntityViews");
  10. var defaultEntities = EntityDescriptorTemplate<TType>.descriptor.entitiesToBuild;
  11. var length = defaultEntities.Length;
  12. entitiesToBuild = new IEntityBuilder[length + extraEntities.Length + 1];
  13. Array.Copy(defaultEntities, 0, entitiesToBuild, 0, length);
  14. Array.Copy(extraEntities, 0, entitiesToBuild, length, extraEntities.Length);
  15. var _builder = new EntityBuilder<EntityInfoView>
  16. {
  17. _initializer = new EntityInfoView
  18. {
  19. entitiesToBuild = entitiesToBuild,
  20. type = typeof(TType)
  21. }
  22. };
  23. entitiesToBuild[entitiesToBuild.Length - 1] = _builder;
  24. }
  25. public IEntityBuilder[] entitiesToBuild { get; }
  26. }
  27. }