diff options
author | chai <chaifix@163.com> | 2018-07-21 15:54:12 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-07-21 15:54:12 +0800 |
commit | 1fbf46b1d033215d41d35495ff931a45f9aeea00 (patch) | |
tree | 975ab346d218241586158a9db28e9d197ebbc2ee | |
parent | d66e32f2adced85c893cb8910caf2003e3c01b82 (diff) |
+Singleton
-rw-r--r-- | Singleton/Singleton.cs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Singleton/Singleton.cs b/Singleton/Singleton.cs new file mode 100644 index 0000000..4b5ae47 --- /dev/null +++ b/Singleton/Singleton.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Assets.Scripts.Tools.Singleton +{ + class Singleton<T> where T : class, new() + { + private static T _instance; + + public static T Instance + { + get + { + if (_instance == null) + _instance = new T(); + return _instance; + } + } + + public static void Release() + { + if (_instance != null) + _instance = null; + } + } +} |