private static void RefreshLanguageFiles() { if (mCurConfig == null) { return; } mCurRegionLanguageFilesInfo = new List <S_LanguageFile_Info>(); //遍历所有区域 foreach (var item in mCurConfig.Regions) { mCurRegions.Add(item.region_name); if (item.region_name == mCurConfig.defaultRegion) { //把语言包统统缓存起来 foreach (var lang in item.language_file) { RemoveIfLangCacheExist(lang); var textasset = AssetDatabase.LoadAssetAtPath <TextAsset>(lang); if (textasset != null) { mCurRegionLanguageFilesInfo.Add(new S_LanguageFile_Info() { path = lang, region = item.region_name, isBase64 = false, data = JsonUtility.FromJson <I18NJsonTpl>(textasset.text) }); } //把语言添加进变动监听 AssetInputHandle.AddAssetListener(lang, OnLangJsonFileChanged); } foreach (var lang in item.language_file_base64) { if (!IsLangCacheExist(lang)) { var textasset = AssetDatabase.LoadAssetAtPath <TextAsset>(lang); if (textasset != null) { mCurRegionLanguageFilesInfo.Add(new S_LanguageFile_Info() { path = lang, region = item.region_name, isBase64 = true, data = JsonUtility.FromJson <I18NJsonTpl>(textasset.text) }); } } //把语言添加进变动监听 AssetInputHandle.AddAssetListener(lang, OnLangJsonFileChanged); } } } }
static XI18NCacheEditor() { //添加配置文件到资源监听 AssetInputHandle.AddAssetListener("Assets/Resources/" + TinaX.Setup.Framework_Config_Path + "/" + TinaX.Conf.ConfigPath.i18n, OnConfigFileChanged); mCurConfig = TinaX.Config.GetTinaXConfig <I18NConfig>(TinaX.Conf.ConfigPath.i18n); if (mCurConfig != null) { RefreshLanguageFiles(); } }
private static void OnLangJsonFileChanged(string path, AssetInputHandle.ResChangeType type) { if (type == AssetInputHandle.ResChangeType.Remove) { RemoveIfLangCacheExist(path); AssetInputHandle.RemoveAssetListener(path, OnLangJsonFileChanged); } if (type == AssetInputHandle.ResChangeType.CreateOrModify) { foreach (var item in mCurRegionLanguageFilesInfo) { if (item.path == path) { item.RefreshFile(); break; } } } }