private void ReadData() { textData.Clear(); //string fileName = Application.dataPath + "/Resources/LTLocalization/localization.csv"; //FILE_PATH // string csvStr = ((TextAsset)Resources.Load(csvFilePath, typeof(TextAsset))).text; string csvStr = FileUtil.ReadStringAsset(csvFilePath); //Debug.Log(csvStr); LTCSVLoader loader = new LTCSVLoader(); // loader.ReadFile(fileName); loader.ReadMultiLine(csvStr); int languageIndex = loader.GetFirstIndexAtRow(GetLanguageAB(language), 0); if (-1 == languageIndex) { Debug.LogError("未读取到" + language + "任何数据,请检查配置表"); return; } int tempRow = loader.GetRow(); for (int i = 0; i < tempRow; ++i) { textData.Add(loader.GetValueAt(0, i), loader.GetValueAt(languageIndex, i)); } }
private void ReadData() { textData.Clear(); //string fileName = Application.dataPath + "/Resources/LTLocalization/localization.csv"; //FILE_PATH string csvStr = Encoding.UTF8.GetString(dataContent); //Debug.Log(csvStr); LTCSVLoader loader = new LTCSVLoader(); // loader.ReadFile(fileName); loader.ReadMultiLine(csvStr); int languageIndex = loader.GetFirstIndexAtRow(GetLanguageAB(language), 0); if (-1 == languageIndex) { Debug.LogError("未读取到" + language + "任何数据,请检查配置表"); return; } int tempRow = loader.GetRow(); for (int i = 0; i < tempRow; ++i) { textData.Add(loader.GetValueAt(0, i), loader.GetValueAt(languageIndex, i)); } }
private void ReadData() { #if UNITY_EDITOR // 在Windows平台下读取语言配置文件 string CSVFilePath = GetWinReadPath(FILE_PATH); LTCSVLoader loader = new LTCSVLoader(); loader.ReadFile(CSVFilePath); // 将配置文件序列化为多个语言类 int csvRow = loader.GetRow(); int csvCol = loader.GetCol(); Debug.Log("row:" + csvRow + "col:" + csvCol); for (int tempCol = 1; tempCol < csvCol; ++tempCol) { LTLocalizationData languageData = new LTLocalizationData(); // 获取第一行数据(语言类型) languageData.LanguageType = loader.GetValueAt(tempCol, 0); // 遍历生成变量 languageData.LanguageData = new Dictionary <string, string>(); for (int tempRow = 1; tempRow < csvRow; ++tempRow) { languageData.LanguageData.Add(loader.GetValueAt(0, tempRow), loader.GetValueAt(tempCol, tempRow)); } // 将语言对象序列化存档 SaveHelper.SaveData(GetWinSavePath(languageData.LanguageType), languageData); if (GetLanguageAB(language).Equals(languageData.LanguageType)) { textData = languageData.LanguageData; } } #else // 读取对应的语言对象 TextAsset tempAsset = (TextAsset)Resources.Load("LTLocalization/" + GetLanguageAB(language), typeof(TextAsset)); if (null == tempAsset) { tempAsset = (TextAsset)Resources.Load("LTLocalization/" + "EN", typeof(TextAsset)); } if (null == tempAsset) { Debug.LogError("未检测到语言配置文件"); } else { string saveData = tempAsset.text; LTLocalizationData currentLanguageData = (LTLocalizationData)SaveHelper.ReadData(saveData, typeof(LTLocalizationData), false); Debug.LogError(currentLanguageData.ToString()); textData = currentLanguageData.LanguageData; } #endif }