CsvToLua.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.IO;
  5. using UnityEditor;
  6. using System.Text;
  7. using System;
  8. using Game.Config;
  9. using RO.Editor;
  10. using LuaInterface;
  11. using System.Linq;
  12. using System.Text.RegularExpressions;
  13. public class CfgLanguageCfg : GameData<CfgLanguageCfg>
  14. {
  15. public string CfgName;
  16. public string Field;
  17. public string CfgID;
  18. public int CfgType;
  19. public int Enable;
  20. public CfgLanguageCfg()
  21. {
  22. CfgName = "";
  23. Field = "";
  24. CfgID = "";
  25. CfgType = 0;
  26. Enable = 0;
  27. }
  28. public static void OnCsvLoad(CsvReader csvReader)
  29. {
  30. CfgLanguageCfg.Onload(csvReader);
  31. }
  32. public static string FileName_S()
  33. {
  34. return "";
  35. }
  36. }
  37. public class LanguageCfg : GameData<LanguageCfg>
  38. {
  39. public string key;
  40. public string Language;
  41. public LanguageCfg()
  42. {
  43. key = "";
  44. Language = "";
  45. }
  46. public static void OnCsvLoad(CsvReader csvReader)
  47. {
  48. LanguageCfg.Onload(csvReader);
  49. }
  50. public static string FileName_S()
  51. {
  52. return "";
  53. }
  54. }
  55. public class CsvToLua : EditorWindow
  56. {
  57. public static string CSV_PATH = "csv path";
  58. public static string LUA_PATH = "lua path";
  59. public static string START_LINE = "start line";
  60. public string tableDirectoryName;
  61. public string luaDirectoryName;
  62. public int startDataLine = 1;
  63. public static bool IsObj;
  64. [MenuItem("Tools/CsvToLua")]
  65. static void Init()
  66. {
  67. CsvToLua window = (CsvToLua)GetWindow(typeof(CsvToLua));
  68. window.Show();
  69. }
  70. void OnEnable()
  71. {
  72. tableDirectoryName = EditorPrefs.GetString(CSV_PATH);
  73. luaDirectoryName = EditorPrefs.GetString(LUA_PATH);
  74. startDataLine = EditorPrefs.GetInt(START_LINE);
  75. }
  76. void OnDisable()
  77. {
  78. EditorPrefs.SetString(CSV_PATH, tableDirectoryName);
  79. EditorPrefs.SetString(LUA_PATH, luaDirectoryName);
  80. EditorPrefs.SetInt(START_LINE, startDataLine);
  81. }
  82. private void OnGUI()
  83. {
  84. GUILayout.Label("Base Settings", EditorStyles.boldLabel);
  85. EditorGUILayout.BeginHorizontal();
  86. tableDirectoryName = EditorGUILayout.TextField("TableDirectory Name", tableDirectoryName);
  87. if (GUILayout.Button("选择csv路径", GUILayout.Width(200)))
  88. {
  89. tableDirectoryName = GetFilePath();
  90. }
  91. EditorGUILayout.EndHorizontal();
  92. EditorGUILayout.BeginHorizontal();
  93. luaDirectoryName = EditorGUILayout.TextField("LuaDirectory Name", luaDirectoryName);
  94. if (GUILayout.Button("选择到处table路径", GUILayout.Width(200)))
  95. {
  96. luaDirectoryName = GetFilePath();
  97. }
  98. EditorGUILayout.EndHorizontal();
  99. startDataLine = EditorGUILayout.IntField("StartDataLine", startDataLine);
  100. if (GUILayout.Button("CsvToLua"))
  101. Change();
  102. if (GUILayout.Button("测试"))
  103. {
  104. string lua = @"local aaa =
  105. {
  106. [1] =
  107. {
  108. ['a'] = 1,
  109. ['b'] = '2',
  110. ['c'] = 'asd' ,
  111. ['d'] = {1,2,3,{{1,2},{3,4},{1.2,0},{0}}},
  112. ['aId'] = 1,
  113. } ,
  114. }
  115. return aaa";
  116. using (LuaState runTime = new LuaState())
  117. {
  118. runTime.Start();
  119. //LuaState runTime = LuaClient.Instance.luaState;
  120. runTime.DoFile("Assets\\Editor\\CsvToLua\\table-save.lua");
  121. LuaTable luaTable = runTime.DoString<LuaTable>(lua);
  122. RolePreviewWindow.SaveToLua(runTime, "aaa.lua", luaTable, "AAA","");
  123. }
  124. }
  125. if (GUILayout.Button("检查"))
  126. {
  127. CheckCgf();
  128. }
  129. IsObj = GUILayout.Toggle(IsObj,"运行时启动");
  130. if (GUILayout.Button("更改CardCfg"))
  131. {
  132. ChangeLuaCfg("Assets/Lua/Config/CardCfg.lua", "Assets\\Editor\\CsvToLua\\LuaCfg.lua", "Build/NewCfg/CardCfg.lua");
  133. }
  134. if (GUILayout.Button("合并Language"))
  135. {
  136. MergeLanauage("Assets/Content/Config/LanguagePackage_cn.csv", "Build/NewCfg/ROLanguagePackage_cn.csv", "Build/NewCfg/Language_merge.csv");
  137. }
  138. }
  139. public static string GetFilePath()
  140. {
  141. OpenDialogDir ofn2 = new OpenDialogDir();
  142. ofn2.pszDisplayName = new string(new char[2000]); ; // 存放目录路径缓冲区
  143. ofn2.lpszTitle = "Open Project";// 标题
  144. //ofn2.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; // 新的样式,带编辑框
  145. IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(ofn2);
  146. char[] charArray = new char[2000];
  147. for (int i = 0; i < 2000; i++)
  148. charArray[i] = '\0';
  149. DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray);
  150. string fullDirPath = new String(charArray);
  151. fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0'));
  152. return fullDirPath;
  153. }
  154. public void Change()
  155. {
  156. Debug.Log(tableDirectoryName);
  157. foreach (var item in Directory.GetFiles(tableDirectoryName))
  158. {
  159. if (item.Contains(".meta"))
  160. continue;
  161. CreatLuaTable(item);
  162. }
  163. }
  164. void CreatLuaTable(string filePath)
  165. {
  166. CreatDirectory();
  167. Save(GetSavePath(filePath), GetSaveContext(filePath));
  168. }
  169. void CreatDirectory()
  170. {
  171. string path = luaDirectoryName;
  172. if (!Directory.Exists(path))
  173. {
  174. Directory.CreateDirectory(path);
  175. AssetDatabase.Refresh();
  176. }
  177. }
  178. string GetSavePath(string filePath)
  179. {
  180. string fileName = GetFileName(filePath);
  181. return luaDirectoryName + "/" + fileName + ".lua";
  182. }
  183. string GetFileName(string filePath)
  184. {
  185. string targetPath = filePath.Replace(@"\", "/");
  186. string[] strs = targetPath.Split('/');
  187. targetPath = strs[strs.Length - 1];
  188. strs = targetPath.Split('.');
  189. string fileName = strs[0];
  190. return fileName;
  191. }
  192. string GetSaveContext(string filePath)
  193. {
  194. string fileName = GetFileName(filePath);
  195. List<string> context = GetContext(filePath);
  196. string[] propertyName = GetPropertyName(context[1]);
  197. string[] typeName = GetPropertyName(context[2]);
  198. StringBuilder sb = new StringBuilder();
  199. sb.Append("local " + fileName + " = {" + "\n");
  200. for (int i = startDataLine; i < context.Count; i++)
  201. {
  202. context[i] = context[i].Replace(" ", "");
  203. string[] details = context[i].Split(',');
  204. sb.Append("[" + details[0] + "]={" + "\n");
  205. for (int j = 0; j < propertyName.Length; j++)
  206. {
  207. sb.Append("['" + propertyName[j] + "']=");
  208. if (typeName[j].Equals("string"))
  209. sb.Append("'" + details[j] + "'," + "\n");
  210. else if (typeName[j].Equals("bool"))
  211. {
  212. sb.Append(details[j].ToLower() + "," + "\n");
  213. }
  214. else if (typeName[j].Equals("list"))
  215. {
  216. if (details[j].IndexOf(';') > 0)
  217. {
  218. ParseTable(sb, details[j], ';');
  219. }
  220. else if (details[j].IndexOf(':') > 0 && details[j].IndexOf(';') < 0)
  221. {
  222. sb.Append("{");
  223. ParseTable(sb, details[j], ':');
  224. sb.Append("}");
  225. }
  226. else
  227. {
  228. sb.Append("{");
  229. try
  230. {
  231. if (details[j].IndexOf('.') > 0)
  232. {
  233. Convert.ToDouble(details[j]);
  234. }
  235. else
  236. {
  237. Convert.ToInt32(details[j]);
  238. }
  239. sb.Append(details[j]);
  240. }
  241. catch
  242. {
  243. if (!string.IsNullOrEmpty(details[j]))
  244. sb.Append("'" + details[j] + "'");
  245. }
  246. sb.Append("}");
  247. }
  248. sb.Append(",\n");
  249. }
  250. else if (typeName[j].Equals("enum"))
  251. {
  252. sb.Append("Enum." + propertyName[j] + "." + details[j] + "," + "\n");
  253. }
  254. else
  255. {
  256. string num = "0";
  257. if (details[j] != "")
  258. {
  259. num = details[j];
  260. }
  261. sb.Append(num + "," + "\n");
  262. }
  263. }
  264. sb.Append("}," + "\n");
  265. }
  266. sb.Append("}" + "\n");
  267. sb.Append("return " + fileName);
  268. return sb.ToString();
  269. }
  270. void ParseTable(StringBuilder sb, string content, char split)
  271. {
  272. string[] strs = content.Split(split);
  273. sb.Append("{");
  274. for (int m = 0; m < strs.Length; ++m)
  275. {
  276. try
  277. {
  278. if (strs[m].IndexOf(':') > 0)
  279. {
  280. ParseTable(sb, strs[m], ':');
  281. }
  282. else
  283. {
  284. if (strs[m].IndexOf('.') > 0)
  285. {
  286. Convert.ToDouble(strs[m]);
  287. }
  288. else
  289. {
  290. Convert.ToInt32(strs[m]);
  291. }
  292. sb.Append(strs[m]);
  293. }
  294. }
  295. catch
  296. {
  297. if (!string.IsNullOrEmpty(strs[m]))
  298. sb.Append("'" + strs[m] + "'");
  299. }
  300. if (m < strs.Length - 1)
  301. {
  302. sb.Append(",");
  303. }
  304. }
  305. sb.Append("}");
  306. }
  307. List<string> GetContext(string filePath)
  308. {
  309. StreamReader sr = new StreamReader(filePath);
  310. List<string> contexts = new List<string>();
  311. string line;
  312. while ((line = sr.ReadLine()) != null)
  313. contexts.Add(line);
  314. return contexts;
  315. }
  316. string[] GetPropertyName(string line)
  317. {
  318. string[] names = line.Split(',');
  319. return names;
  320. }
  321. void Save(string path, string information)
  322. {
  323. if (File.Exists(path))
  324. File.Delete(path);
  325. FileStream aFile = new FileStream(@"" + path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
  326. StreamWriter sw = new StreamWriter(aFile);
  327. sw.Write(information);
  328. sw.Close();
  329. sw.Dispose();
  330. aFile.Close();
  331. aFile.Dispose();
  332. sw = null;
  333. aFile = null;
  334. AssetDatabase.Refresh();
  335. }
  336. public static Dictionary<string, List<CfgLanguageCfg>> GetCfgLanguageCfg(string path)
  337. {
  338. Dictionary<string, List<CfgLanguageCfg>> ret = new Dictionary<string, List<CfgLanguageCfg>>();
  339. TextAsset ta = AssetDatabase.LoadAssetAtPath<TextAsset>(path);
  340. CsvReader csvReader = new CsvReader(CfgLanguageCfg.FileName_S(), ta.bytes);
  341. CfgLanguageCfg.OnCsvLoad(csvReader);
  342. CfgLanguageCfg.Foreach(it =>
  343. {
  344. if (it.Enable == 0)
  345. {
  346. return;
  347. }
  348. if (ret.ContainsKey(it.CfgName))
  349. {
  350. ret[it.CfgName].Add(it);
  351. }
  352. else
  353. {
  354. List<CfgLanguageCfg> cfgs = new List<CfgLanguageCfg>();
  355. cfgs.Add(it);
  356. ret.Add(it.CfgName,cfgs);
  357. }
  358. //Debug.Log(it.BaseName);
  359. });
  360. CfgLanguageCfg.Clear();
  361. return ret;
  362. }
  363. public static Dictionary<string, LanguageCfg> GetLanguageCfg(string path)
  364. {
  365. Dictionary<string, LanguageCfg> ret = new Dictionary<string, LanguageCfg>();
  366. TextAsset ta = AssetDatabase.LoadAssetAtPath<TextAsset>(path);
  367. CsvReader csvReader = new CsvReader(LanguageCfg.FileName_S(), ta.bytes,1,2,3);
  368. LanguageCfg.OnCsvLoad(csvReader);
  369. LanguageCfg.Foreach(it =>
  370. {
  371. if (!ret.ContainsKey(it.key))
  372. {
  373. ret.Add(it.key, it);
  374. }
  375. else
  376. {
  377. ret.Add(it.key+ret.Count,it);
  378. Debug.Log("重复项:" + it.key);
  379. }
  380. //Debug.Log(it.BaseName);
  381. });
  382. LanguageCfg.Clear(false);
  383. return ret;
  384. }
  385. public static void CheckCgf()
  386. {
  387. string luaPath = "Assets/Lua/Config/";
  388. string csvPath = "Assets/Content/Config/";
  389. string OutPutPath = "Build/NewCfg/";
  390. Dictionary<string, List<CfgLanguageCfg>> cfgs = GetCfgLanguageCfg("Assets/Editor/CsvToLua/CfgLanguageCfg.csv");
  391. Dictionary<string, LanguageCfg> language = GetLanguageCfg("Assets/Content/Config/LanguagePackage_cn.csv");
  392. float ckcount = 0;
  393. foreach (var item in cfgs)
  394. {
  395. ckcount+=1;
  396. List<CfgLanguageCfg> value = item.Value;
  397. EditorUtility.DisplayProgressBar("检测配置中", $"检测:{item.Key}...", ckcount/cfgs.Count);
  398. string cfgPath = "";
  399. if (value[0].CfgType == 1)
  400. {
  401. cfgPath = luaPath + item.Key + ".lua";
  402. CheckLauCfg_CS(value,cfgPath,language, $"{OutPutPath}lua/{value[0].CfgName}.lua");
  403. }
  404. else
  405. {
  406. cfgPath = csvPath + item.Key + ".csv";
  407. CheckCsvCfg(value, cfgPath, language, $"{OutPutPath}csv/{value[0].CfgName}.csv");
  408. }
  409. }
  410. EditorUtility.ClearProgressBar();
  411. CsvWriter<LanguageCfg> csvWriter = new CsvWriter<LanguageCfg>(OutPutPath+ "Language.csv", "Language.csv",language.Values.ToList(), LanguageCfg.GetFormatInfo());
  412. csvWriter.Write();
  413. }
  414. private static void CheckLauCfg(List<CfgLanguageCfg> cfg,string path, Dictionary<string, LanguageCfg> language,string outputPath)
  415. {
  416. using (LuaState runTime = new LuaState())
  417. {
  418. runTime.Start();
  419. RolePreviewWindow.LuaForEach<int, LuaTable>(runTime, path, (id,luatable) =>
  420. {
  421. for (int i = 0; i < cfg.Count; i++)
  422. {
  423. if (cfg[i].Enable == 0)
  424. continue;
  425. string value = luatable.RawGet<string, string>(cfg[i].Field);
  426. if (string.IsNullOrEmpty(value))
  427. {
  428. continue;
  429. }
  430. KeyValuePair<string,LanguageCfg> valuePair = language.FirstOrDefault(it =>
  431. {
  432. return string.Equals(it.Value.Language, value);
  433. });
  434. if (!string.IsNullOrEmpty(valuePair.Key))
  435. {
  436. luatable.RawSet<string, string>(cfg[i].Field, valuePair.Key);
  437. }
  438. else
  439. {
  440. string key = cfg[i].CfgID + id;
  441. luatable.RawSet<string, string>(cfg[i].Field, key);
  442. if (value.Contains("\n"))
  443. {
  444. Debug.Log(value);
  445. value = value.Replace("\n","\\n");
  446. Debug.Log(value);
  447. }
  448. language.Add(key,new LanguageCfg() { key = key,Language = value});
  449. }
  450. }
  451. },(ltab)=>
  452. {
  453. bool useObj = IsObj;
  454. if (useObj)
  455. {
  456. LuaState luaState = LuaClient.Instance.luaState;
  457. luaState.DoFile("Assets\\Editor\\CsvToLua\\table-save.lua");
  458. RolePreviewWindow.SaveToLua(luaState, outputPath, ltab, cfg[0].CfgName, "1");
  459. }
  460. else
  461. {
  462. LuaState luaState = runTime;
  463. luaState.DoFile("Assets\\Editor\\CsvToLua\\table-save.lua");
  464. RolePreviewWindow.SaveToLua(luaState, outputPath, ltab, cfg[0].CfgName, "");
  465. }
  466. });
  467. }
  468. }
  469. private static void SetLuaLine(string[] rowDatas,int id,string key,string data,string dataF = "'{0}',")
  470. {
  471. string idkey = $"[{id}]";
  472. string keykey = $"'{key}'";
  473. string wdata = string.Format(dataF,data);//$"'{data}',";
  474. bool isFind = false;
  475. for (int line = 0; line < rowDatas.Length; line++)
  476. {
  477. if (rowDatas[line].Trim().IndexOf("--") == 0)
  478. {
  479. Debug.Log("注释跳过");
  480. }
  481. if (rowDatas[line].Contains(idkey))
  482. {
  483. isFind = true;
  484. }
  485. if (isFind && rowDatas[line].Contains(keykey))
  486. {
  487. int s = rowDatas[line].IndexOf('[');
  488. string p = "";
  489. if (s > 0)
  490. {
  491. for (int i = 0; i < s; i++)
  492. {
  493. p += " ";
  494. }
  495. }
  496. string newstr = $"{p}[{keykey}]={wdata}" ;
  497. rowDatas[line] = newstr;
  498. break;
  499. }
  500. }
  501. }
  502. private static void CheckLauCfg_CS(List<CfgLanguageCfg> cfg, string path, Dictionary<string, LanguageCfg> language, string outputPath)
  503. {
  504. string[] rowDatas = File.ReadAllLines(path);
  505. bool iswrite = true;
  506. using (LuaState runTime = new LuaState())
  507. {
  508. runTime.Start();
  509. RolePreviewWindow.LuaForEach<int, LuaTable>(runTime, path, (id, luatable) =>
  510. {
  511. for (int i = 0; i < cfg.Count; i++)
  512. {
  513. if (cfg[i].Enable == 0)
  514. {
  515. iswrite = false;
  516. continue;
  517. }
  518. string value = luatable.RawGet<string, string>(cfg[i].Field);
  519. if (string.IsNullOrEmpty(value))
  520. {
  521. continue;
  522. }
  523. KeyValuePair<string, LanguageCfg> valuePair = language.FirstOrDefault(it =>
  524. {
  525. return string.Equals(it.Value.Language, value);
  526. });
  527. if (!string.IsNullOrEmpty(valuePair.Key))
  528. {
  529. luatable.RawSet<string, string>(cfg[i].Field, valuePair.Key);
  530. SetLuaLine(rowDatas,id, cfg[i].Field, valuePair.Key);
  531. }
  532. else
  533. {
  534. string key = cfg[i].CfgID + id;
  535. luatable.RawSet<string, string>(cfg[i].Field, key);
  536. if (value.Contains("\n"))
  537. {
  538. //Debug.Log(value);
  539. value = value.Replace("\n", "\\n");
  540. //Debug.Log(value);
  541. }
  542. if (!language.ContainsKey(key))
  543. {
  544. valuePair = language.FirstOrDefault(it =>
  545. {
  546. return string.Equals(it.Value.key, value);
  547. });
  548. if (string.IsNullOrEmpty(valuePair.Key))
  549. {
  550. SetLuaLine(rowDatas, id, cfg[i].Field, key);
  551. language.Add(key, new LanguageCfg() { key = key, Language = value });
  552. }
  553. }
  554. }
  555. }
  556. });
  557. }
  558. if (iswrite)
  559. File.WriteAllLines(outputPath,rowDatas);
  560. }
  561. private static void CheckCsvCfg(List<CfgLanguageCfg> cfg, string path, Dictionary<string, LanguageCfg> language, string outputPath)
  562. {
  563. CsvReader csvReader = new CsvReader(path,1,2,3);
  564. string[][] datas = csvReader.RowDatas;
  565. for (int i = csvReader.StartLine; i < datas.Length; i++)
  566. {
  567. string[] curLine = datas[i];
  568. for (int j = 0; j < cfg.Count; j++)
  569. {
  570. if (cfg[j].Enable == 0)
  571. continue;
  572. string value = csvReader.GetDataByFieldName(cfg[j].Field,i);
  573. if (string.IsNullOrEmpty(value))
  574. {
  575. continue;
  576. }
  577. KeyValuePair<string, LanguageCfg> valuePair = language.FirstOrDefault(it =>
  578. {
  579. return string.Equals(it.Value.Language, value);
  580. });
  581. if (!string.IsNullOrEmpty(valuePair.Key))
  582. {
  583. csvReader.SetDataByFieldName(cfg[j].Field, valuePair.Key, i);
  584. }
  585. else
  586. {
  587. string key = cfg[j].CfgID + i;
  588. csvReader.SetDataByFieldName(cfg[j].Field, key,i);
  589. language.Add(key, new LanguageCfg() { key = key, Language = value });
  590. }
  591. }
  592. }
  593. FileHelper.WirteStringToFile(outputPath,csvReader.GetString());
  594. }
  595. private static void ChangeLuaCfg(string luacfgpath,string luachagepath,string outputPath)
  596. {
  597. string[] rowDatas = File.ReadAllLines(luacfgpath);
  598. using (LuaState runTime = new LuaState())
  599. {
  600. runTime.Start();
  601. LuaTable luaTable = runTime.DoFile<LuaTable>(luachagepath);
  602. RolePreviewWindow.LuaForEach<int, LuaTable>(runTime, luacfgpath, (id, luatable) =>
  603. {
  604. LuaFunction luaFunction = luaTable.GetLuaFunction("IsChangefg");
  605. bool ischange = luaFunction.Invoke<LuaTable,LuaTable, bool>(luaTable,luatable);
  606. if (ischange)
  607. {
  608. LuaTable fieldValue = luaTable.Invoke<LuaTable,LuaTable>("GetFieldAddValue", luaTable);
  609. string field = fieldValue.RawGet<string, string>("field");
  610. string value = fieldValue.RawGet<string, string>("value");
  611. SetLuaLine(rowDatas,id,field,value.ToString(),"{0},");
  612. }
  613. });
  614. }
  615. File.WriteAllLines(outputPath, rowDatas);
  616. }
  617. struct lgInfo
  618. {
  619. public int index;
  620. public int off;
  621. }
  622. private static void MergeLanauage(string oldPath,string newPath, string outputPath)
  623. {
  624. List<string> oldLg = File.ReadAllLines(oldPath).ToList();
  625. List<string> newLg = File.ReadAllLines(newPath).ToList();
  626. Dictionary<string, lgInfo> cfgmap = new Dictionary<string, lgInfo>();
  627. int length = oldLg.Count;
  628. int off = -1;
  629. for (int i = 0; i < length; i++)
  630. {
  631. off = oldLg[i].IndexOf(',');
  632. if (off < 0)
  633. {
  634. continue;
  635. }
  636. string key = oldLg[i].Substring(0,off);
  637. if (!cfgmap.ContainsKey(key))
  638. {
  639. lgInfo info = new lgInfo();
  640. info.index = i;
  641. info.off = off;
  642. cfgmap.Add(key, info);
  643. }
  644. }
  645. foreach (var item in newLg)
  646. {
  647. if (item == "" || item == ","||item == "key"||item == "string")
  648. continue;
  649. off = item.IndexOf(',');
  650. if (off < 0)
  651. {
  652. continue;
  653. }
  654. string key = item.Substring(0,off);
  655. if (!cfgmap.ContainsKey(key))
  656. {
  657. Debug.Log($"不包含:{key} off = {off}");
  658. oldLg.Add(item);
  659. }
  660. else
  661. {
  662. lgInfo lgIf = cfgmap[key];
  663. oldLg[lgIf.index] = item;
  664. }
  665. }
  666. string data = FileHelper.CatStringArray(oldLg,"\r\n");
  667. FileHelper.WirteStringToFile(outputPath, data);
  668. }
  669. }