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); }
protected void LoadProperty(XmlNode node) { string key = XMLUtil.GetNodeAttrValue(node, Name_Key, "").Trim(); if (key.Length > 0) { if (!this.propDict.ContainsKey(key)) { string value = XMLUtil.GetNodeAttrValue(node, Value_Key, ""); if (value.Length == 0) { value = XMLUtil.GetNodeValue(node, "").Trim(); } this.propDict[key] = value; } } }
public static BehaviourTreeNode GetRefNode(string value, object o = null) { var xml = new XmlDocument(); xml.Load("Assets/cscat/dataStruct/behaviourTree/config/base.xml"); XmlNode xmlNode = null; foreach (XmlNode child in xml.FirstChild.ChildNodes) { var childValue = XMLUtil.GetNodeAttrValue(child, "name", ""); if (childValue == value) { xmlNode = child; } } if (xmlNode != null) { return(ParseNode(xmlNode, o)); } return(null); }
public void LoadFrom(XmlNode node) { if (this.name == null) { string name = node.Name; if (name != null) { this.name = name.Trim(); } } Dictionary <string, string> nodeAttrDict = XMLUtil.GetNodeAttrs(node); foreach (string key in nodeAttrDict.Keys) { if (this.attrDict.ContainsKey(key)) { continue; } string value = nodeAttrDict.GetOrAddDefault(key, () => ""); this.attrDict[key] = value; } XmlNode child = node.FirstChild; XMLConfig subConfig = null; while (child != null) { if (child.NodeType == XmlNodeType.Element) { if (IsPropertyNode(child)) { LoadProperty(child); } else { string childNodeName = child.Name; if (childNodeName == null) { continue; } childNodeName = childNodeName.Trim(); string parseClassString = XMLUtil.GetNodeAttrValue(child, "parseClass", ""); if (parseClassString.Length > 0) { subConfig = (XMLConfig)Activator.CreateInstance(Type.GetType(parseClassString)); } else { subConfig = new XMLConfig(); } subConfig.parentConfig = this; subConfig.name = childNodeName; subConfig.LoadFrom(child); // 不断循环下一层 this.configList.Add(subConfig); } } child = child.NextSibling; } string configPath = nodeAttrDict.GetOrAddDefault(Config_Path_Key, () => ""); if (configPath.Length > 0) { LoadFrom(configPath); } }