示例#1
0
 /// <summary>
 /// 将指定的对象回收到对象池。
 /// </summary>
 /// <param name="obj">对象</param>
 public void Put(T obj)
 {
     if (AvailiableObjects.Contains(obj))
     {
         return;
     }
     OnPut(obj);
     AvailiableObjects.Enqueue(obj);
 }
示例#2
0
        /// <summary>
        /// 将指定的对象回收到对象池。
        /// </summary>
        /// <param name="obj">对象</param>
        public void Put(object obj)
        {
            var put = (T)obj;

            if (AvailiableObjects.Contains(put))
            {
                return;
            }
            OnPut(put);
            AvailiableObjects.Enqueue(put);
        }
示例#3
0
 /// <summary>
 /// 清理所有缓存的对象。
 /// </summary>
 public void Clear()
 {
     while (AvailiableObjects.Count > 0)
     {
         UnityEngine.Object.Destroy(AvailiableObjects.Dequeue());
     }
     while (InUseObjects.Count > 0)
     {
         UnityEngine.Object.Destroy(InUseObjects.Dequeue());
     }
 }
示例#4
0
        /// <summary>
        /// 从对象池中获取一个对象。
        /// </summary>
        /// <returns>可用的对象</returns>
        public T Get()
        {
            T ret;

            if (AvailiableObjects.Count != 0)
            {
                ret = AvailiableObjects.Dequeue();
            }
            else if (InUseObjects.Count == Capacity)
            {
                ret = InUseObjects.Dequeue();
                OnPut(ret);
            }
            else
            {
                ret = Create();
            }
            OnGet(ret);
            InUseObjects.Enqueue(ret);
            return(ret);
        }