Skip to content

Commit

Permalink
adding the ability to create multiple entites ion a single command bu…
Browse files Browse the repository at this point in the history
…ffer
  • Loading branch information
tbg10101 committed Aug 23, 2020
1 parent 4206e80 commit d49d854
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions Runtime/Scripts/MonoBehaviours/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PostManagedMonoBehaviourUpdateEntityCommandBufferSystem>().CreateCommandBuffer();
public (Entity, EntityCommandBuffer) Create(int prefabIndex, CreationBufferToken creationBufferToken = null) {
EntityCommandBuffer ecb = creationBufferToken?.EntityCommandBuffer
?? GetExistingSystem<PostManagedMonoBehaviourUpdateEntityCommandBufferSystem>()
.CreateCommandBuffer();

Entity entity = ecb.CreateEntity(_archetypes[prefabIndex]);
ecb.AddComponent(entity, new SpawnPrefabComponentData {
Expand All @@ -138,5 +142,18 @@ public void Destroy(Entity entity) {
GetExistingSystem<PostManagedMonoBehaviourUpdateEntityCommandBufferSystem>().CreateCommandBuffer();
ecb.AddComponent(entity, new DestroyFlagComponentData());
}

public CreationBufferToken GetCreationBufferToken() {
return new CreationBufferToken {
EntityCommandBuffer =
GetExistingSystem<PostManagedMonoBehaviourUpdateEntityCommandBufferSystem>().CreateCommandBuffer()
};
}

public class CreationBufferToken {
internal EntityCommandBuffer EntityCommandBuffer;

internal CreationBufferToken() { }
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit d49d854

Please sign in to comment.