using System.Collections.Generic; using UnityEngine; public class IDFactory { private uint m_idSeed = 0; private Stack m_Pool; public IDFactory(uint seed = 0) { m_Pool = new Stack(); m_idSeed = 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 = 0; m_Pool.Clear(); } }