Beispiel #1
0
 public void RemoveChild(KC_TreeNode child)
 {
     if (Children.Remove(child))
     {
         // Child removed - set the parent link of child to null
         Debug.Assert(child.Parent == this);
         child.Parent = null;
     }
 }
Beispiel #2
0
        public KC_TreeNode(KC_TreeNode parent)
        {
            //  Set the parent and add this node to the children of the parent.
            // fixme: remove
            // Parent = parent;
            parent?.AddChild(this);

            Children = new List <KC_TreeNode>();
        }
Beispiel #3
0
 public static void RemoveTreeChild(this Unit unit, KC_TreeNode child)
 {
     if (unit.HasComponent <KC_TreeNode>())
     {
         unit.GetComponent <KC_TreeNode>().RemoveChild(child);
     }
     else
     {
         throw new InvalidOperationException("RemoveTreeChild() called on Unit without a KC_TreeNode componenent.");
     }
 }
Beispiel #4
0
 public static void SetTreeParent(this Unit unit, KC_TreeNode parent)
 {
     if (unit.HasComponent <KC_TreeNode>())
     {
         parent.AddChild(unit.GetComponent <KC_TreeNode>());
     }
     else
     {
         throw new InvalidOperationException("SetTreeParent() called on Unit without a KC_TreeNode componenent.");
     }
 }
Beispiel #5
0
        public KC_TreeNode(KC_TreeNode parent, IList <KC_TreeNode> children)
        {
            // Set the Parent and add this node to the children of the parent
            // fixme: remove
            // Parent = parent;
            parent?.AddChild(this);

            // Set the Children and set the parent of each of the children to this node
            Children = children;
            foreach (KC_TreeNode child in children)
            {
                child.Parent = this;
            }
        }
Beispiel #6
0
 public void AddChild(KC_TreeNode child)
 {
     Children.Add(child);
     if (child.Parent == null)
     {
         // Child didn't have a previous parent - set the parent's child
         child.Parent = this;
     }
     else
     {
         // Child had previous parent - remove the child from the Children of previous parent and set new parent
         bool removed = child.Parent.Children.Remove(child);
         Debug.Assert(removed);
         child.Parent = this;
     }
 }
Beispiel #7
0
        public static void SetTreeChildren(this Unit unit, IList <KC_TreeNode> children)
        {
            if (unit.HasComponent <KC_TreeNode>())
            {
                KC_TreeNode thisNode = unit.GetComponent <KC_TreeNode>();

                // First remove any existing children.
                thisNode.RemoveChildren();

                // Now add each new child to the node
                foreach (KC_TreeNode child in children)
                {
                    thisNode.AddChild(child);
                }
            }
            else
            {
                throw new InvalidOperationException("SetTreeChildren() called on Unit without a KC_TreeNode componenent.");
            }
        }