public class SingletonNoMono<T> where T : new()
{
private static T instance;
private static readonly object lockObject = new object();
public static T Instance
{
get
{
if (instance == null)
{
lock (lockObject)
{
if (instance == null)
{
instance = new T();
}
}
}
return instance;
}
}
}
使用:
public class SystemCaller : SingletonNoMono<SystemCaller>
{
public void StartLevel(string _level)
{
}
}
SystemCaller.Instance.StartLevel("1");