summaryrefslogtreecommitdiff
path: root/SurvivalTest/Assets/Scripts/Utils/Singleton.cs
diff options
context:
space:
mode:
Diffstat (limited to 'SurvivalTest/Assets/Scripts/Utils/Singleton.cs')
-rw-r--r--SurvivalTest/Assets/Scripts/Utils/Singleton.cs24
1 files changed, 24 insertions, 0 deletions
diff --git a/SurvivalTest/Assets/Scripts/Utils/Singleton.cs b/SurvivalTest/Assets/Scripts/Utils/Singleton.cs
new file mode 100644
index 0000000..d7aad49
--- /dev/null
+++ b/SurvivalTest/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