Exemple #1
0
        public BTAgent Clone()
        {
            BTAgent agent = new BTAgent(m_BtPath, m_LibraryName, m_TreeName);

            for (int i = 0; i < m_Actions.Count; i++)
            {
                agent.RegisterAction(m_Actions[i].Clone());
            }

            return(agent);
        }
        static BTAgent Resolver(string btPath)
        {
            BTAgent agent = null;

            TextAsset asset = UnityEngine.Resources.Load(btPath) as TextAsset;

            if (asset != null && !string.IsNullOrEmpty(asset.text))
            {
                try
                {
                    XmlDocument       xmlDoc   = new XmlDocument();
                    XmlReaderSettings settings = new XmlReaderSettings();
                    settings.IgnoreComments = true;
                    XmlReader reader = XmlReader.Create(new StringReader(asset.text), settings);
                    xmlDoc.Load(reader);

                    XmlElement root    = xmlDoc.SelectSingleNode("Tree") as XmlElement;
                    string     library = XmlUtil.GetAttributeString(root, "Library");
                    string     tree    = XmlUtil.GetAttributeString(root, "Tree");

                    agent = new BTAgent(btPath, library, tree);
                    agent.Tick();

                    //Profiler.BeginSample("XmlNode");
                    XmlNodeList xmlNodeList = root.GetElementsByTagName("Action");
                    foreach (XmlNode node in xmlNodeList)
                    {
                        XmlElement e        = node as XmlElement;
                        string     typeName = XmlUtil.GetAttributeString(e, "Type");

                        BTAction action = agent.GetAction(typeName);

                        if (action == null)
                        {
                            action = Reflecter.Instance.CreateAction(typeName);
                            agent.RegisterAction(action);
                        }

                        if (action != null)
                        {
                            InitData(btPath, action, e);
                        }
                    }
                }
                catch (System.Exception e)
                {
                    Debug.LogError("[" + btPath + "]" + "<" + e + ">");
                }
            }

            return(agent);
        }