using UnityEngine;
using Cyber.Console;
namespace Cyber.Entities {
///
/// A utility class to spawn entities into the world based on
/// their .
///
public class Spawner : MonoBehaviour {
///
/// The this should be using to
/// set entities' IDs.
///
public SyncDB SyncDB;
///
/// The prefab.
///
public GameObject PCEntityPrefab;
///
/// The prefab.
///
public GameObject NPCEntityPrefab;
///
/// Spawns an entity and returns that entity.
///
/// Type.
/// Position.
/// The ids of the entity's synced components. Should be
/// set if they exist already (eg. the server has sent them over). These
/// ids should be from . To create new
/// ids, leave as the default (null).
public GameObject Spawn(EntityType type, Vector3 position, int[] ids = null) {
GameObject Spawned = null;
switch (type) {
case EntityType.PC:
Spawned = Instantiate(PCEntityPrefab, position, new Quaternion(), transform);
break;
case EntityType.NPC:
Spawned = Instantiate(NPCEntityPrefab, position, new Quaternion(), transform);
break;
}
if (Spawned != null) {
if (ids != null) {
SyncDB.AddEntity(Spawned, ids);
} else {
SyncDB.AddEntity(Spawned, SyncDB.GetNewEntityIDs(Spawned));
}
}
return Spawned;
}
public void Remove(GameObject gameObject) {
SyncDB.RemoveEntity(gameObject);
Destroy(gameObject);
}
}
}