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

☆樱花仙子☆ 提交于 2019-12-01 06:53:49

概述参考请看 参考博客

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

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;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!