Singleton.cs 501 B

1234567891011121314151617181920212223242526
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Singleton<T> where T : class , new()
  5. {
  6. private static readonly object _lock = new object();
  7. private static T _instance;
  8. public static T Instance
  9. {
  10. get
  11. {
  12. lock (_lock)
  13. {
  14. if (_instance == null)
  15. {
  16. _instance = new T();
  17. }
  18. }
  19. return _instance;
  20. }
  21. }
  22. }