单例工具代码

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

 

posted @ 2018-06-03 16:25  方是源  阅读(130)  评论(0编辑  收藏  举报
回顶部