123456789101112131415161718192021222324252627282930313233 |
- using UnityEngine;
- public abstract class MonoSingleton<T> : MonoBehaviour where T : MonoBehaviour
- {
- public bool global = true;
- static T instance;
- protected bool _isInit = false;
- public static T Instance
- {
- get
- {
- if (instance == null)
- {
- instance =(T)FindObjectOfType<T>();
- }
- return instance;
- }
- }
- void Start()
- {
- if (global) DontDestroyOnLoad(this.gameObject);
- //Debug.Log(this.gameObject.name);
- this.OnStart();
- }
- protected virtual void OnStart()
- {
- }
- }
|