using System.Collections.Generic;
|
using UnityEngine;
|
|
public class IDFactory
|
{
|
private uint m_idSeed = 0;
|
private uint m_InitSeed = 0;
|
|
private Stack<uint> m_Pool;
|
|
public IDFactory(uint seed = 0)
|
{
|
m_Pool = new Stack<uint>();
|
m_idSeed = seed;
|
m_InitSeed = seed;
|
}
|
|
public uint Request()
|
{
|
uint _idSeed = 0;
|
|
if (m_Pool.Count > 0)
|
{
|
_idSeed = m_Pool.Pop();
|
}
|
else
|
{
|
_idSeed = ++m_idSeed;
|
}
|
|
return _idSeed;
|
}
|
|
public void Release(uint id)
|
{
|
if (m_Pool.Contains(id))
|
{
|
DebugEx.LogWarning("释放ID: {0} 的时候检测池中已存在此id");
|
return;
|
}
|
|
m_Pool.Push(id);
|
}
|
|
public void Clear()
|
{
|
m_idSeed = m_InitSeed;
|
m_Pool.Clear();
|
}
|
|
}
|