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