diff options
author | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-01-25 14:28:30 +0800 |
commit | 6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch) | |
tree | 7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XMainClient/XDataPool.cs |
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XMainClient/XDataPool.cs')
-rw-r--r-- | Client/Assets/Scripts/XMainClient/XDataPool.cs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/XMainClient/XDataPool.cs b/Client/Assets/Scripts/XMainClient/XDataPool.cs new file mode 100644 index 00000000..9cdf3e4f --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XDataPool.cs @@ -0,0 +1,41 @@ +using System;
+using System.Collections.Generic;
+
+namespace XMainClient
+{
+ public class XDataPool<T> where T : XDataBase, new()
+ {
+ private static Queue<T> _pool = new Queue<T>();
+
+ public static T GetData()
+ {
+ bool flag = XDataPool<T>._pool.Count > 0;
+ T result;
+ if (flag)
+ {
+ T t = XDataPool<T>._pool.Dequeue();
+ t.Init();
+ t.bRecycled = false;
+ result = t;
+ }
+ else
+ {
+ T t2 = Activator.CreateInstance<T>();
+ t2.Init();
+ t2.bRecycled = false;
+ result = t2;
+ }
+ return result;
+ }
+
+ public static void Recycle(T data)
+ {
+ bool flag = !data.bRecycled;
+ if (flag)
+ {
+ XDataPool<T>._pool.Enqueue(data);
+ data.bRecycled = true;
+ }
+ }
+ }
+}
|