public TranslateMapper Export(string filePath) { Regex rx = new Regex("[\u4e00-\u9fa5]+"); TranslateMapper trsMap = new TranslateMapper(filePath); string assetPath = filePath.Substring(filePath.IndexOf("Assets/")); GameObject prefab = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)) as GameObject; GameObject instance = GameObject.Instantiate(prefab) as GameObject; #if NGUI UILabel[] labels = instance.GetComponentsInChildren <UILabel>(true); for (int q = 0; q < labels.Length; q++) { string labText = labels[q].text.Trim(); if (string.IsNullOrEmpty(labText)) { continue; } labText = labText.Replace("\n", @"\n").Replace("\r", ""); if (rx.IsMatch(labText) && !trsMap.ContainWorld(labText)) { trsMap.AddWorld(labText); } } // UIInput中的默认文本 UIInput[] inputs = instance.GetComponentsInChildren <UIInput>(true); for (int q = 0; q < inputs.Length; q++) { string text = inputs[q].value.Trim(); if (string.IsNullOrEmpty(text)) { continue; } text = text.Replace("\n", @"\n").Replace("\r", ""); if (rx.IsMatch(text) && !trsMap.ContainWorld(text)) { trsMap.AddWorld(text); } } #endif GameObject.DestroyImmediate(instance); return(trsMap); }
public TranslateMapper Export(string filePath) { TranslateMapper trsMap = new TranslateMapper(filePath); if (isFilterFolder(filePath)) { return(trsMap); } Regex rx = new Regex("[\u4e00-\u9fa5]+"); string assetPath = filePath.Substring(filePath.IndexOf("Assets/")); string[] lines = File.ReadAllLines(assetPath); //用正则表达式把代码里面两种字符串中间的字符串提取出来。 Regex reg = new Regex("\"[^\"]*\""); Regex reg2 = new Regex("'[^\']*\'"); //Lua单引号字符 for (int i = 0; i < lines.Length; i++) { if (isFilter(lines[i])) { continue; } MatchCollection mc = reg.Matches(lines[i]); if (mc.Count == 0) { mc = reg2.Matches(lines[i]); } foreach (Match m in mc) { if (rx.IsMatch(m.Value)) { string format = m.Value.Substring(1, m.Value.Length - 2); if (!trsMap.ContainWorld(format)) { trsMap.AddWorld(format); } } } } return(trsMap); }