46 lines
655 B
C#
46 lines
655 B
C#
using UnityEngine;
|
|
|
|
namespace OHM.UnityToolkit.Pooling
|
|
{
|
|
public class PooledObject : MonoBehaviour
|
|
{
|
|
private int poolId;
|
|
|
|
private bool _used;
|
|
|
|
public int PoolId => poolId;
|
|
|
|
public bool Used => _used;
|
|
|
|
public void Use()
|
|
{
|
|
_used = true;
|
|
}
|
|
|
|
public void Release()
|
|
{
|
|
_used = false;
|
|
}
|
|
|
|
public void AddToPool(int poolId)
|
|
{
|
|
this.poolId = poolId;
|
|
}
|
|
|
|
public void RemoveFromPool()
|
|
{
|
|
poolId = -1;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (poolId != -1)
|
|
{
|
|
Debug.LogWarning("Pooled object " + base.name
|
|
+ "destroyed whereas not ready. You should not destroy a pooled , but use the PoolsManager");
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|