/// <summary> /// Add a child node /// </summary> public void AddChild(NodeBase node) { if(childList == null) childList = new Collection<NodeBase>(); node.Parent = this; childList.Add(node); }
/// <summary> /// it checks whether the node is a child node /// </summary> public bool IsChild(NodeBase node) { return childList.Contains(node); }
/// <summary> /// Copy all child nodes to array. /// </summary> public void GetChildArray(NodeBase[] array) { childList.CopyTo(array, 0); }
/// <summary> /// Insert a child node /// </summary> public void InsertChild(int index, NodeBase node) { node.Parent = this; childList.Insert(index, node); }
/// <summary> /// Remove a child node /// </summary> /// <param name="node">target node</param> /// <param name="isRecursive"> /// whether to remove the child node which has been included in the target node /// </param> public void RemoveChild(NodeBase node, bool isRecursive) { if (childList != null) { if (isRecursive ) { node.RemoveAllChild(isRecursive); } childList.Remove(node); node.Parent = null; } }
/// <summary> /// Remove this node from parent /// </summary> public void RemoveFromParent() { if (parent != null) { parent.RemoveChild(this, false); parent = null; } }
/// <summary> /// it checks whether the node is a child node /// </summary> public bool IsChild(NodeBase node) { return(childList.Contains(node)); }
/// <summary> /// drops weapon at specified position. /// </summary> /// <param name="position">new drop position</param> /// <param name="parent">new scene node</param> /// <param name="layer">new collision layer</param> public void Drop(Vector3 position, NodeBase parent, CollisionLayer layer) { // Detached scene node from owner AttachOwner(parent); // Add a collision if( layer != null) layer.AddCollide(this.Collide); DroppedModel.SetRootAxis( Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f))); this.Position = position; this.isDropped = true; this.Enabled = true; this.Visible = true; }
/// <summary> /// owner acquires weapon. /// </summary> /// <param name="owner"></param> public void Pickup(NodeBase owner) { // Attach node to new owner AttachOwner(owner); // All weapon model is active for (int i = 0; i < modelWeapon.Length; i++) { this.modelWeapon[i].Enabled = true; this.modelWeapon[i].Visible = true; this.modelWeapon[i].WorldTransform = Matrix.Identity; } // Collision is off this.Collide.RemoveInLayer(); DroppedModel.SetRootAxis(Matrix.Identity); this.WorldTransform = Matrix.Identity; this.isDropped = false; this.Enabled = false; this.Visible = false; }
/// <summary> /// sticks to the owner as a child. /// Will depend on owner as a child. /// </summary> /// <param name="owner"></param> public void AttachOwner(NodeBase owner) { DetachOwner(); if (specData.ModelAlone ) { for (int i = 0; i < specData.ModelCount; i++) { // New parent is owner now this.AddChild(modelWeapon[i]); modelWeapon[i].SetRootAxis(Matrix.Identity); } } owner.AddChild(this); }