public void AddChild(BehaviourNode child) { switch (Type) { case NodeType.TASK: throw new System.Exception($"Failed to add {child.Name}. Tasks don`t have children"); case NodeType.DECORATOR: if (Children.Count > 1) { throw new System.Exception($"Failed to add {child.Name} to {Name}. Too many children"); } break; } if (!_children.Contains(child)) { if (child.Parent != null) { throw new System.Exception($"Adding child to {Name} failed. {child.Name} already has parent {child.Parent.Name}"); } _children.Add(child); child.SetParent(this); OnChildNodeAdded.Invoke(this, child); } }
public void RemoveChild(BehaviourNode child) { child.SetParent(null); _children.Remove(child); OnChildNodeRemoved.Invoke(this, child); }