首页 > 其他 > 详细

单例工具代码

时间:2018-06-03 16:48:12      阅读:201      评论:0      收藏:0      [点我收藏+]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//T为脚本名,可以直接把已经写好的脚本变为单例来用

public class SingleObject<T>where T:class,new() {
    private static T instance;
    public static T Instance
    {
         get
         {
             if(instance==null)
             {
                 instance = new T();
             }
             return instance;
         }
     }
}

 

单例工具代码

原文:https://www.cnblogs.com/fangshiyuanzhucheng/p/9129526.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!