/*
*DanLi
* 整个软件生命周期,有且只有一个实例
*/
public class DanLi : MonoBehaviour
{
//继承于MonoBehaviour的类单例
public static DanLi instance;
private void Awake()
{
instance = this;
}
}
//非继承于MonoBehaviour的类单例
public class TestSingle {
private static TestSingle instance;
public static TestSingle Instance {
get{
if (instance == null)
{ instance = new TestSingle();
}
return instance;
}
}
}