单例脚本基类
作者:
貪狼大人 | 来源:发表于
2017-11-01 21:18 被阅读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;
}
}
本文标题:单例脚本基类
本文链接:https://www.haomeiwen.com/subject/pxqnpxtx.html
网友评论