From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/XMainClient/XDataPool.cs | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XDataPool.cs (limited to 'Client/Assets/Scripts/XMainClient/XDataPool.cs') 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 where T : XDataBase, new() + { + private static Queue _pool = new Queue(); + + public static T GetData() + { + bool flag = XDataPool._pool.Count > 0; + T result; + if (flag) + { + T t = XDataPool._pool.Dequeue(); + t.Init(); + t.bRecycled = false; + result = t; + } + else + { + T t2 = Activator.CreateInstance(); + t2.Init(); + t2.bRecycled = false; + result = t2; + } + return result; + } + + public static void Recycle(T data) + { + bool flag = !data.bRecycled; + if (flag) + { + XDataPool._pool.Enqueue(data); + data.bRecycled = true; + } + } + } +} -- cgit v1.1-26-g67d0