using UnityEngine; namespace SK.Framework { /// /// Mono类型单例 /// /// public static class MonoSingleton where T : MonoBehaviour, IMonoSingleton { private static T instance; private static readonly object _lock = new object(); public static T Instance { get { lock (_lock) { if (null == instance) { instance = Object.FindObjectOfType() ?? new GameObject($"[{typeof(T).Name}]").AddComponent(); instance.OnInit(); if (instance.IsDontDestroyOnLoad) { Object.DontDestroyOnLoad(instance); } } } return instance; } } public static void Dispose() { instance = null; } } }