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

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

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

            return(null);
        }
コード例 #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);
        }
コード例 #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);
            }
        }
コード例 #5
0
        private ObjectPoolBase InternalCreateObjectPool(Type objectType, string name, bool allowMultiSpawn, float autoReleaseInterval, int capacity, float expireTime, int priority)
        {
            if (objectType == null)
            {
                throw new GameFrameworkException("Object type is invalid.");
            }

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

            if (HasObjectPool(objectType, name))
            {
                throw new GameFrameworkException(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, autoReleaseInterval, capacity, expireTime, priority);

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