一.单例类模板
using UnityEngine;
/// <summary>
/// 通用Mono单例模板
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class MonoSingleton<T> : MonoBehaviour where T : MonoSingleton<T>
{
private static T ms_instance;
public static T Instance
{
get
{
if (ms_instance == null)
{
ms_instance = Instantiate();
}
return ms_instance;
}
}
protected static T Instantiate()
{
if (ms_instance != null) return ms_instance;
// 在场景中查找T类型的Mono类
ms_instance = (T)FindObjectOf