Singleton.cs 488 B

12345678910111213141516171819202122232425
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace SC.XR.Unity
  7. {
  8. public abstract class Singleton<T> where T : class, new()
  9. {
  10. protected Singleton()
  11. {
  12. }
  13. private readonly static Lazy<T> instance = new Lazy<T>(() => new T());
  14. public static T Instance
  15. {
  16. get
  17. {
  18. return instance.Value;
  19. }
  20. }
  21. }
  22. }