ConfigHelper.cs 880 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using ETModel;
  3. using UnityEngine;
  4. namespace ETHotfix
  5. {
  6. public static class ConfigHelper
  7. {
  8. public static string GetText(string key)
  9. {
  10. try
  11. {
  12. GameObject config = ETModel.Game.Scene.GetComponent<ResourcesComponent>().GetAsset<GameObject>("config.unity3d", "Config");
  13. string configStr = config.Get<TextAsset>(key).text;
  14. return configStr;
  15. }
  16. catch (Exception e)
  17. {
  18. throw new Exception($"load config file fail, key: {key}", e);
  19. }
  20. }
  21. public static string GetGlobal()
  22. {
  23. try
  24. {
  25. GameObject config = (GameObject)Resources.Load("KV");
  26. string configStr = config.Get<TextAsset>("GlobalProto").text;
  27. return configStr;
  28. }
  29. catch (Exception e)
  30. {
  31. throw new Exception($"load global config file fail", e);
  32. }
  33. }
  34. public static T ToObject<T>(string str)
  35. {
  36. return JsonHelper.FromJson<T>(str);
  37. }
  38. }
  39. }