Пример #1
0
        public new T Pop()
        {
            var item = base.Pop();

            OnPop?.Invoke(item);
            return(item);
        }
Пример #2
0
    public virtual T Pop()
    {
        T item = stack.Pop();

        OnPop?.Invoke(item);
        return(item);
    }
Пример #3
0
 void PushCommand(Command i)
 {
     Commands.Enqueue(i);
     CommandObjects.Enqueue(Instantiate(CommandPrefabs[(int)i], Container.transform, false));
     if (Commands.Count > Length)
     {
         var v = Commands.Dequeue();
         OnPop?.Invoke(v);
         Destroy(CommandObjects.Dequeue());
     }
     RefreshSpacers();
 }
Пример #4
0
 /// <summary>
 /// Straight Up Queue.Dequeue
 /// </summary>
 /// <returns></returns>
 public T getNextObj()
 {
     if (avaliableItems.Count < 1)
     {
         Populate(5);
         OnPop.Invoke(avaliableItems.Peek());
         return(avaliableItems.Dequeue());
     }
     else
     {
         OnPop.Invoke(avaliableItems.Peek());
         return(avaliableItems.Dequeue());
     }
 }
Пример #5
0
        /// <summary>
        /// Pop an instance from the pool
        /// </summary>
        /// <returns></returns>
        public T Pop()
        {
            T instanceToPop;

            //If pool is empty, create a new instance of the default prefab
            if (pool.Count == 0)
            {
                instanceToPop = CreateNew(Prefab);
            }
            //Pool has instances, pops the first item in the pool
            else
            {
                instanceToPop = pool.Pop();
            }

            OnPop?.Invoke(instanceToPop);
            return(instanceToPop);
        }
Пример #6
0
 public ObjectPool(Creator creator, OnPush onPush = null, OnPop onPop = null)
 {
     this.creator = creator;
     this.onPop   = onPop;
     this.onPush  = onPush;
 }