少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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();
    }
 
}