locle210 发表于 2018-1-19 16:12:58

unity 单例 封装


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//System.IDisposable where T : new()
//继承System.IDisposable
public class Singleton<T> : System.IDisposable where T :new()
{
    private static T instance;
    public static T Instance
    {
      get
      {
            if (instance == null)
            {
                instance = new T();
            }
            return instance;
      }
    }




    public virtual void Dispose()
    {
      // 内存处理的善后工作
    }
}


页: [1]
查看完整版本: unity 单例 封装