概述参考请看 参考博客
单例模式的使用非常广泛,相信大家在学习设计模式之前,就已经接触过了单例模式。
1、单例模式
C#中单例模式
public class Test { private static Test _instance; public static Test Instance { get { if (_instance == null) _instance = new Test(); return _instance; } } }
Unity中单例模式
public class Test : MonoBehaviour { public static Test Instance; private void Awake() { Instance = this; } }