using UnityEngine; namespace Utils { public abstract class MonoSingleton : MonoBehaviour where T : MonoBehaviour { private static T _instance; public bool isGlobal = true; public static T Instance => _instance ??= FindFirstObjectByType(); private void Awake() { Debug.LogWarning($"{typeof(T)} [{GetInstanceID()}] Awake"); if (isGlobal) { if (_instance is not null && _instance != gameObject.GetComponent()) { Destroy(gameObject); return; } DontDestroyOnLoad(gameObject); _instance = gameObject.GetComponent(); } OnStart(); } protected abstract void OnStart(); } }