Skip to content

Commit

Permalink
adding prefab to entity archetype producer
Browse files Browse the repository at this point in the history
  • Loading branch information
tbg10101 committed Apr 24, 2020
1 parent e3444ce commit edaec02
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 59e50b2783a74e9490437497d06cc731, type: 3}
m_Name: Test Archetype Producer
m_EditorClassIdentifier:
_prefab: {fileID: 8475769614565911509, guid: 623b4872363a965488030ae17263a3fd, type: 3}
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
_prefabs:
- ArchetypeProducer: {fileID: 11400000, guid: 2edfc5aa963d22c4e8ea8e4795d2d3e8, type: 2}
Prefab: {fileID: 8475769614565911509, guid: 623b4872363a965488030ae17263a3fd, type: 3}
- {fileID: 11400000, guid: 2edfc5aa963d22c4e8ea8e4795d2d3e8, type: 2}
_simulationSystems:
- {fileID: 11400000, guid: b55916dcf0ef8ed4a9c0aa675f60e447, type: 2}
_presentationSystems:
Expand Down
5 changes: 5 additions & 0 deletions Runtime/Scripts/Archetypes/ArchetypeProducer.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
using Software10101.DOTS.MonoBehaviours;
using Unity.Entities;
using UnityEngine;

namespace Software10101.DOTS.Archetypes {
public abstract class ArchetypeProducer : ScriptableObject {
[SerializeField]
private EntityMonoBehaviour _prefab = null;
public EntityMonoBehaviour Prefab => _prefab;

public abstract EntityArchetype Produce(EntityManager entityManager);
}
}
20 changes: 7 additions & 13 deletions Runtime/Scripts/MonoBehaviours/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ namespace Software10101.DOTS.MonoBehaviours {
/// </summary>
public class Bootstrapper : WorldBehaviour {
[SerializeField]
private PrefabAndArchetype[] _prefabs = new PrefabAndArchetype[0];
private ArchetypeProducer[] _prefabs = null;
private EntityArchetype[] _prefabArchetypes = null;
private readonly Dictionary<GameObject ,int> _prefabIndices = new Dictionary<GameObject ,int>();

[SerializeField]
Expand Down Expand Up @@ -65,10 +66,11 @@ protected virtual void Start() {
// set up archetypes
EntityManager entityManager = EntityManager;

for (int i = 0; i < _prefabs.Length; i++) {
PrefabAndArchetype p = _prefabs[i];
_prefabArchetypes = new EntityArchetype[_prefabs.Length];

p.Archetype = p.ArchetypeProducer.Produce(entityManager);
for (int i = 0; i < _prefabs.Length; i++) {
ArchetypeProducer p = _prefabs[i];
_prefabArchetypes[i] = p.Produce(entityManager);
_prefabIndices[p.Prefab.gameObject] = i;
}
}
Expand All @@ -89,7 +91,7 @@ internal EntityMonoBehaviour GetPrefab(int prefabIndex) {
EntityCommandBuffer entityCommandBuffer =
GetExistingSystem<PostUpdatePresentationEntityCommandBufferSystem>().CreateCommandBuffer();

Entity entity = entityCommandBuffer.CreateEntity(_prefabs[prefabIndex].Archetype);
Entity entity = entityCommandBuffer.CreateEntity(_prefabArchetypes[prefabIndex]);
entityCommandBuffer.AddComponent(entity, new InitComponentData {
PrefabIndex = prefabIndex
});
Expand All @@ -103,13 +105,5 @@ public void Destroy(Entity entity) {

entityCommandBuffer.AddComponent(entity, new DestroyFlagComponentData());
}

[Serializable]
private class PrefabAndArchetype {
public ArchetypeProducer ArchetypeProducer = null;
public EntityMonoBehaviour Prefab = null;
[NonSerialized]
public EntityArchetype Archetype;
}
}
}
4 changes: 2 additions & 2 deletions 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.1.1",
"version": "0.2.0",
"unity": "2020.1",
"displayName": "DOTS Hybrid Simulation Worlds",
"dependencies": {
Expand All @@ -13,4 +13,4 @@
"url": "https://github.com/tbg10101/DOTS-Hybrid-Simulation-Worlds.git"
},
"type": "library"
}
}

0 comments on commit edaec02

Please sign in to comment.