From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/XMainClient/AI/AIRunTimeTreeMgr.cs | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/AI/AIRunTimeTreeMgr.cs (limited to 'Client/Assets/Scripts/XMainClient/AI/AIRunTimeTreeMgr.cs') diff --git a/Client/Assets/Scripts/XMainClient/AI/AIRunTimeTreeMgr.cs b/Client/Assets/Scripts/XMainClient/AI/AIRunTimeTreeMgr.cs new file mode 100644 index 00000000..d93b0db6 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/AI/AIRunTimeTreeMgr.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Xml; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class AIRunTimeTreeMgr : XSingleton + { + private Dictionary _behavior_tree = new Dictionary(); + + private AIRunTimeRootNode LoadAITree(Stream content, string key) + { + XmlDocument xmlDocument = new XmlDocument(); + xmlDocument.Load(content); + XSingleton.singleton.ClearStream(content); + XmlElement documentElement = xmlDocument.DocumentElement; + AIRunTimeRootNode airunTimeRootNode = this.LoadOneNode(documentElement.FirstChild as XmlElement) as AIRunTimeRootNode; + this._behavior_tree[key] = airunTimeRootNode; + return airunTimeRootNode; + } + + public AIRunTimeRootNode GetBehavior(string name) + { + AIRunTimeRootNode result = null; + bool flag = !this._behavior_tree.TryGetValue(name, out result); + if (flag) + { + result = this.LoadAITree(XSingleton.singleton.ReadText("Table/AITree/" + name, ".xml", true), name); + } + return result; + } + + private AIRunTimeNodeBase LoadOneNode(XmlElement element) + { + bool flag = element == null; + AIRunTimeNodeBase result; + if (flag) + { + result = null; + } + else + { + AIRunTimeNodeBase airunTimeNodeBase = AINodeFactory.CreateAINodeByName(element.Name, element); + bool flag2 = element.Name == "ConditionalEvaluator"; + if (flag2) + { + AIRunTimeNodeBase airunTimeNodeBase2 = AINodeFactory.CreateAINodeByName((airunTimeNodeBase as AIRunTimeConditionalEvaluator).ConditionNodeName, element); + bool flag3 = airunTimeNodeBase2 != null; + if (flag3) + { + (airunTimeNodeBase as AIRunTimeConditionalEvaluator).AddConditionNode(airunTimeNodeBase2); + } + } + for (int i = 0; i < element.ChildNodes.Count; i++) + { + AIRunTimeNodeBase airunTimeNodeBase3 = this.LoadOneNode(element.ChildNodes[i] as XmlElement); + bool flag4 = airunTimeNodeBase3 != null; + if (flag4) + { + airunTimeNodeBase.AddChild(airunTimeNodeBase3); + } + } + result = airunTimeNodeBase; + } + return result; + } + } +} -- cgit v1.1-26-g67d0