using UnityEngine; namespace AlicizaX { /// /// 游戏框架单例 /// /// public abstract class GameFrameworkMonoSingleton : MonoBehaviour where T : MonoBehaviour { private static T _instance; [UnityEngine.Scripting.Preserve] protected GameFrameworkMonoSingleton() { } /// /// 单例对象 /// [UnityEngine.Scripting.Preserve] public static T Instance { get { if (_instance == null) { #if UNITY_6000_0_OR_NEWER _instance = Object.FindFirstObjectByType(); #else _instance = (T)Object.FindObjectOfType(typeof(T)); #endif } if (_instance == null) { var insObj = new GameObject(); _instance = insObj.AddComponent(); _instance.name = "[Singleton]" + typeof(T); Object.DontDestroyOnLoad(insObj); } return _instance; } } } }