From 1fbf46b1d033215d41d35495ff931a45f9aeea00 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 21 Jul 2018 15:54:12 +0800 Subject: +Singleton --- Singleton/Singleton.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Singleton/Singleton.cs (limited to 'Singleton') 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 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; + } + } +} -- cgit v1.1-26-g67d0