WindowSingleton.cs 715 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using UnityEngine;
  2. public abstract class WindowSingleton<T> : MonoBehaviour where T : MonoBehaviour
  3. {
  4. //public string data;
  5. static T instance;
  6. protected bool _isInit = false;
  7. public static T Instance
  8. {
  9. get
  10. {
  11. if (instance == null)
  12. {
  13. instance =(T)FindObjectOfType<T>();
  14. }
  15. return instance;
  16. }
  17. }
  18. void Start()
  19. {
  20. //if (global) DontDestroyOnLoad(this.gameObject);
  21. //Debug.Log(this.gameObject.name);
  22. this.OnStart();
  23. }
  24. protected virtual void OnStart()
  25. {
  26. }
  27. public virtual void UpdateData()
  28. {
  29. }
  30. public virtual void OnEnable()
  31. {
  32. }
  33. }