UGUITextTool.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. namespace UnityEngine.UI
  5. {
  6. public class UGUITextTool
  7. {
  8. public static ITextTool TextTool;
  9. public interface IConfig
  10. {
  11. int GetID();
  12. }
  13. [Serializable]
  14. public struct LanguageChineseConfig : IConfig
  15. {
  16. public int GetID()
  17. {
  18. return ID;
  19. }
  20. /// <summary>
  21. ///ID
  22. /// </summary>
  23. #if !COMBAT_SERVER
  24. public int ID;
  25. #else
  26. public int ID{ set; get; }
  27. #endif
  28. /// <summary>
  29. ///文本内容
  30. /// </summary>
  31. #if !COMBAT_SERVER
  32. public string txt;
  33. #else
  34. public string txt{ set; get; }
  35. #endif
  36. }
  37. public class EditorLanguageChinese
  38. {
  39. public List<LanguageChineseConfig> configList = new List<LanguageChineseConfig>();
  40. public string Text(int id)
  41. {
  42. for (int i = 0; i < configList.Count; i++)
  43. {
  44. if (configList[i].ID == id)
  45. {
  46. return configList[i].txt;
  47. }
  48. }
  49. return "无";
  50. }
  51. }
  52. protected static EditorLanguageChinese editorLanguageChinese;
  53. protected static EditorLanguageChinese editorStartLanguageChinese;
  54. public static string GetLanguageMassage(int id)
  55. {
  56. if (!Application.isPlaying)
  57. {
  58. #if UNITY_EDITOR
  59. editorStartLanguageChinese = new EditorLanguageChinese();
  60. TextAsset ta =
  61. AssetDatabase.LoadAssetAtPath<TextAsset>(@"Assets\Res\Config\StartGameLanguageChineseConfig.json");
  62. if (ta != null)
  63. {
  64. editorStartLanguageChinese = JsonUtility.FromJson<EditorLanguageChinese>(ta.text);
  65. }
  66. editorLanguageChinese = new EditorLanguageChinese();
  67. ta = AssetDatabase.LoadAssetAtPath<TextAsset>(@"Assets\Res\Config\LanguageChineseConfig.json");
  68. if (ta != null)
  69. {
  70. editorLanguageChinese = JsonUtility.FromJson<EditorLanguageChinese>(ta.text);
  71. }
  72. if (editorStartLanguageChinese != null && editorStartLanguageChinese.Text(id) != "无")
  73. {
  74. return editorStartLanguageChinese.Text(id);
  75. }
  76. else
  77. {
  78. if (editorLanguageChinese != null)
  79. {
  80. return editorLanguageChinese.Text(id);
  81. }
  82. }
  83. #endif
  84. }
  85. else
  86. {
  87. return TextTool?.GetLanguageMassge(id);
  88. }
  89. return "无";
  90. }
  91. }
  92. }