25 lines
477 B
C#
25 lines
477 B
C#
|
|
using System.Collections.Generic;
|
||
|
|
namespace Gameplay.Pool
|
||
|
|
{
|
||
|
|
public class ObjPool
|
||
|
|
{
|
||
|
|
private readonly Stack<object> _pool = new Stack<object>();
|
||
|
|
|
||
|
|
public int count => _pool.Count;
|
||
|
|
|
||
|
|
public object Get()
|
||
|
|
{
|
||
|
|
if (_pool.Count > 0)
|
||
|
|
{
|
||
|
|
return _pool.Pop();
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Return(object obj)
|
||
|
|
{
|
||
|
|
_pool.Push(obj);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|