CommonDataManager.cs 940 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using GFGGame;
  2. using SimpleJSON;
  3. using UnityEngine;
  4. using YooAsset;
  5. public class CommonDataManager2 : Singleton<CommonDataManager2>
  6. {
  7. public static cfg.Tables Tables;
  8. protected override void Awake()
  9. {
  10. base.Awake();
  11. DontDestroyOnLoad(gameObject);
  12. }
  13. public void Init()
  14. {
  15. Tables = new cfg.Tables(LoadByteBuf);
  16. }
  17. private JSONNode LoadByteBuf(string file)
  18. {
  19. var str = ReadStringSync(file);
  20. if (string.IsNullOrEmpty(str))
  21. {
  22. Debug.LogError("load luban json failed:" + file);
  23. return null;
  24. }
  25. return JSON.Parse(str);
  26. }
  27. public string ReadStringSync(string loc)
  28. {
  29. var handler = YooAssets.LoadAssetSync<Sprite>(loc);
  30. if (handler == null)
  31. {
  32. return null;
  33. }
  34. var data = handler.AssetObject as TextAsset;
  35. return data != null ? data.text : null;
  36. }
  37. }