Axiom.Core.Node.AddChild C# (CSharp) Method

AddChild() public method

Adds a node to the list of children of this node.
public AddChild ( Node child ) : void
child Node
return void
		public void AddChild( Node child )
		{
			string childName = child.Name;
			if ( child == this )
				throw new ArgumentException( string.Format( "Node '{0}' cannot be added as a child of itself.", childName ) );
			if ( childNodes.ContainsKey( childName ) )
				throw new ArgumentException( string.Format( "Node '{0}' already has a child node with the name '{1}'.", this.name, childName ) );

			child.RemoveFromParent();
			childNodes.Add( childName, child );

			child.NotifyOfNewParent( this );
		}

Usage Example

Example #1
0
 protected virtual void ParentChanged(Node oldParent, Node newParent)
 {
     if(oldParent != null) {
         oldParent.RemoveChild(this);
         if (NodeDetachedEvent != null)
             NodeDetachedEvent(this);
     }
     if (newParent != null) {
         newParent.AddChild(this);
         if (NodeAttachedEvent != null)
             NodeAttachedEvent(this);
     }
 }