示例#1
0
        /// <summary>
        /// Add a child
        /// </summary>
        /// <param name="child">Node to add as a child</param>
        public void AddChild(Node child)
        {
            if (child == null) throw new ArgumentNullException("child");
            if (child._parentNode != null)
            {
                if (child._parentNode != this) throw new ArgumentException("", "child");

                return;
            }

            Childrens.Add(child);
            child.SetParent(this);
        }
示例#2
0
        /// <summary>
        /// Sets the parent of this node
        /// </summary>
        /// <param name="parent">Parent node</param>
        private void SetParent(Node parent)
        {
            bool changed = (parent != _parentNode);
            _parentNode = parent;
            ParentTransform = parent;
            if (!changed) return;

            if (_parentNode != null) _depth = _parentNode._depth + 1;
            else _depth = 0;

            for(int i = 0; i < Childrens.Count; i++) Childrens[i].UpdateDepthLevel();
        }
示例#3
0
        /// <summary>
        /// Receives a request for updating a specific child
        /// </summary>
        /// <param name="child">Child node to update</param>
        protected virtual void RequestUpdate(Node child)
        {
            ChildldrensToUpdate.Add(child);

            if ((ParentTransform == null) || _parentAskedForUpdate) return;

            _parentNode.RequestUpdate(this);
            _parentAskedForUpdate = true;
        }
示例#4
0
 /// <summary>
 /// Performs internal operation when a child node is about to be destroyed.
 /// Used when this class is inherited
 /// </summary>
 /// <param name="child">Child to destroy</param>
 protected abstract void DestroyChildIntern(Node child);
示例#5
0
        /// <summary>
        /// Remove a child
        /// </summary>
        /// <param name="child">Child to remove</param>
        /// <returns></returns>
        public bool RemoveChild(Node child)
        {
            if(child._parentNode != this) throw new ArgumentException("", "child");

            Childrens.Remove(child);
            child.SetParent(null);

            return true;
        }
示例#6
0
        /// <summary>
        /// Destroys a child node
        /// </summary>
        /// <param name="child">Child to destroy</param>
        public void DestroyChild(Node child)
        {
            if (child._parentNode != this) throw new ArgumentException("", "child");

            child.DestroyAllChild();
            RemoveChild(child);
            DestroyChildIntern(child);
        }
示例#7
0
        /// <summary>
        /// Destroys a child node
        /// </summary>
        /// <param name="child">Child to destroy</param>
        protected override void DestroyChildIntern(Node child)
        {
            SceneNode node = child as SceneNode;
            if(node == null)
                throw new InvalidCastException("Must be a SceneNode instance");

            node.Owner.DestroyNode(node);
        }