예제 #1
0
        /// <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);
            }
        }
예제 #2
0
파일: ZEntityNode.cs 프로젝트: zzh-527/ZECS
        /// <summary>
        /// Sets the relation.
        /// </summary>
        /// <param name="parentID">Parent I.</param>
        /// <param name="subID">Sub I.</param>
        public void SetRelation(int parentID, int subID)
        {
            ZEntityNode parentParentNode = null;
            ZEntityNode parentNode       = FindNodeWithParent(parentID, out parentParentNode);

            ZEntityNode oldParentNode = null;
            ZEntityNode subNode       = FindNodeWithParent(subID, out oldParentNode);

            if (oldParentNode != null && oldParentNode.ID == parentID)
            {
                return;
            }

            if (parentParentNode != null && parentParentNode.ID == subID)
            {
                return;
            }

            if (parentNode == null)
            {
                return;
            }


            parentNode.subs.Add(subNode);

            if (oldParentNode != null)
            {
                oldParentNode.subs.Remove(subNode);
            }
            else
            {
                Entities.Remove(subNode);
            }
        }
예제 #3
0
파일: ZEntityNode.cs 프로젝트: zzh-527/ZECS
 /// <summary>
 /// Adds the entity data.
 /// </summary>
 /// <param name="data">Data.</param>
 /// <param name="parent">Parent.</param>
 public void AddEntityData(ZEntityNode data, ZEntityNode parent = null)
 {
     if (parent != null)
     {
         parent.subs.Add(data);
     }
     else
     {
         Entities.Add(data);
     }
 }
예제 #4
0
파일: ZEntityNode.cs 프로젝트: zzh-527/ZECS
        /// <summary>
        /// Determines whether this instance isolate relation the specified subID.
        /// </summary>
        /// <returns><c>true</c> if this instance isolate relation the specified subID; otherwise, <c>false</c>.</returns>
        /// <param name="subID">Sub I.</param>
        public void IsolateRelation(int subID)
        {
            ZEntityNode oldParentNode = null;
            ZEntityNode subNode       = FindNodeWithParent(subID, out oldParentNode);

            if (oldParentNode != null)
            {
                oldParentNode.subs.Remove(subNode);

                Entities.Add(subNode);
            }
        }
예제 #5
0
파일: ZEntityNode.cs 프로젝트: zzh-527/ZECS
        /// <summary>
        /// Deletes the node.
        /// </summary>
        /// <param name="id">Identifier.</param>
        public void DeleteNode(int id)
        {
            ZEntityNode parent = null;
            var         node   = FindNodeWithParent(id, out parent);

            if (parent != null)
            {
                parent.subs.Remove(node);
            }
            else
            {
                Entities.Remove(node);
            }
        }
예제 #6
0
        /// <summary>
        /// Creates the entity at node.
        /// </summary>
        /// <param name="node">Node.</param>
        public void CreateEntityAt(ZEntityNode node)
        {
            if (Application.isPlaying || !Application.isEditor)
            {
                throw new System.Exception("this function can't call in run time");
            }

            int    id     = PoolNodeRoot.GetEntityStartID();
            string enName = "entity" + id.ToString();

            CreateEntity(id, enName);

            PoolNodeRoot.AddEntityData(new ZEntityNode(id, enName), node);
        }
예제 #7
0
        /// <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);
        }
예제 #8
0
파일: ZEntityNode.cs 프로젝트: zzh-527/ZECS
        /// <summary>
        /// Finds the node.
        /// </summary>
        /// <returns>The node.</returns>
        /// <param name="id">Identifier.</param>
        public ZEntityNode FindNode(int id)
        {
            ZEntityNode node = Entities.Find((a) => a.ID == id);

            if (node == null)
            {
                foreach (var n in Entities)
                {
                    node = n.FindNode(id);
                    if (node != null)
                    {
                        break;
                    }
                }
            }
            return(node);
        }
예제 #9
0
파일: ZEntityNode.cs 프로젝트: zzh-527/ZECS
        /// <summary>
        /// Finds the node with parent.
        /// </summary>
        /// <returns>The node with parent.</returns>
        /// <param name="id">Identifier.</param>
        /// <param name="parent">Parent.</param>
        public ZEntityNode FindNodeWithParent(int id, out ZEntityNode parent)
        {
            parent = null;
            ZEntityNode node = Entities.Find((a) => a.ID == id);

            if (node == null)
            {
                foreach (var n in Entities)
                {
                    node = n.FindNodeWithParent(id, out parent);
                    if (node != null)
                    {
                        break;
                    }
                }
            }

            return(node);
        }
예제 #10
0
파일: ZEntityNode.cs 프로젝트: zzh-527/ZECS
        public ZEntityNode FindNodeWithParent(int ID, out ZEntityNode parent)
        {
            var node = subs.Find((a) => a.ID == ID);

            parent = null;

            if (node == null)
            {
                foreach (var n in subs)
                {
                    node = n.FindNodeWithParent(ID, out parent);
                    if (node != null)
                    {
                        break;
                    }
                }
            }
            else
            {
                parent = this;
            }

            return(node);
        }