예제 #1
0
        /// <summary>
        /// 在对象池中取对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="maxcount"></param>
        /// <returns></returns>
        public T NewClassObjectFromPool <T>(int maxcount) where T : class, new()
        {
            ClassObjectPool <T> pool = GetOrCreateClassPool <T>(maxcount);

            if (pool == null)
            {
                return(null);
            }

            return(pool.Spawn(true));
        }
예제 #2
0
        /// <summary>
        /// 创建类对象池,创建完成后可外部保存ClassPool,再调用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>);
        }
예제 #3
0
 /// <summary>
 /// 初始化调用
 /// </summary>
 /// <param name="recycleTrs"></param>
 /// <param name="sceneTrs"></param>
 public void Init(Transform recycleTrs, Transform sceneTrs)
 {
     m_ResourceObjClassPool = GetOrCreateClassPool <ResourceObj>(1000);
     this.ResyclePoolTrs    = recycleTrs;
     this.SceneTrs          = sceneTrs;
 }
예제 #4
0
        protected ClassObjectPool <AssetBundleItem> m_AssetBundleItemPool; //Fix:=ObjectManager.Instance.GetOrCreateClassPool<AssetBundleItem>(500);不能在这里调用单例,单例中用了unity下的FindObjectByType

        void Awake()
        {
            m_AssetBundleItemPool = ObjectManager.Instance.GetOrCreateClassPool <AssetBundleItem>(500);
        }