123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- 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<CurrentLanguage, CurrentLanguage> OnLanguageChange;
- public static CurrentLanguage CurrentLanguage;
- public static Dictionary<Text, object[]> TextDictionary = new Dictionary<Text, object[]>();
- public static Dictionary<TextMesh, object[]> TextMeshDictionary = new Dictionary<TextMesh, object[]>();
- #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;
- }
- }
|