This repository has been archived by the owner on Mar 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Entity
pointcache edited this page Jan 17, 2017
·
2 revisions
Entity is:
- Access point to it's components
- Will be serialized (position, rotation, parenting)
- Abstraction allowing you to view things from the point of what they represent, without knowing their details.
Entity self registers in EntityManager which gives it a UID.
public class Entity : MonoBehaviour
{
[NotEditableString]
public string database_ID;
[NotEditableString]
public string instance_ID;
[NotEditableString]
public string blueprint_ID;
public string ID
{
get
{
if (String.IsNullOrEmpty(instance_ID))
{
instance_ID = EntityManager.get_id();
}
return instance_ID;
}
}
void OnEnable()
{
EntityManager.RegisterEntity(this);
}
void OnDisable()
{
EntityManager.UnRegisterEntity(this);
}
public T GetEntityComponent<T>() where T : ComponentBase
{
return Pool<T>.getComponent(ID);
}
/// <summary>
/// Not the most performant way but will do for now.
/// </summary>
/// <returns></returns>
public List<ComponentBase> GetAllEntityComponents() {
List<ComponentBase> comps = new List<ComponentBase>();
comps.AddRange(GetComponents<ComponentBase>());
getAllCompsRecursive(transform, comps);
foreach (Transform t in transform) {
getAllCompsRecursive(t, comps);
}
return comps;
}
void getAllCompsRecursive(Transform tr, List<ComponentBase> comps) {
if (tr.GetComponent<Entity>())
return;
else {
comps.AddRange(tr.GetComponents<ComponentBase>());
foreach (Transform t in tr) {
getAllCompsRecursive(t, comps);
}
}
}
public void MakePersistent() {
PersistentDataSystem.MakePersistent(this);
}
}