ConfigHelper.cs 806 B

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