public void CacheBehaviorTree(int bt_config_id, int cache_cnt)
        {
            bool is_new            = false;
            BehaviorTreeCache pool = GetPool(bt_config_id, out is_new);

            if (pool == null || pool.m_proto == null)
            {
                return;
            }
            if (is_new)
            {
                --cache_cnt;
            }
            else
            {
                if (cache_cnt + pool.m_cache.Count > MAX_CACHE_CNT)
                {
                    cache_cnt = MAX_CACHE_CNT - pool.m_cache.Count;
                }
            }
            for (int i = 0; i < cache_cnt; ++i)
            {
                BehaviorTree instance = pool.m_proto.CloneBehaviorTree();
                pool.m_cache.Add(instance);
            }
        }
        public void RecycleBehaviorTree(BehaviorTree instance)
        {
            if (instance == null)
            {
                return;
            }
            int  bt_config_id      = instance.ConfigID;
            bool is_new            = false;
            BehaviorTreeCache pool = GetPool(bt_config_id, out is_new);

            if (pool == null || pool.m_proto == null)
            {
                return;
            }
            instance.Reset();
            pool.m_cache.Add(instance);
        }
        BehaviorTreeCache GetPool(int bt_config_id, out bool is_new)
        {
            is_new = false;
            BehaviorTreeCache pool = null;

            if (!m_pools.TryGetValue(bt_config_id, out pool))
            {
                is_new = true;
                pool   = new BehaviorTreeCache();
                BehaviorTree instance = CreateBeahviorTreeFromConfig(bt_config_id);
                if (instance == null)
                {
                    LogWrapper.LogError("BehaviorTreeFactory, INVALID ID, ", bt_config_id);
                }
                else
                {
                    pool.m_proto = instance;
                    pool.m_cache.Add(instance);
                }
                m_pools[bt_config_id] = pool;
            }
            return(pool);
        }
        public BehaviorTree CreateBehaviorTree(int bt_config_id)
        {
            bool is_new            = false;
            BehaviorTreeCache pool = GetPool(bt_config_id, out is_new);

            if (pool == null || pool.m_proto == null)
            {
                return(null);
            }
            BehaviorTree instance    = null;
            int          cache_count = pool.m_cache.Count;

            if (cache_count > 0)
            {
                instance = pool.m_cache[cache_count - 1];
                pool.m_cache.RemoveAt(cache_count - 1);
            }
            else
            {
                instance = pool.m_proto.CloneBehaviorTree();
            }
            return(instance);
        }