using System; using UnityEngine; using UnityEngine.UI; using System.Collections; using System.Collections.Generic; public enum CurrentLanguage { Default, English, ChineseSimplified, ChineseTraditional, } public class MulLanStr { public string ID; public string Page; public MulLanStr(string pageAndID) { string[] strings = pageAndID.Split(new[] { LanguageLabel.LanguagePageSeperator }, StringSplitOptions.None); Page = strings[0]; ID = strings[1]; } public override string ToString() { return Language.GetStr(Page, ID); } } public class LanguageManager : Regist { #region Config public static Action OnLanguageChange; public static CurrentLanguage CurrentLanguage; public static Dictionary TextDictionary = new Dictionary(); public static Dictionary TextMeshDictionary = new Dictionary(); #endregion public static void Add(Text text, params object[] objs) { if (TextDictionary.ContainsKey(text)) { TextDictionary[text] = objs; text.text = Translate(objs); } else { TextDictionary.Add(text, objs); text.text = Translate(objs); } } public static void Add(TextMesh textMesh, params object[] objs) { if (TextMeshDictionary.ContainsKey(textMesh)) { TextMeshDictionary[textMesh] = objs; textMesh.text = Translate(objs); } else { TextMeshDictionary.Add(textMesh, objs); textMesh.text = Translate(objs); } } public static void SwitchLanguage(CurrentLanguage currentLanguage) { CurrentLanguage fromLanguage = CurrentLanguage; CurrentLanguage = currentLanguage; Language.SwitchLanguage(currentLanguage); Manager.SwitchLanguage(); foreach (var regist in Initializer.RegistList) { regist.SwitchLanguage(); } foreach (var kv in TextDictionary) { kv.Key.text = Translate(kv.Value); } foreach (var kv in TextMeshDictionary) { kv.Key.text = Translate(kv.Value); } foreach (var kv in AchieveManager.AchieveItemDictionary) { if (kv.Value.Item != null) { kv.Value.DescriptionText.text = AchieveItem.GetDescription(kv.Value.Description, kv.Value.TargetValue); } } for (int i = 0; i < Manager.SkillList.Count; i++) { Manager.SkillList[i].SwitchLanguage(); } if (OnLanguageChange != null) { OnLanguageChange.Invoke(fromLanguage, currentLanguage); } } public static string Translate(object[] objs) { string str = ""; for (int i = 0; i < objs.Length; i++) { MulLanStr mulLanStr = objs[i] as MulLanStr; if (mulLanStr == null) { str += objs[i]; } else { str += mulLanStr.ToString(); } } return str; } }