示例#1
0
 protected virtual void Awake()
 {
     if (_instance != null)
     {
         Debug.LogError("MonoSingleton [" + _instance.ToString() + "] allready exist");
         Destroy(this);
     }
     _instance = GetComponent <T>();
     if (dontDestroyOnLoad)
     {
         DontDestroyByLoad.EnableDontDestroyOnLoad(gameObject);
     }
     gameObject.SetActive(!hideAtLaunch);
 }
示例#2
0
 protected virtual void OnDestroy()
 {
     _instance = default;
     DontDestroyByLoad.OnDestroyObj(gameObject);
 }