123456789101112131415161718192021222324 |
- namespace Plugins.CxShine.Singleton
- {
- public abstract class ScriptSingleton<T>
- where T : new()
- {
- private static T _instance;
- private static readonly object _lock = new();
- public static T Instance
- {
- get
- {
- if (_instance == null)
- // 上锁,防止重复实例化
- lock (_lock)
- {
- if (_instance == null) _instance = new T();
- }
- return _instance;
- }
- }
- }
- }
|