diff options
author | chai <chaifix@163.com> | 2022-04-22 09:24:15 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2022-04-22 09:24:15 +0800 |
commit | 06df35f1e8e9695b844553867a39cd12d68db8b4 (patch) | |
tree | 3af5c78db3d84bfe8bbea26a54031cf0b1169f7e /AlienSurvival/Assets/Scripts/Utils/Singleton.cs | |
parent | ea0717eba0b624d47bd60edba7fb7862633f2f5f (diff) |
*arrow
Diffstat (limited to 'AlienSurvival/Assets/Scripts/Utils/Singleton.cs')
-rw-r--r-- | AlienSurvival/Assets/Scripts/Utils/Singleton.cs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/AlienSurvival/Assets/Scripts/Utils/Singleton.cs b/AlienSurvival/Assets/Scripts/Utils/Singleton.cs new file mode 100644 index 0000000..d7aad49 --- /dev/null +++ b/AlienSurvival/Assets/Scripts/Utils/Singleton.cs @@ -0,0 +1,24 @@ +public class Singleton<T> where T : class, new() +{ + private static T _instance; + private static readonly object syslock = new object(); + + public static T Instance + { + get + { + if (_instance == null) + { + lock (syslock) + { + if (_instance == null) + { + _instance = new T(); + } + } + } + return _instance; + + } + } +}
\ No newline at end of file |