示例#1
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="recycleTrs">回收节点</param>
 /// <param name="sceneTrs">场景默认节点</param>
 public void Init(Transform recycleTrs, Transform sceneTrs)
 {
     m_ResourceObjClassPool = GetOrCreatClassPool <ResouceObj>(1000);
     RecyclePoolTrs         = recycleTrs;
     SceneTrs = sceneTrs;
     RecyclePoolTrs.gameObject.SetActive(false);
     SceneTrs.gameObject.SetActive(false);
 }
示例#2
0
        /// <summary>
        /// 创建类对象池,创建完成以后外面可以保存ClassObjectPool<T>,然后调用Spawn和Recycle来创建和回收类对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="maxcount"></param>
        /// <returns></returns>
        public ClassObjectPool <T> GetOrCreatClassPool <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>);
        }