123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System.Collections.Generic;
- using UnityEngine;
- public class LanguageMatchManager : MonoBehaviour
- {
- static LanguageMatchManager _instance;
- public static LanguageMatchManager Instance { get { return _instance; } }
- private int languageType = 0;
- private MultiLanguageConfig scrMonoConfig;
- public MultiLanguageConfig scrConfig;
- private List<LanguageMatch> listlanguageMatch;
- public void Awake()
- {
-
- Init();
- }
- public void Init()
- {
- _instance = this;
- languageType = PlayerPrefs.GetInt("CurLanguage", 0);
- listlanguageMatch = new List<LanguageMatch>();
- scrMonoConfig = Resources.Load<MultiLanguageConfig>("localLanguage");
- }
- public void AddScrLanguageMatch(LanguageMatch item)
- {
- if (!listlanguageMatch.Contains(item))
- {
- listlanguageMatch.Add(item);
- MatchLanguageText(item);
- }
- }
- public string GetLanByKey(string str)
- {
- string lan = scrMonoConfig.GetDataByName(str, (LanguageType)languageType);
- return lan;
- }
- public void RemoveScrLanguageMatch(LanguageMatch item)
- {
- if (listlanguageMatch.Contains(item))
- {
- listlanguageMatch.Remove(item);
- }
- }
- public void RefreshLanguage(int _lan)
- {
- int lan = (int)_lan;
- if (languageType == lan) return;
- PlayerPrefs.SetInt("CurLanguage", _lan);
- languageType = lan;
- foreach (var item in listlanguageMatch)
- {
- if (item != null && item.gameObject.activeSelf)
- {
- MatchLanguageText(item);
- }
- }
- }
- public void MatchLanguageText(LanguageMatch lm)
- {
- if (scrConfig == null)
- {
- lm.RefreshTxt("null");
- return;
- }
- string str = scrConfig.GetDataByName(lm.configName, (LanguageType)languageType);
- lm.RefreshTxt(str == null ? "null" : str);
- if (str == null)
- {
- string strr = GetErrorPrefabName(lm, out string parentName);
- if (!parentName.Contains("Clone"))
- {
- Debug.LogError($"静态多语言表 ID:{lm.configName},表里不存在.预制体位置:{strr}");
- }
- }
- }
- public LanguageType GetCurLanType()
- {
- return (LanguageType)languageType;
- }
- public string GetErrorPrefabName(LanguageMatch lm, out string parentName)
- {
- string path = lm.name;
- bool isFind = true;
- Transform tf = lm.transform;
- int debugCount = 16;
- parentName = "";
- while (isFind && debugCount > 0)
- {
- debugCount--;
- tf = tf.parent;
- if (tf.name.Contains("Dlg"))
- {
- parentName = tf.name;
- isFind = false;
- }
- path = tf.gameObject.name + "/" + path;
- }
- return path;
- }
- }
|