Unity---游戏设计模式(3)之单例模式

概述参考请看 参考博客

单例模式的使用非常广泛,相信大家在学习设计模式之前,就已经接触过了单例模式。

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;
    }
}

猜你喜欢

转载自www.cnblogs.com/Fflyqaq/p/11576524.html