Exemple #1
0
        public T Spawn()
        {
            T tmpPoolObj;

            if (mQueue.Count > 0)
            {
                tmpPoolObj = mQueue.Dequeue();
            }
            else
            {
                tmpPoolObj = Activator.CreateInstance <T>();
                tmpPoolObj.OnInit();
            }

            tmpPoolObj.OnSpawn();

            return(tmpPoolObj);
        }
Exemple #2
0
        public T Spawn()
        {
            T tmpPoolObj;

            if (mQueue.Count > 0)
            {
                tmpPoolObj = mQueue.Dequeue();
            }
            else
            {
                tmpPoolObj = Activator.CreateInstance <T>();
                tmpPoolObj.OnInit();
            }

            tmpPoolObj.IsFromPool = true;
            tmpPoolObj.Id         = IdGenerater.GenerateId();
            tmpPoolObj.OnSpawn();

            return(tmpPoolObj);
        }
Exemple #3
0
        /// <summary>
        /// 从引用池获取引用。
        /// </summary>
        /// <typeparam name="T">引用类型。</typeparam>
        public static T Fetch <T>() where T : class, IReference
        {
            T tmpInstance = default(T);

            lock (s_ReferencePool)
            {
                EQueue <IReference> referencePool = GetReferencePool(typeof(T));
                if (referencePool.Count > 0)
                {
                    tmpInstance = (T)referencePool.Dequeue();
                }
            }

            if (null == tmpInstance)
            {
                tmpInstance = Activator.CreateInstance <T>();
            }

            tmpInstance.OnInit();
            return(tmpInstance);
        }
Exemple #4
0
        /// <summary>
        /// 从引用池获取引用。
        /// </summary>
        /// <typeparam name="T">引用类型。</typeparam>
        public static T Fetch <T>() where T : class, IReference, new()
        {
            T tmpInstance = default(T);

            lock (s_ReferencePool)
            {
                EQueue <IReference> referencePool = GetReferencePool(typeof(T).FullName);
                if (referencePool.Count > 0)
                {
                    tmpInstance = (T)referencePool.Dequeue();
                }
            }

            if (null == tmpInstance)
            {
                tmpInstance = new T();
            }

            tmpInstance.IsFromPool = true;

            return(tmpInstance);
        }