单例脚本基类
2017-11-01 本文已影响0人
貪狼大人
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 单例脚本基类
/// </summary>
public class SingletonMono<T> : MonoBehaviour
where T : SingletonMono<T>
{
private static T instance;
public static T Instance
{
get
{
if (null == instance)
{
GameObject obj = new GameObject(typeof(T).Name);
instance = obj.AddComponent<T>();
}
return instance;
}
}
protected virtual void Awake()
{
instance = this as T;
}
}