/// <summary> /// Loads the entity. /// </summary> /// <returns>The entity.</returns> /// <param name="name">Name.</param> static public ZEntity LoadEntity(string name, int ID, string strData) { //create the entity ZEntity newEntity = new ZEntity(); newEntity.Name = name; newEntity.ID = ID; if (strData != null) { StringReader sr = new StringReader(strData); string sl = ""; sl = sr.ReadLine(); //newEntity.ID = Convert.ToInt32(sl); //read type sl = sr.ReadLine(); newEntity.EType = (EntityType)Enum.Parse(typeof(EntityType), sl); while (sl != null) { sl = sr.ReadLine(); if (sl != null && sl.CompareTo(ComponentPrefix) == 0) { var c = LoadAComponent(sr); if (c != null) { newEntity.AddComponent(c); } } } sr.Close(); } return(newEntity); }
/// <summary> /// Builds the sub tree. /// </summary> /// <param name="newEntity">New entity.</param> private void BuildSubTree(ZEntity newEntity, ZEntityNode curNode = null) { if (newEntity == null) { return; } ZEntityNode node = curNode; if (node == null) { node = PoolNodeRoot.FindNode(newEntity.ID); } if (node == null) { return; } foreach (var subNode in node.subs) { var subEntity = CreateSubEntity(subNode.ID); if (newEntity.subEntities == null) { newEntity.subEntities = new List <ZEntity> (); } newEntity.subEntities.Add(subEntity); BuildSubTree(subEntity, subNode); } }
/// <summary> /// Starts the entity. /// </summary> /// <param name="newEntity">New entity.</param> private void StartEntity(ZEntity newEntity) { if (newEntity != null) { newEntity.Start(); } }
/// <summary> /// Creates the entity. for runtime /// </summary> /// <returns>The entity.</returns> /// <param name="ID">I.</param> public ZEntity CreateEntity(int ID) { ZEntity template = FindEntityTemplateByID(ID); if (template == null) { return(null); } ZEntity newEntity = Clone(template); if (newEntity != null) { //build the sub entity BuildSubTree(newEntity); entities.Add(newEntity); newEntity.pool = this; //if (newEntity.EType != EntityType.System) newEntity.Start(); } return(newEntity); }
/// <summary> /// Adds the entity template. /// </summary> /// <param name="en">En.</param> public void AddEntityTemplate(ZEntity en) { if (Application.isPlaying || !Application.isEditor) { throw new System.Exception("this function can't call in run time"); } CurPool.AddEntityTemplate(en); }
/// <summary> /// Releases the entity. /// </summary> /// <param name="en">En.</param> public void ReleaseEntity(ZEntity en) { if (en != null) { en.Destory(); entities.Remove(en); //TODO reuse the entity } }
/// <summary> /// Deletes the entity. /// </summary> /// <returns>The entity.</returns> /// <param name="en">En.</param> public ZEntity DeleteEntity(ZEntity en) { if (Application.isPlaying || !Application.isEditor) { throw new System.Exception("this function can't call in run time"); } entityPool.DelEntityTemplate(en.ID); //PoolData.Entities.RemoveAll ((a) => a.ID == en.ID); PoolNodeRoot.DeleteNode(en.ID); return(en); }
/// <summary> /// Runtimes the build pool. /// </summary> private void RuntimeBuildPool() { InitEntityPoolConfigData(this.PoolNodeRoot); foreach (var e in PoolNodeRoot.GetAllEntities()) { string strData = EntityFileMgr.FindAsset(e.Name); ZEntity en = EntityPoolRuntimeBuildUtils.LoadEntity(e.Name, e.ID, strData); entityPool.AddEntityTemplate(en); } //build the entity tree entityPool.PoolNodeRoot = PoolNodeRoot; }
/// <summary> /// Sels A entity. /// </summary> /// <param name="id">Identifier.</param> public ZEntityNode SelAEntity(int id) { // if (Application.isPlaying || !Application.isEditor) { // throw new System.Exception ("this function can't call in run time"); // } curConfigEntity = entityPool.FindEntityTemplateByID(id); curConfigEntityID = id; //ret current node ZEntityNode node = PoolNodeRoot.FindNode(id); return(node); }
/// <summary> /// Creates the entity. /// </summary> /// <param name="id">Identifier.</param> /// <param name="name">Name.</param> private void CreateEntity(int id, string name) { if (Application.isPlaying || !Application.isEditor) { throw new System.Exception("this function can't call in run time"); } ZEntity en = new ZEntity(); en.ID = id; en.Name = name; curConfigEntity = en; curConfigEntityID = id; entityPool.AddEntityTemplate(en); }
/// <summary> /// Clone this instance. /// </summary> public ZEntity Clone() { ZEntity newEntity = new ZEntity(); newEntity.Name = Name; newEntity.ID = ID; foreach (var e in components) { var newCom = EntityPoolRuntimeBuildUtils.CloneObject(e); if (newCom != null) { newEntity.AddComponent((IZComponent)newCom); } } return(newEntity); }
/// <summary> /// Creates the sub entity. /// </summary> /// <returns>The sub entity.</returns> /// <param name="ID">I.</param> private ZEntity CreateSubEntity(int ID) { ZEntity template = FindEntityTemplateByID(ID); if (template == null) { return(null); } ZEntity newEntity = Clone(template); if (newEntity != null) { newEntity.pool = this; newEntity.Start(); } return(newEntity); }
/// <summary> /// Adds the entity template. /// </summary> /// <param name="en">En.</param> internal void AddEntityTemplate(ZEntity en) { entitieTemplates.Add(en); en.pool = this; }
/// <summary> /// Clone the specified en. /// </summary> /// <param name="en">En.</param> public ZEntity Clone(ZEntity en) { ZEntity newEntity = (ZEntity)EntityPoolRuntimeBuildUtils.CloneObject((object)en); return(newEntity); }