using UnityEngine;
|
using System.Collections;
|
|
|
public abstract class Singleton<T> : MonoBehaviour where T : Singleton<T>
|
{
|
private static T g_Instance = default(T);
|
public static T Inst
|
{
|
get
|
{
|
if (g_Instance == null)
|
{
|
T t = GameObject.FindObjectOfType(typeof(T)) as T;
|
g_Instance = t;
|
|
if (t == null)
|
{
|
string strName = typeof(T).ToString();
|
GameObject go = new GameObject(string.Format("[{0}]", strName));
|
g_Instance = go.AddComponent<T>();
|
}
|
}
|
|
return g_Instance;
|
}
|
|
set { g_Instance = value; }
|
}
|
|
public virtual void Awake()
|
{
|
//DontDestroyOnLoad(this);
|
}
|
}
|