Singleton.cs 628 B

1234567891011121314151617181920212223242526272829303132
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public abstract class Singleton<T> where T:class, new()
  5. {
  6. protected static T _instance = null;
  7. public static T Instance
  8. {
  9. get
  10. {
  11. if(_instance == null)
  12. {
  13. _instance = new T();
  14. }
  15. return _instance;
  16. }
  17. }
  18. protected Singleton()
  19. {
  20. if(_instance != null)
  21. {
  22. Debug.LogError("This" + (typeof(T)).ToString() + "Singleton Instance is not null");
  23. }
  24. Init();
  25. }
  26. public virtual void Init()
  27. {
  28. }
  29. }