This repository was 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.
publicclassEntity:MonoBehaviour{[NotEditableString]publicstringdatabase_ID;[NotEditableString]publicstringinstance_ID;[NotEditableString]publicstringblueprint_ID;publicstringID{get{if(String.IsNullOrEmpty(instance_ID)){instance_ID=EntityManager.get_id();}returninstance_ID;}}voidOnEnable(){EntityManager.RegisterEntity(this);}voidOnDisable(){EntityManager.UnRegisterEntity(this);}publicTGetEntityComponent<T>()whereT:ComponentBase{returnPool<T>.getComponent(ID);}/// <summary>/// Not the most performant way but will do for now./// </summary>/// <returns></returns>publicList<ComponentBase>GetAllEntityComponents(){List<ComponentBase>comps=newList<ComponentBase>();comps.AddRange(GetComponents<ComponentBase>());getAllCompsRecursive(transform,comps);foreach(Transformtintransform){getAllCompsRecursive(t,comps);}returncomps;}voidgetAllCompsRecursive(Transformtr,List<ComponentBase>comps){if(tr.GetComponent<Entity>())return;else{comps.AddRange(tr.GetComponents<ComponentBase>());foreach(Transformtintr){getAllCompsRecursive(t,comps);}}}publicvoidMakePersistent(){PersistentDataSystem.MakePersistent(this);}}