Files
5.24BuYu/Assets/MyGame/Framework/Base/AutoMonoSingleton.cs
T
2026-10-14 19:39:24 +08:00

23 lines
546 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AutoMonoSingleton<T>: MonoBehaviour where T : MonoBehaviour
{
private static T _instance;
public static T Instance
{
get
{
if(_instance==null)
{
GameObject obj = new GameObject();
obj.name = typeof(T).ToString();
DontDestroyOnLoad(obj);
_instance = obj.AddComponent<T>();
}
return _instance;
}
}
}