/// <summary> /// Removes all children from this node. /// </summary> public virtual void RemoveChildren() { if (children.Count == 0) { return; } foreach (Node node in children) { node.Parent = null; node.SceneGraph = null; if (node is BranchNode) { foreach (Node child in ((BranchNode)node).Children) { PropagateSceneGraph(child); } } // at this time, still don't remove the node from children to guarantee thread-safe operation // will be actually removed right before processing the scene graph in Scene class NodeChangeInfo info = new NodeChangeInfo(); info.Node = node; info.Type = ChangeType.Remove; changeList.Add(info); } }
/// <summary> /// Adds a child to this node. /// </summary> /// <param name="node">The child node to be added</param> public virtual void AddChild(Node node) { if (node.Parent != null) { throw new GoblinException(node.Name + " already has a parent"); } if (children.Contains(node)) { throw new GoblinException("This child is already added to this node"); } if (node == this) { throw new GoblinException("You cannot add a node to itself"); } if (node.Parent == this) { throw new GoblinException(Name + " already has " + node.Name + " as child"); } CheckForLoops(node); if (scene != null && scene.IsStarted) { // at this time, still don't add the node to children to guarantee thread-safe operation // will be actually added during processing the scene graph in Scene class NodeChangeInfo info = new NodeChangeInfo(); info.Node = node; info.Type = ChangeType.Add; changeList.Add(info); } // if the scene hasn't started processing the tree yet, then it's safe to add now else { children.Add(node); } node.Parent = this; PropagateSceneGraph(node); }
/// <summary> /// Removes all children from this node. /// </summary> public virtual void RemoveChildren() { if (children.Count == 0) return; foreach (Node node in children) { node.Parent = null; node.SceneGraph = null; if(node is BranchNode) foreach (Node child in ((BranchNode)node).Children) PropagateSceneGraph(child); // at this time, still don't remove the node from children to guarantee thread-safe operation // will be actually removed right before processing the scene graph in Scene class NodeChangeInfo info = new NodeChangeInfo(); info.Node = node; info.Type = ChangeType.Remove; changeList.Add(info); } }
/// <summary> /// Adds a child to this node. /// </summary> /// <param name="node">The child node to be added</param> public virtual void AddChild(Node node) { if (node.Parent != null) throw new GoblinException(node.Name + " already has a parent"); if (children.Contains(node)) throw new GoblinException("This child is already added to this node"); if (node == this) throw new GoblinException("You cannot add a node to itself"); if (node.Parent == this) throw new GoblinException(Name + " already has " + node.Name + " as child"); CheckForLoops(node); if (scene != null && scene.IsStarted) { // at this time, still don't add the node to children to guarantee thread-safe operation // will be actually added during processing the scene graph in Scene class NodeChangeInfo info = new NodeChangeInfo(); info.Node = node; info.Type = ChangeType.Add; changeList.Add(info); } // if the scene hasn't started processing the tree yet, then it's safe to add now else children.Add(node); node.Parent = this; PropagateSceneGraph(node); }