Unity 框架

SingletonBase.cs 447B

12345678910111213141516171819202122
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace TFramework
  5. {
  6. /// <summary>
  7. /// µ¥Àýģʽ»ùÀà
  8. /// </summary>
  9. /// <typeparam name="T"></typeparam>
  10. public class SingletonBase<T> where T : class, new()
  11. {
  12. private static T _instance;
  13. /// <summary>
  14. /// µ±Ç°ÊµÀý
  15. /// </summary>
  16. public static T Instance => _instance = _instance ?? new T();
  17. }
  18. }