111
This commit is contained in:
@@ -1,22 +1,25 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Singleton<T> where T:class,new()
|
||||
namespace Tuan.GameFramework
|
||||
{
|
||||
static T _inst;
|
||||
static readonly object _lock = new object();
|
||||
public static T Inst
|
||||
public class Singleton<T> where T : class, new()
|
||||
{
|
||||
get
|
||||
static T _inst;
|
||||
static readonly object _lock = new object();
|
||||
public static T Inst
|
||||
{
|
||||
lock (_lock)
|
||||
get
|
||||
{
|
||||
if(_inst == null)
|
||||
lock (_lock)
|
||||
{
|
||||
_inst = new T();
|
||||
Debug.Log($"[Singleton] 创建 {typeof(T).Name} 实例");
|
||||
if (_inst == null)
|
||||
{
|
||||
_inst = new T();
|
||||
Debug.Log($"[Singleton] 创建 {typeof(T).Name} 实例");
|
||||
}
|
||||
return _inst;
|
||||
}
|
||||
return _inst;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user