|
|
|
|
|
|
/// <typeparam name="T">Specifies the type of elements to pool.</typeparam>
|
|
|
|
public abstract class PoolSO<T> : ScriptableObject, IPool<T> |
|
|
|
{ |
|
|
|
protected readonly Stack<T> _available = new Stack<T>(); |
|
|
|
protected readonly Stack<T> Available = new Stack<T>(); |
|
|
|
public abstract IFactory<T> Factory { get; set; } |
|
|
|
protected bool HasBeenPrewarmed { get; set; } |
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
for (int i = 0; i < num; i++) |
|
|
|
{ |
|
|
|
_available.Push(Create()); |
|
|
|
Available.Push(Create()); |
|
|
|
} |
|
|
|
HasBeenPrewarmed = true; |
|
|
|
} |
|
|
|
|
|
|
return _available.Count > 0 ? _available.Pop() : Create(); |
|
|
|
return Available.Count > 0 ? Available.Pop() : Create(); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual IEnumerable<T> Request(int num = 1) |
|
|
|
|
|
|
|
|
|
|
public virtual void Return(T member) |
|
|
|
{ |
|
|
|
_available.Push(member); |
|
|
|
Available.Push(member); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual void Return(IEnumerable<T> members) |
|
|
|
|
|
|
|
|
|
|
public virtual void OnDisable() |
|
|
|
{ |
|
|
|
_available.Clear(); |
|
|
|
Available.Clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |