Ejemplo n.º 1
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="recycleTrs">回收节点</param>
        /// <param name="sceneTrs">场景默认节点</param>
        public void Init(Transform recycleTrs, Transform sceneTrs)
        {
            m_ResObjClassPool = ObjectManager.Instance.GetOrCreateClassPool <ResourceObj>(1000);

            RecyclePoolTrs = recycleTrs;

            SceneTrs = sceneTrs;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取或者创建类对象池,创建完成后,外面可以保存ClassObjectPool<T>
        /// 然后调用Spawn和Recycle来创建和回收类对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="maxcount"></param>
        /// <returns></returns>
        public ClassObjectPool <T> GetOrCreateClassPool <T>(int maxcount) where T : class, new()
        {
            Type type = typeof(T);

            object outObj = null;

            if (!m_ClassPoolDic.TryGetValue(type, out outObj) || outObj == null)
            {
                ClassObjectPool <T> newPool = new ClassObjectPool <T>(maxcount);
                m_ClassPoolDic.Add(type, newPool);
                return(newPool);
            }

            return(outObj as ClassObjectPool <T>);
        }