using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// 单例模式类模板
///
public class UnitySingleton : MonoBehaviour
where T : Component
{
private static T m_instance;
public static T Instance
{
get
{
if (m_instance == null)
{
m_instance = FindObjectOfType();
if (m_instance == null)
{
Debug.LogError("缺少 " + typeof(T) + " 这个单例,没法在场景中找到");
}
}
return m_instance;
}
}
protected virtual void Awake()
{
if (m_instance == null)
{
m_instance = this as T;
}
else
{
Destroy(gameObject);
}
}
}