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.

44 lines
1.5KB

  1. #if UNITY_ECS
  2. namespace Svelto.ECS.SveltoOnDOTS
  3. {
  4. public interface ISveltoOnDOTSHandleLifeTimeEngine
  5. {
  6. EntityCommandBufferForSvelto entityCommandBuffer { set; }
  7. }
  8. public class SveltoOnDOTSHandleLifeTimeEngine<DOTSEntityComponent> : ISveltoOnDOTSHandleLifeTimeEngine,
  9. IReactOnRemove<DOTSEntityComponent>,
  10. IReactOnSwapEx<DOTSEntityComponent> where DOTSEntityComponent : unmanaged, IEntityComponentForDOTS
  11. {
  12. public void Remove(ref DOTSEntityComponent entityComponent, EGID egid)
  13. {
  14. ECB.DestroyEntity(entityComponent.dotsEntity);
  15. }
  16. EntityCommandBufferForSvelto ECB { get; set; }
  17. public EntityCommandBufferForSvelto entityCommandBuffer
  18. {
  19. set => ECB = value;
  20. }
  21. public void MovedTo((uint start, uint end) rangeOfEntities, in EntityCollection<DOTSEntityComponent> collection,
  22. ExclusiveGroupStruct _, ExclusiveGroupStruct toGroup)
  23. {
  24. var (entities, entityIDs, _) = collection;
  25. for (uint i = rangeOfEntities.start; i < rangeOfEntities.end; i++)
  26. {
  27. ref var entityComponent = ref entities[i];
  28. ECB.SetSharedComponent(entityComponent.dotsEntity, new DOTSSveltoGroupID(toGroup));
  29. ECB.SetComponent(entityComponent.dotsEntity, new DOTSSveltoEGID
  30. {
  31. egid = new EGID(entityIDs[i], toGroup)
  32. });
  33. }
  34. }
  35. }
  36. }
  37. #endif