LitJsonMgr.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using UnityEngine;
  2. namespace SC.XR.Unity.Module_PlatformAccount
  3. {
  4. public abstract class LitJsonMgr
  5. {
  6. private static LitJsonMgr instance;
  7. public static LitJsonMgr Instance
  8. {
  9. get
  10. {
  11. if (instance != null)
  12. {
  13. return instance;
  14. }
  15. else
  16. {
  17. instance = new LitJsonManager();
  18. }
  19. return instance;
  20. }
  21. }
  22. /// <summary>
  23. /// Json保存目录
  24. /// </summary>
  25. public string DirectoryPath { get { return Application.persistentDataPath + "/PlatformAccount/"; } }
  26. /// <summary>
  27. /// 初始化Json
  28. /// </summary>
  29. public abstract void Init<T>(string key, T t) where T : new();
  30. /// <summary>
  31. /// 读取Json
  32. /// </summary>
  33. public abstract T ReadJson<T>(string key, ref T t) where T : new();
  34. /// <summary>
  35. /// 写入Json
  36. /// </summary>
  37. public virtual void WriteJson<T>(string key, T t) where T : new()
  38. {
  39. Save();
  40. }
  41. /// <summary>
  42. /// 保存数据
  43. /// </summary>
  44. public virtual void Save() { }
  45. }
  46. }