SD-20250415ABSO\Administrator 321e38cb79 冠军框架迁移
2025-04-18 19:18:15 +08:00

26 lines
628 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MonoSingleton<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).Name;
GameObject.DontDestroyOnLoad(obj);
T component = obj.AddComponent<T>();
_instance = component;
}
return _instance;
}
}
}