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); }
public static BTAgent Instantiate(string btPath, IAgent agent) { BTAgent newAgent = Pop(btPath); if (newAgent != null) { newAgent.SetAgent(agent); } return(newAgent); }
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); }
public static BTAgent Pop(string btPath) { BTAgent agent = null; BTAgent agentCopy; if (s_btAgents.TryGetValue(btPath, out agentCopy) && agentCopy != null) { agent = agentCopy.Clone(); } else { Debug.Log("Can't find behave tree : " + btPath); } return(agent); }
public static void RegisterToCache(string btPath) { if (!string.IsNullOrEmpty(btPath) && !s_btAgents.ContainsKey(btPath)) { if (_btCached) { BTAgent agent = Resolver(btPath); if (agent != null) { s_btAgents.Add(btPath, agent); } } else { s_btAgents.Add(btPath, null); // Placeholder } } }
public int Instantiate(string btPath, IAgent agent, bool isLaunch = true) { if (!string.IsNullOrEmpty(btPath)) { BTAgent btAgent = BTResolver.Instantiate(btPath, agent); if (btAgent != null) { if (isLaunch) { btAgent.Start(); } int id = ++m_Count; m_Agents.Add(id, btAgent); return(id); } } return(-1); }