模板:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class Singleton<T> : MonoBehaviour
//对泛型T进行类型约束
where T : MonoBehaviour
{
private static T m_instance = null;
private static T Instance
{
get { return m_instance; }
}
protected virtual void Awake()
{
m_instance = this as T;
}
}
使用: