ConfigHelper.cs 856 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. GameObject config = (GameObject)Game.Scene.GetComponent<ResourcesComponent>().GetAsset("config.unity3d", "Config");
  12. string configStr = config.Get<TextAsset>(key).text;
  13. return configStr;
  14. }
  15. catch (Exception e)
  16. {
  17. throw new Exception($"load config file fail, key: {key}", e);
  18. }
  19. }
  20. public static string GetGlobal()
  21. {
  22. try
  23. {
  24. GameObject config = (GameObject)Resources.Load("KV");
  25. string configStr = config.Get<TextAsset>("GlobalProto").text;
  26. return configStr;
  27. }
  28. catch (Exception e)
  29. {
  30. throw new Exception($"load global config file fail", e);
  31. }
  32. }
  33. public static T ToObject<T>(string str)
  34. {
  35. return JsonHelper.FromJson<T>(str);
  36. }
  37. }
  38. }