/// <summary> /// Tries to remove the specified component from the current node. /// </summary> /// <param name="transform">The transformation component to remove.</param> /// <returns>True if the component was removed successfully.</returns> public bool RemoveChild(TransformComponent transform) { if (_children.Remove(transform)) { // Remove the reference to the current node transform._parent = null; // Notify the caller that the component has been removed return true; } // Component could not be found return false; }
/// <summary> /// Checks whether the current transformation component is a child of /// the specified component. /// </summary> /// <param name="transform">The transformation component that might be the parent.</param> /// <returns>True if the current component is a child of the specified one.</returns> public bool IsChildOf(TransformComponent transform) { return _parent == transform; }
/// <summary> /// Checks whether the current transformation component is the parent /// of the specified component. /// </summary> /// <param name="transform">The transformation component that might be the child node.</param> /// <returns>True if the current component is the parent of the specified one.</returns> public bool IsParentOf(TransformComponent transform) { return _children.Contains(transform); }
/// <summary> /// Adds a transformation component to the current node to allow /// hierarchical transformation. /// </summary> /// <param name="transform">The transformation component to attach.</param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="transform"/> component is null. /// </exception> public void AddChild(TransformComponent transform) { if (transform == null) throw new ArgumentNullException("The specified transformation component is null."); // Detach from the old parent if (transform._parent != null && transform._parent != this) transform._parent.RemoveChild(transform); // Attach the component to the current node, if not already done. if (transform._parent == null) { // Assign the parent reference transform._parent = this; // Add the component to the current collection _children.Add(transform); } }