Exemple #1
0
        /// <summary>
        /// 销毁对象池。
        /// </summary>
        /// <param name="objectPool">要销毁的对象池。</param>
        /// <returns>是否销毁对象池成功。</returns>
        public bool DestroyObjectPool(ObjectPoolBase objectPool)
        {
            if (objectPool == null)
            {
                throw new AshException("Object pool is invalid.");
            }

            return(InternalDestroyObjectPool(Utility.Text.GetFullName(objectPool.ObjectType, objectPool.Name)));
        }
Exemple #2
0
        private ObjectPoolBase InternelGetObjectPool(string fullName)
        {
            ObjectPoolBase objectPool = null;

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

            return(null);
        }
Exemple #3
0
        private bool InternalDestroyObjectPool(string fullName)
        {
            ObjectPoolBase objectPool = null;

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

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

                return(objectPools);
            }
        }
Exemple #5
0
        private ObjectPoolBase InternalCreateObjectPool(Type objectType, string name, bool allowMultiSpawn, int capacity, float expireTime, int priority)
        {
            if (objectType == null)
            {
                throw new AshException("Object type is invalid.");
            }

            if (!typeof(ObjectBase).IsAssignableFrom(objectType))
            {
                throw new AshException(string.Format("Object type '{0}' is invalid.", objectType.FullName));
            }

            if (HasObjectPool(objectType, name))
            {
                throw new AshException(string.Format("Already exist object pool '{0}'.", Utility.Text.GetFullName(objectType, name)));
            }

            Type           objectPoolType = typeof(ObjectPool <>).MakeGenericType(objectType);
            ObjectPoolBase objectPool     = (ObjectPoolBase)Activator.CreateInstance(objectPoolType, name, allowMultiSpawn, capacity, expireTime, priority);

            m_ObjectPools.Add(Utility.Text.GetFullName(objectType, name), objectPool);
            return(objectPool);
        }
Exemple #6
0
 private int ObjectPoolComparer(ObjectPoolBase a, ObjectPoolBase b)
 {
     return(a.Priority.CompareTo(b.Priority));
 }