123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- 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[] { "__" }, 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 CurrentLanguage CurrentLanguage;
- public static Dictionary<Text, object[]> TextDic = new Dictionary<Text, object[]>();
- public static Dictionary<TextMesh, object[]> TextMeshDic = new Dictionary<TextMesh, object[]>();
- #endregion
- public static void Add(Text text, params object[] objs)
- {
- if (TextDic.ContainsKey(text))
- {
- TextDic[text] = objs;
- text.text = Translate(objs);
- }
- else
- {
- TextDic.Add(text, objs);
- text.text = Translate(objs);
- }
- }
- public static void Add(TextMesh textMesh, params object[] objs)
- {
- if (TextMeshDic.ContainsKey(textMesh))
- {
- TextMeshDic[textMesh] = objs;
- textMesh.text = Translate(objs);
- }
- else
- {
- TextMeshDic.Add(textMesh, objs);
- textMesh.text = Translate(objs);
- }
- }
- public static void SwitchLanguage(CurrentLanguage currentLanguage)
- {
- CurrentLanguage = currentLanguage;
- Language.SwitchLanguage(currentLanguage);
- Manager.SwitchLanguage();
- foreach (var kv in TextDic)
- {
- kv.Key.text = Translate(kv.Value);
- }
- foreach (var kv in TextMeshDic)
- {
- kv.Key.text = Translate(kv.Value);
- }
- foreach (var kv in AchieveManager.AchieveDic)
- {
- if (kv.Value.AchieveItem != null)
- {
- kv.Value.Lab.text = Achieve.GetDescription(kv.Value.Desc, kv.Value.TargetValue);
- }
- }
- for (int i = 0; i < Manager.SkillList.Count; i++)
- {
- Manager.SkillList[i].SwitchLanguage();
- }
- }
- 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;
- }
- }
|