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]