YanCheng_Metrology/Assets/Scripts/ProjectBase/BaseManager/SingletonAutoMono.cs

21 lines
455 B
C#

using UnityEngine;
public class SingletonAutoMono<T> : MonoBehaviour where T : MonoBehaviour
{
private static T instance;
public static T Instance
{
get
{
if (instance == null)
{
GameObject obj = new GameObject(typeof(T).ToString());
instance = obj.AddComponent<T>();
DontDestroyOnLoad(obj);
}
return instance;
}
}
}