Пример #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
        /// <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
 /// <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
        /// <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
        /// <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
        /// <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
        /// <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
        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);
        }