Пример #1
0
        public static T RetrieveObject <T>(T obj) where T : Object
        {
            PoolObjectQueue poq      = m_objectQueues[obj];
            Queue <Object>  objQueue = poq.queue;

            if (!poq.isCircularPool && objQueue.Count == 0)
            {
                AddNewObject(obj, objQueue, poq.enabledAsDefault);
            }

            Object newObj = objQueue.Dequeue();

            if (poq.isCircularPool)
            {
                objQueue.Enqueue(newObj);
            }

            return((T)newObj);
        }
Пример #2
0
        public static void RegisterObject(Object obj, bool isCircular, int quantity, bool enabledAsDefault = false)
        {
            if (m_objectQueues.ContainsKey(obj))
            {
                return;
            }

            Queue <Object>  objQueue = new Queue <Object>(quantity);
            PoolObjectQueue poq      = new PoolObjectQueue
            {
                isCircularPool   = isCircular,
                enabledAsDefault = enabledAsDefault,
                queue            = objQueue
            };

            for (int i = 0; i < quantity; i++)
            {
                AddNewObject(obj, objQueue, enabledAsDefault);
            }

            m_objectQueues.Add(obj, poq);
        }