【Unity】通用单例类 Singleton

内容

代码

    public class Singleton<T> where T : new() {
        private static T _instance;

        public static T Instance {
            get {
                if (_instance == null) {
                    _instance = new T();
                }

                return _instance;
            }
        }
    }
posted @ 2024-02-17 10:41  星空探险家  阅读(52)  评论(0编辑  收藏  举报