using UnityEngine; namespace BrewMonster { public class MonoSingleton : MonoBehaviour where T : MonoBehaviour { private static T _instance; public static T Instance { get { if (_instance == null) { _instance = FindFirstObjectByType(); if (_instance == null) { GameObject obj = new GameObject(typeof(T).Name); _instance = obj.AddComponent(); } } return _instance; } } protected virtual void Awake() { _instance = this as T; BrewMonster.BMLogger.Log("HoangDev : " + gameObject.name); Initialize(); } /// Override this method to initialize the singleton protected virtual void Initialize() { } } }