示例#1
0
 public Behaviors MakeNewBehaviors(Window.UnitArrang arrang = null)
 {
     return(new Behaviors(xmlAI, gameObject, waitTime, updateAllTree, arrang));
 }
示例#2
0
        public Behaviors(TextAsset txt, GameObject obj, float waitTime, bool updateAllTree, Window.UnitArrang arrang = null)
        {
            if (txt == null || txt.text == null || txt.text.Length < 1)
            {
                Debug.LogWarningFormat("No xml tree [{0}]", obj.name);
                return;
            }

            XmlDocument xmlDoc = new XmlDocument();

            if (arrang != null)
            {
                string path = arrang.window.GetAssetTextPath(txt);
                using (TextReader tr = new StreamReader(path))
                {
                    xmlDoc.Load(tr);
                }
            }
            else
            {
                using (StringReader sr = new StringReader(txt.text))
                {
                    xmlDoc.Load(sr);
                }
            }

            XmlNodeList xmlNodes = xmlDoc.SelectNodes("root");
            BComponent  root     = null;

            components = FindComponents(obj);
            xmlAI      = txt;

            foreach (XmlNode xmlNode in xmlNodes)
            {
                root = BuildComponent(xmlNode, null, this);
            }

            this.root = root as RootSelector;
            if (this.root == null)
            {
                throw new NullReferenceException(string.Format("Behaviors: xml is invalid - has no root element [{0}]", txt.name));
            }
            this.root.updateAllTree = updateAllTree;

            this.waitTime = waitTime;
        }