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; } }
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>(); }
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."); } }
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."); } }
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; } }
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; } }
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."); } }