ConfigHelper.cs 577 B

12345678910111213141516171819202122232425262728
  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 = (GameObject)ETModel.Game.Scene.GetComponent<ResourcesComponent>().GetAsset("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 T ToObject<T>(string str)
  22. {
  23. return JsonHelper.FromJson<T>(str);
  24. }
  25. }
  26. }