public new T Pop() { var item = base.Pop(); OnPop?.Invoke(item); return(item); }
public virtual T Pop() { T item = stack.Pop(); OnPop?.Invoke(item); return(item); }
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(); }
/// <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()); } }
/// <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); }
public ObjectPool(Creator creator, OnPush onPush = null, OnPop onPop = null) { this.creator = creator; this.onPop = onPop; this.onPush = onPush; }