Example #1
0
        public void UpdateBTTree(int _timeLastFrameInMS)
        {
            BTTree btTree = BTTree;

            if (btTree == null || btTree.Root == null)
            {
                return;
            }

            if (Mgr <GameEngine> .Singleton._gameEngineMode == GameEngine.GameEngineMode.MapEditor)
            {
                InitDebugTrail();
            }
            btTree.Root.DoExecute(this);
            // on exit
            foreach (BTActionNode actionNode in m_runningAction)
            {
                if (!m_nextRunningAction.Contains(actionNode))
                {
                    actionNode.OnExit(this);
                }
            }

            // swap
            HashSet <BTActionNode> tmp = m_nextRunningAction;

            m_nextRunningAction = m_runningAction;
            m_runningAction     = tmp;
            m_nextRunningAction.Clear();
        }
Example #2
0
        /**
         * @brief load and update bttree. (if exist, it update the existing tree)
         **/
        public BTTree LoadBTTree(string _name, bool _forceLoad = false)
        {
            if (!_forceLoad && m_btTrees.ContainsKey(_name))
            {
                return(m_btTrees[_name]);
            }
            if (!m_btTreeReadDirectoryRoot.EndsWith("/") && !m_btTreeReadDirectoryRoot.EndsWith("\\"))
            {
                m_btTreeReadDirectoryRoot += '/';
            }
            string filepath = m_btTreeReadDirectoryRoot + _name + ".btt";

            if (File.Exists(filepath))
            {
                BTTree btTree = BTTree.Load(filepath);
                if (m_btTrees.ContainsKey(_name))
                {
                    // Update tree
                    m_btTrees[_name] = btTree;
                }
                m_btTrees.Add(_name, btTree);
                return(btTree);
            }
            else
            {
                Debug.Assert(false, "Cannot find BTTree: " + filepath);
                return(null);
            }
        }
Example #3
0
        public BTTree CreateAndSaveEmptyBTTree(string _name = "UntitleBTTree")
        {
            BTTree newTree = BTTree.CreateEmptyBTTree();
            // find a name
            string baseName = _name;
            string surfix   = ".btt";
            int    index    = 0;
            string name     = baseName;
            string fullname = name + surfix;
            string path     = CatProject.GetStandardPath(m_btTreeReadDirectoryRoot);

            while (File.Exists(path + fullname))
            {
                ++index;
                name     = baseName + index;
                fullname = name + surfix;
            }
            m_btTrees.Add(name, newTree);
            newTree.Save(CatProject.GetStandardPath(m_btTreeWriteDirectory) + fullname);
            if (Mgr <CatProject> .Singleton != null)
            {
                Mgr <CatProject> .Singleton.SynchronizeBTTrees();
            }
            return(newTree);
        }
Example #4
0
        public static BTTree CreateEmptyBTTree()
        {
            BTTree newBTTree = new BTTree();

            newBTTree.m_root = new BTRootNode();
            return(newBTTree);
        }
Example #5
0
        /**
         * @brief load bttree from file
         **/
        public static BTTree Load(string _filepath)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(_filepath);

            BTTree newBTTree = new BTTree();

            XmlNode nodeBTTree   = doc.SelectSingleNode("BTTree");
            XmlNode nodeRoot     = nodeBTTree.SelectSingleNode("Root");
            XmlNode nodeRealRoot = nodeRoot.FirstChild;

            Serialable.BeginSupportingDelayBinding();
            newBTTree.m_root = Serialable.DoUnserial(nodeRealRoot) as BTNode;
            Serialable.EndSupportingDelayBinding(true);
            return(newBTTree);
        }
Example #6
0
 public void AddBTTree(string _name, BTTree _btTree)
 {
     m_btTrees.Add(_name, _btTree);
 }