ManaLan.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. public enum Lan
  6. {
  7. English,
  8. ChineseSimplified,
  9. }
  10. public class LanStr
  11. {
  12. public string ID;
  13. public string Page;
  14. public LanStr(string id, string page)
  15. {
  16. ID = id;
  17. Page = page;
  18. }
  19. public override string ToString()
  20. {
  21. return Language.GetStr(ID, Page);
  22. }
  23. }
  24. public class ManaLan : Regist
  25. {
  26. #region 变量
  27. public static Lan CurrentLan = Lan.ChineseSimplified;
  28. public static Dictionary<Text, object[]> TextDic = new Dictionary<Text, object[]>();
  29. public static Dictionary<TextMesh, object[]> TextMeshDic = new Dictionary<TextMesh, object[]>();
  30. #endregion
  31. public static void Add(Text text, params object[] objs)
  32. {
  33. if (TextDic.ContainsKey(text))
  34. {
  35. TextDic[text] = objs;
  36. text.text = Translate(objs);
  37. }
  38. else
  39. {
  40. TextDic.Add(text, objs);
  41. text.text = Translate(objs);
  42. }
  43. }
  44. public static void Add(TextMesh textMesh, params object[] objs)
  45. {
  46. if (TextMeshDic.ContainsKey(textMesh))
  47. {
  48. TextMeshDic[textMesh] = objs;
  49. textMesh.text = Translate(objs);
  50. }
  51. else
  52. {
  53. TextMeshDic.Add(textMesh, objs);
  54. textMesh.text = Translate(objs);
  55. }
  56. }
  57. public static void SwitchLanguage(Lan lan)
  58. {
  59. CurrentLan = lan;
  60. Language.SwitchLanguage(lan);
  61. foreach (var kv in TextDic)
  62. {
  63. kv.Key.text = Translate(kv.Value);
  64. }
  65. foreach (var kv in TextMeshDic)
  66. {
  67. kv.Key.text = Translate(kv.Value);
  68. }
  69. for (int i = 0; i < ManaData.SkillList.Count; i++)
  70. {
  71. ManaData.SkillList[i].SwitchLanguage();
  72. }
  73. }
  74. private static string Translate(object[] objs)
  75. {
  76. string str = "";
  77. for (int i = 0; i < objs.Length; i++)
  78. {
  79. LanStr lanStr = objs[i] as LanStr;
  80. if (lanStr == null)
  81. {
  82. str += objs[i];
  83. }
  84. else
  85. {
  86. str += lanStr.ToString();
  87. }
  88. }
  89. return str;
  90. }
  91. }