单例模式:整个软件生命周期,,有且仅有一个实例。
关键字:satic
模板1:
public class XXX : MonoBehaviour
{
public static XXX xxx;
private void Awake()
{
xxx = this;
}
}
模板2:
public class YYY
{
private static YYY yyy;
public static YYY Yyy
{
get
{
if (yyy == null)
{
yyy = new YYY();
}
return yyy;
}
}
public void ShowMe()
{
}
}
调用:
YYY.Yyy.ShowMe();