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/LuaEngine/Core/Single.cs |
+scripts
Diffstat (limited to 'Client/Assets/Scripts/LuaEngine/Core/Single.cs')
-rw-r--r-- | Client/Assets/Scripts/LuaEngine/Core/Single.cs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/LuaEngine/Core/Single.cs b/Client/Assets/Scripts/LuaEngine/Core/Single.cs new file mode 100644 index 00000000..7286d44c --- /dev/null +++ b/Client/Assets/Scripts/LuaEngine/Core/Single.cs @@ -0,0 +1,59 @@ +using UnityEngine;
+using System.Collections;
+
+public class Single<T> where T : new()
+{
+ private static T s_instance;
+
+ public static T Instance
+ {
+ get { return GetInstance(); }
+ }
+
+ protected Single()
+ {
+ }
+
+ public static void CreateInstance()
+ {
+ if (s_instance == null)
+ {
+ s_instance = new T();
+
+ (s_instance as Single<T>).Init();
+ }
+ }
+
+ public static void DestroyInstance()
+ {
+ if (s_instance != null)
+ {
+ (s_instance as Single<T>).UnInit();
+ s_instance = default(T);
+ }
+ }
+
+ public static T GetInstance()
+ {
+ if (s_instance == null)
+ {
+ CreateInstance();
+ }
+ return s_instance;
+ }
+
+ public static bool HasInstance()
+ {
+ return (s_instance != null);
+ }
+
+ public virtual void Init()
+ {
+ }
+
+ public virtual void UnInit()
+ {
+ }
+
+
+}
|