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