//泛型函數
private T GetData<T>() where T:Object,new()
{
T t = new T();
return t;
}
//泛型單例類
public class Singleton<T> where T:Singleton<T>,new()
{
protected static T instance;
public static T Instance
{
get
{
if (instance == null)
instance = new T();
return instance;
}
}
public Singleton()
{
if(instance!=null)
{
Debug.LogException(new System.Exception(
typeof(T).Name + " is Singleton type,can't malloc another"));
}
}
}