using UnityEngine; namespace MMO { public abstract class MMOSingleton : MonoBehaviour where T : MMOSingleton { private static T _instance = null; public static T Instance { get { if (_instance == null) { GameObject go = new GameObject(); DontDestroyOnLoad(go); go.name = "MMOSingleton:" + typeof(T).ToString(); go.transform.localPosition = Vector3.zero; go.transform.localEulerAngles = Vector3.zero; go.transform.localScale = Vector3.one; _instance = go.AddComponent(); } return _instance; } } private void Awake() { Initialize(); } protected virtual void Initialize() { } private void OnDestroy() { _instance = null; Dispose(); } protected virtual void Dispose() { } } }