123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- using System.Collections.Generic;
- public enum Lan
- {
- English,
- ChineseSimplified,
- }
- public class LanStr
- {
- public string ID;
- public string Page;
- public LanStr(string id, string page)
- {
- ID = id;
- Page = page;
- }
- public override string ToString()
- {
- return Language.GetStr(ID, Page);
- }
- }
- public class ManaLan : Regist
- {
- #region 变量
- public static Lan CurrentLan = Lan.ChineseSimplified;
- 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(Lan lan)
- {
- CurrentLan = lan;
- Language.SwitchLanguage(lan);
- foreach (var kv in TextDic)
- {
- kv.Key.text = Translate(kv.Value);
- }
- foreach (var kv in TextMeshDic)
- {
- kv.Key.text = Translate(kv.Value);
- }
- for (int i = 0; i < ManaData.SkillList.Count; i++)
- {
- ManaData.SkillList[i].SwitchLanguage();
- }
- }
- private static string Translate(object[] objs)
- {
- string str = "";
- for (int i = 0; i < objs.Length; i++)
- {
- LanStr lanStr = objs[i] as LanStr;
- if (lanStr == null)
- {
- str += objs[i];
- }
- else
- {
- str += lanStr.ToString();
- }
- }
- return str;
- }
- }
|