diff --git a/Assets/Scripts/Spawner.cs b/Assets/Scripts/Spawner.cs
index 1aab139..09441c0 100644
--- a/Assets/Scripts/Spawner.cs
+++ b/Assets/Scripts/Spawner.cs
@@ -12,7 +12,7 @@ public class Spawner : MonoBehaviour {
///
/// Type.
/// Position.
- public GameObject Spawn(EntityType type, Vector3 position, uint[] ids) {
+ public GameObject Spawn(EntityType type, Vector3 position, uint[] ids = null) {
GameObject Spawned = null;
switch (type) {
case EntityType.PC:
@@ -23,18 +23,22 @@ public class Spawner : MonoBehaviour {
break;
}
if (Spawned != null) {
- SyncDB.AddEntity(Spawned, ids);
+ if (ids != null) {
+ SyncDB.AddEntity(Spawned, ids);
+ } else {
+ SyncDB.AddEntity(Spawned, SyncDB.GetNewEntityIDs(Spawned));
+ }
}
return Spawned;
}
private void Start() {
- Spawn(EntityType.PC, new Vector3(), new uint[]{ SyncDB.CreateID() });
+ Spawn(EntityType.PC, new Vector3());
}
private void Update() {
if (Input.GetButtonDown("Jump") && !Term.IsVisible()) {
- Spawn(EntityType.NPC, new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-2f, 2f)), new uint[]{ SyncDB.CreateID() });
+ Spawn(EntityType.NPC, new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-2f, 2f)));
}
}
}
diff --git a/Assets/Scripts/SyncDB.cs b/Assets/Scripts/SyncDB.cs
index 8c76716..152f008 100644
--- a/Assets/Scripts/SyncDB.cs
+++ b/Assets/Scripts/SyncDB.cs
@@ -22,11 +22,14 @@ public class SyncDB : MonoBehaviour {
}
}
- public uint[] GetEntityIDs(GameObject gameObject) {
+ public uint[] GetEntityIDs(GameObject gameObject, bool newIDs = false) {
List IDs = new List();
for (int i = 0; i < SyncableClasses.Length; i++) {
SyncBase Syncable = (SyncBase) gameObject.GetComponent(SyncableClasses[i]);
if (Syncable != null) {
+ if (newIDs) {
+ Syncable.ID = CreateID();
+ }
IDs.Add(Syncable.ID);
}
}
@@ -37,6 +40,10 @@ public class SyncDB : MonoBehaviour {
return IDArray;
}
+ public uint[] GetNewEntityIDs(GameObject gameObject) {
+ return GetEntityIDs(gameObject, true);
+ }
+
public SyncBase Get(uint id) {
return Database[id];
}