LanguageDataUtils.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using HDJ.Framework.Utils;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using UnityEngine;
  7. public class LanguageDataUtils
  8. {
  9. public const string SavePathDir = "Assets/Resources/Data/Language/";
  10. public static LanguageSettingConfig LoadEditorConfig()
  11. {
  12. if(ResourceManager.GetResourceIsExist(LanguageManager.c_configFileName))
  13. {
  14. LanguageSettingConfig config;
  15. string json = AssetsPoolManager.ReadTextFile(LanguageManager.c_configFileName);
  16. if (!string.IsNullOrEmpty(json))
  17. config = JsonUtils.FromJson<LanguageSettingConfig>(json);
  18. else
  19. {
  20. config = null;
  21. //config.defaultLanguage = SystemLanguage.ChineseSimplified;
  22. //config.gameExistLanguages.Add(SystemLanguage.ChineseSimplified);
  23. }
  24. return config;
  25. }
  26. else
  27. {
  28. return null;
  29. }
  30. }
  31. public static void SaveEditorConfig(LanguageSettingConfig config)
  32. {
  33. string json = JsonUtils.ToJson(config);
  34. FileUtils.CreateTextFile(SavePathDir + LanguageManager.c_configFileName + ".txt", json);
  35. }
  36. public static DataTable LoadFileData(SystemLanguage language, string fullKeyFileName)
  37. {
  38. if (string.IsNullOrEmpty(fullKeyFileName))
  39. return null;
  40. string path = GetLanguageSavePath(language, fullKeyFileName);
  41. string text = FileUtils.LoadTextFileByPath(path);
  42. //Debug.Log("path :" + path);
  43. //Debug.Log("Text :" + text);
  44. return DataTable.Analysis(text);
  45. }
  46. public static string GetLanguageSavePath(SystemLanguage langeuageName, string fullkeyFileName)
  47. {
  48. return LanguageDataUtils.SavePathDir + langeuageName + "/" + LanguageManager.GetLanguageDataName(langeuageName, fullkeyFileName) + ".txt";
  49. }
  50. }