diff --git a/Runtime/Scripts/MonoBehaviours/Bootstrapper.cs b/Runtime/Scripts/MonoBehaviours/Bootstrapper.cs index 2ff925d..6724b91 100644 --- a/Runtime/Scripts/MonoBehaviours/Bootstrapper.cs +++ b/Runtime/Scripts/MonoBehaviours/Bootstrapper.cs @@ -117,13 +117,17 @@ internal EntityMonoBehaviour GetPrefab(int prefabIndex) { return _archetypeProducers[prefabIndex].Prefab; } - public (Entity, EntityCommandBuffer) Create(ArchetypeProducer archetypeProducer) { + public (Entity, EntityCommandBuffer) Create( + ArchetypeProducer archetypeProducer, + CreationBufferToken creationBufferToken = null) { + return Create(_archetypeProducerIndices[archetypeProducer]); } - public (Entity, EntityCommandBuffer) Create(int prefabIndex) { - EntityCommandBuffer ecb = - GetExistingSystem().CreateCommandBuffer(); + public (Entity, EntityCommandBuffer) Create(int prefabIndex, CreationBufferToken creationBufferToken = null) { + EntityCommandBuffer ecb = creationBufferToken?.EntityCommandBuffer + ?? GetExistingSystem() + .CreateCommandBuffer(); Entity entity = ecb.CreateEntity(_archetypes[prefabIndex]); ecb.AddComponent(entity, new SpawnPrefabComponentData { @@ -138,5 +142,18 @@ public void Destroy(Entity entity) { GetExistingSystem().CreateCommandBuffer(); ecb.AddComponent(entity, new DestroyFlagComponentData()); } + + public CreationBufferToken GetCreationBufferToken() { + return new CreationBufferToken { + EntityCommandBuffer = + GetExistingSystem().CreateCommandBuffer() + }; + } + + public class CreationBufferToken { + internal EntityCommandBuffer EntityCommandBuffer; + + internal CreationBufferToken() { } + } } } diff --git a/package.json b/package.json index f7ec520..2edb4d0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.10101software.dots.hybridsimulation", "description": "A framework for using FixedUpdate in a simulation world which is linked to a GameObject-based presentation layer.", - "version": "0.6.4", + "version": "0.6.5", "unity": "2020.1", "displayName": "DOTS Hybrid Simulation Worlds", "dependencies": {