Example #1
0
        /// <summary>
        /// 获取对象池。
        /// </summary>
        /// <typeparam name="T">对象类型。</typeparam>
        /// <param name="name">对象池名称。</param>
        /// <returns>要获取的对象池。</returns>
        public IObjectPool <T> GetObjectPool <T>(string name) where T : BaseObject
        {
            BaseObjectPool objectPool = null;

            if (m_ObjectPools.TryGetValue(TextHelper.GetFullName <T>(name), out objectPool))
            {
                return((IObjectPool <T>)objectPool);
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// 销毁对象池。
        /// </summary>
        /// <typeparam name="T">对象类型。</typeparam>
        /// <param name="name">要销毁的对象池名称。</param>
        /// <returns>是否销毁对象池成功。</returns>
        public bool DestroyObjectPool <T>(string name) where T : BaseObject
        {
            string         fullName   = TextHelper.GetFullName <T>(name);
            BaseObjectPool objectPool = null;

            if (m_ObjectPools.TryGetValue(fullName, out objectPool))
            {
                objectPool.Shutdown();
                return(m_ObjectPools.Remove(fullName));
            }

            return(false);
        }
Example #3
0
        /// <summary>
        /// 获取所有对象池。
        /// </summary>
        /// <param name="sort">是否根据对象池的优先级排序。</param>
        /// <returns>所有对象池。</returns>
        public BaseObjectPool[] GetAllObjectPools(bool sort)
        {
            if (sort)
            {
                List <BaseObjectPool> objectPools = new List <BaseObjectPool>(m_ObjectPools.Values);
                objectPools.Sort(ObjectPoolComparer);
                return(objectPools.ToArray());
            }
            else
            {
                int index = 0;
                BaseObjectPool[] objectPools = new BaseObjectPool[m_ObjectPools.Count];
                foreach (KeyValuePair <string, BaseObjectPool> objectPool in m_ObjectPools)
                {
                    objectPools[index++] = objectPool.Value;
                }

                return(objectPools);
            }
        }
Example #4
0
 private int ObjectPoolComparer(BaseObjectPool a, BaseObjectPool b)
 {
     return(a.Priority.CompareTo(b.Priority));
 }