public static BehaviourTreeNode ParseNode(XmlNode parentXMLNode, object o = null) { BehaviourTreeNode parent = null; if (parentXMLNode.Name == "RefNode") { parent = GetRefNode(XMLUtil.GetNodeAttrValue(parentXMLNode, "ref", ""), o); } if (parentXMLNode.Name == "SelectorNode") { parent = new SelectorNode(); } if (parentXMLNode.Name == "ConditionNode") { parent = new ConditionActionNode(XMLUtil.GetNodeAttrValue(parentXMLNode, "condition", "")); } if (parentXMLNode.Name == "DecortorNode") { var untilStatusString = XMLUtil.GetNodeAttrValue(parentXMLNode, "untilStatus", "").ToLower(); var untilStatus = untilStatusString == "success" ? BehaviourTreeNodeStatus.Success : BehaviourTreeNodeStatus.Fail; parent = new DecortorNode(untilStatus); } if (parentXMLNode.Name == "ParallelNode") { parent = new ParallelNode(); } if (parentXMLNode.Name == "ParallelNode2") { parent = new ParallelNode2(); } if (parentXMLNode.Name == "RandomSelectorNode") { parent = new RandomSelectorNode(); } if (parentXMLNode.Name == "SequenceNode") { parent = new SequenceNode(); } for (var i = 0; i < parentXMLNode.ChildNodes.Count; i++) { XmlNode childXMLNode = parentXMLNode.ChildNodes[i]; var child = ParseNode(childXMLNode, o); ((BehaviourTreeCompositeNode)parent).AddChild(child); } return(parent); }
public override T GetChild <T>(bool loop = false) { for (var i = 0; i < childList.Count; i++) { var child = childList[i]; if (!loop) { if (child is T node) { return(node); } } else { BehaviourTreeNode grandchild = child.GetChild <T>(loop); if (grandchild is T) { return((T)grandchild); } } } return(null); }
public void AddChild(BehaviourTreeNode child) { childList.Add(child); child.parent = this; }