单例
public class Singleton<T> where T : new()
{
private static T instance;
public static T Instance
{
get
{
if (instance == null)
{
instance = new T();
}
return instance;
}
}
}
Unity中的mono单例
public class Singleton<T> : MonoBehaviour where T : Singleton<T>
{
private static T instance;
public static T Instance { get => instance; }
protected virtual void Awake()
{
if(instance != null)
Destroy(this);
else
instance = (T)this;
}
}
标签:Singleton,mono,instance,static,单例,public
From: https://www.cnblogs.com/AlexNJW/p/17007161.html