private static async void Init() { _phrases = new Dictionary <string, Dictionary <string, string> >(0); ChangeLanguage(PlayerPrefs.GetString("JEngine.Core.Localization.language", CultureInfo.InstalledUICulture.Name)); var file = (TextAsset)await AssetMgr.LoadAsync(CsvLoc, typeof(TextAsset)); if (file == null) { Log.PrintError("Localization模块无效,因为没有获取到表格文件"); return; } //获取全部行 List <string> allRows = new List <string>(0); byte[] array = Encoding.UTF8.GetBytes(file.text); MemoryStream stream = new MemoryStream(array); StreamReader sr = new StreamReader(stream, Encoding.Default); String line; while ((line = sr.ReadLine()) != null) { allRows.Add(line); } sr.Close(); string pattern = ",(?=(?:[^\\" + '"' + "]*\\" + '"' + "[^\\" + '"' + "]*\\" + '"' + ")*[^\\" + '"' + "]*$)"; //获取语言 var header = Regex.Split(allRows[0], pattern); for (int i = 1; i < header.Length; i++) { //某语言 string lang = _getExactValue(header[i]).ToLower(); //获取key和value Dictionary <string, string> p = new Dictionary <string, string>(); for (int j = 1; j < allRows.Count; j++) { //某一行 string row = allRows[j]; //切割 var cells = Regex.Split(row, pattern); //添加key-value p.Add(_getExactValue(cells[0]), _getExactValue(cells[i])); } //添加lang _phrases.Add(lang, p); } }
/// <summary> /// 异步并行加载热更资源(可加回调) /// Load hot update resource async but parallel (can add callback) /// </summary> /// <typeparam name="T"></typeparam> /// <param name="path"></param> /// <param name="callback"></param> /// <param name="mode"></param> public static async void LoadResAsync <T>(string path, Action <T> callback, MatchMode mode = MatchMode.AutoMatch) where T : UnityEngine.Object { var asset = await AssetMgr.LoadAsync(path, typeof(T)); callback?.Invoke(asset as T); }