CsvToLua.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  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. MergeLanauage("Build/NewCfg/Language.csv", "Assets/Content/Config/LanguagePackage_cn.csv", "Build/NewCfg/Language_merge_cn.csv");
  138. }
  139. }
  140. public static string GetFilePath()
  141. {
  142. OpenDialogDir ofn2 = new OpenDialogDir();
  143. ofn2.pszDisplayName = new string(new char[2000]); ; // 存放目录路径缓冲区
  144. ofn2.lpszTitle = "Open Project";// 标题
  145. //ofn2.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; // 新的样式,带编辑框
  146. IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(ofn2);
  147. char[] charArray = new char[2000];
  148. for (int i = 0; i < 2000; i++)
  149. charArray[i] = '\0';
  150. DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray);
  151. string fullDirPath = new String(charArray);
  152. fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0'));
  153. return fullDirPath;
  154. }
  155. public void Change()
  156. {
  157. Debug.Log(tableDirectoryName);
  158. foreach (var item in Directory.GetFiles(tableDirectoryName))
  159. {
  160. if (item.Contains(".meta"))
  161. continue;
  162. CreatLuaTable(item);
  163. }
  164. }
  165. void CreatLuaTable(string filePath)
  166. {
  167. CreatDirectory();
  168. Save(GetSavePath(filePath), GetSaveContext(filePath));
  169. }
  170. void CreatDirectory()
  171. {
  172. string path = luaDirectoryName;
  173. if (!Directory.Exists(path))
  174. {
  175. Directory.CreateDirectory(path);
  176. AssetDatabase.Refresh();
  177. }
  178. }
  179. string GetSavePath(string filePath)
  180. {
  181. string fileName = GetFileName(filePath);
  182. return luaDirectoryName + "/" + fileName + ".lua";
  183. }
  184. string GetFileName(string filePath)
  185. {
  186. string targetPath = filePath.Replace(@"\", "/");
  187. string[] strs = targetPath.Split('/');
  188. targetPath = strs[strs.Length - 1];
  189. strs = targetPath.Split('.');
  190. string fileName = strs[0];
  191. return fileName;
  192. }
  193. string GetSaveContext(string filePath)
  194. {
  195. string fileName = GetFileName(filePath);
  196. List<string> context = GetContext(filePath);
  197. string[] propertyName = GetPropertyName(context[1]);
  198. string[] typeName = GetPropertyName(context[2]);
  199. StringBuilder sb = new StringBuilder();
  200. sb.Append("local " + fileName + " = {" + "\n");
  201. for (int i = startDataLine; i < context.Count; i++)
  202. {
  203. context[i] = context[i].Replace(" ", "");
  204. string[] details = context[i].Split(',');
  205. sb.Append("[" + details[0] + "]={" + "\n");
  206. for (int j = 0; j < propertyName.Length; j++)
  207. {
  208. sb.Append("['" + propertyName[j] + "']=");
  209. if (typeName[j].Equals("string"))
  210. sb.Append("'" + details[j] + "'," + "\n");
  211. else if (typeName[j].Equals("bool"))
  212. {
  213. sb.Append(details[j].ToLower() + "," + "\n");
  214. }
  215. else if (typeName[j].Equals("list"))
  216. {
  217. if (details[j].IndexOf(';') > 0)
  218. {
  219. ParseTable(sb, details[j], ';');
  220. }
  221. else if (details[j].IndexOf(':') > 0 && details[j].IndexOf(';') < 0)
  222. {
  223. sb.Append("{");
  224. ParseTable(sb, details[j], ':');
  225. sb.Append("}");
  226. }
  227. else
  228. {
  229. sb.Append("{");
  230. try
  231. {
  232. if (details[j].IndexOf('.') > 0)
  233. {
  234. Convert.ToDouble(details[j]);
  235. }
  236. else
  237. {
  238. Convert.ToInt32(details[j]);
  239. }
  240. sb.Append(details[j]);
  241. }
  242. catch
  243. {
  244. if (!string.IsNullOrEmpty(details[j]))
  245. sb.Append("'" + details[j] + "'");
  246. }
  247. sb.Append("}");
  248. }
  249. sb.Append(",\n");
  250. }
  251. else if (typeName[j].Equals("enum"))
  252. {
  253. sb.Append("Enum." + propertyName[j] + "." + details[j] + "," + "\n");
  254. }
  255. else
  256. {
  257. string num = "0";
  258. if (details[j] != "")
  259. {
  260. num = details[j];
  261. }
  262. sb.Append(num + "," + "\n");
  263. }
  264. }
  265. sb.Append("}," + "\n");
  266. }
  267. sb.Append("}" + "\n");
  268. sb.Append("return " + fileName);
  269. return sb.ToString();
  270. }
  271. void ParseTable(StringBuilder sb, string content, char split)
  272. {
  273. string[] strs = content.Split(split);
  274. sb.Append("{");
  275. for (int m = 0; m < strs.Length; ++m)
  276. {
  277. try
  278. {
  279. if (strs[m].IndexOf(':') > 0)
  280. {
  281. ParseTable(sb, strs[m], ':');
  282. }
  283. else
  284. {
  285. if (strs[m].IndexOf('.') > 0)
  286. {
  287. Convert.ToDouble(strs[m]);
  288. }
  289. else
  290. {
  291. Convert.ToInt32(strs[m]);
  292. }
  293. sb.Append(strs[m]);
  294. }
  295. }
  296. catch
  297. {
  298. if (!string.IsNullOrEmpty(strs[m]))
  299. sb.Append("'" + strs[m] + "'");
  300. }
  301. if (m < strs.Length - 1)
  302. {
  303. sb.Append(",");
  304. }
  305. }
  306. sb.Append("}");
  307. }
  308. List<string> GetContext(string filePath)
  309. {
  310. StreamReader sr = new StreamReader(filePath);
  311. List<string> contexts = new List<string>();
  312. string line;
  313. while ((line = sr.ReadLine()) != null)
  314. contexts.Add(line);
  315. return contexts;
  316. }
  317. string[] GetPropertyName(string line)
  318. {
  319. string[] names = line.Split(',');
  320. return names;
  321. }
  322. void Save(string path, string information)
  323. {
  324. if (File.Exists(path))
  325. File.Delete(path);
  326. FileStream aFile = new FileStream(@"" + path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
  327. StreamWriter sw = new StreamWriter(aFile);
  328. sw.Write(information);
  329. sw.Close();
  330. sw.Dispose();
  331. aFile.Close();
  332. aFile.Dispose();
  333. sw = null;
  334. aFile = null;
  335. AssetDatabase.Refresh();
  336. }
  337. public static Dictionary<string, List<CfgLanguageCfg>> GetCfgLanguageCfg(string path)
  338. {
  339. Dictionary<string, List<CfgLanguageCfg>> ret = new Dictionary<string, List<CfgLanguageCfg>>();
  340. TextAsset ta = AssetDatabase.LoadAssetAtPath<TextAsset>(path);
  341. CsvReader csvReader = new CsvReader(CfgLanguageCfg.FileName_S(), ta.bytes);
  342. CfgLanguageCfg.OnCsvLoad(csvReader);
  343. CfgLanguageCfg.Foreach(it =>
  344. {
  345. if (it.Enable == 0)
  346. {
  347. return;
  348. }
  349. if (ret.ContainsKey(it.CfgName))
  350. {
  351. ret[it.CfgName].Add(it);
  352. }
  353. else
  354. {
  355. List<CfgLanguageCfg> cfgs = new List<CfgLanguageCfg>();
  356. cfgs.Add(it);
  357. ret.Add(it.CfgName,cfgs);
  358. }
  359. //Debug.Log(it.BaseName);
  360. });
  361. CfgLanguageCfg.Clear();
  362. return ret;
  363. }
  364. public static Dictionary<string, LanguageCfg> GetLanguageCfg(string path)
  365. {
  366. Dictionary<string, LanguageCfg> ret = new Dictionary<string, LanguageCfg>();
  367. TextAsset ta = AssetDatabase.LoadAssetAtPath<TextAsset>(path);
  368. CsvReader csvReader = new CsvReader(LanguageCfg.FileName_S(), ta.bytes,1,2,3);
  369. LanguageCfg.OnCsvLoad(csvReader);
  370. LanguageCfg.Foreach(it =>
  371. {
  372. if (!ret.ContainsKey(it.key))
  373. {
  374. ret.Add(it.key, it);
  375. }
  376. else
  377. {
  378. ret.Add(it.key+ret.Count,it);
  379. Debug.Log("重复项:" + it.key);
  380. }
  381. //Debug.Log(it.BaseName);
  382. });
  383. LanguageCfg.Clear(false);
  384. return ret;
  385. }
  386. public static void CheckCgf()
  387. {
  388. string luaPath = "Assets/Lua/Config/";
  389. string csvPath = "Assets/Content/Config/";
  390. string OutPutPath = "Build/NewCfg/";
  391. Dictionary<string, List<CfgLanguageCfg>> cfgs = GetCfgLanguageCfg("Assets/Editor/CsvToLua/CfgLanguageCfg.csv");
  392. Dictionary<string, LanguageCfg> language = GetLanguageCfg("Assets/Content/Config/LanguagePackage_cn.csv");
  393. float ckcount = 0;
  394. foreach (var item in cfgs)
  395. {
  396. ckcount+=1;
  397. List<CfgLanguageCfg> value = item.Value;
  398. EditorUtility.DisplayProgressBar("检测配置中", $"检测:{item.Key}...", ckcount/cfgs.Count);
  399. string cfgPath = "";
  400. if (value[0].CfgType == 1)
  401. {
  402. cfgPath = luaPath + item.Key + ".lua";
  403. CheckLauCfg_CS(value,cfgPath,language, $"{OutPutPath}lua/{value[0].CfgName}.lua");
  404. }
  405. else
  406. {
  407. cfgPath = csvPath + item.Key + ".csv";
  408. CheckCsvCfg(value, cfgPath, language, $"{OutPutPath}csv/{value[0].CfgName}.csv");
  409. }
  410. }
  411. EditorUtility.ClearProgressBar();
  412. CsvWriter<LanguageCfg> csvWriter = new CsvWriter<LanguageCfg>(OutPutPath+ "Language.csv", "Language.csv",language.Values.ToList(), LanguageCfg.GetFormatInfo());
  413. csvWriter.Write();
  414. }
  415. private static void CheckLauCfg(List<CfgLanguageCfg> cfg,string path, Dictionary<string, LanguageCfg> language,string outputPath)
  416. {
  417. using (LuaState runTime = new LuaState())
  418. {
  419. runTime.Start();
  420. RolePreviewWindow.LuaForEach<int, LuaTable>(runTime, path, (id,luatable) =>
  421. {
  422. for (int i = 0; i < cfg.Count; i++)
  423. {
  424. if (cfg[i].Enable == 0)
  425. continue;
  426. string value = luatable.RawGet<string, string>(cfg[i].Field);
  427. if (string.IsNullOrEmpty(value))
  428. {
  429. continue;
  430. }
  431. KeyValuePair<string,LanguageCfg> valuePair = language.FirstOrDefault(it =>
  432. {
  433. return string.Equals(it.Value.Language, value);
  434. });
  435. if (!string.IsNullOrEmpty(valuePair.Key))
  436. {
  437. luatable.RawSet<string, string>(cfg[i].Field, valuePair.Key);
  438. }
  439. else
  440. {
  441. string key = cfg[i].CfgID + id;
  442. luatable.RawSet<string, string>(cfg[i].Field, key);
  443. if (value.Contains("\n"))
  444. {
  445. Debug.Log(value);
  446. value = value.Replace("\n","\\n");
  447. Debug.Log(value);
  448. }
  449. language.Add(key,new LanguageCfg() { key = key,Language = value});
  450. }
  451. }
  452. },(ltab)=>
  453. {
  454. bool useObj = IsObj;
  455. if (useObj)
  456. {
  457. LuaState luaState = LuaClient.Instance.luaState;
  458. luaState.DoFile("Assets\\Editor\\CsvToLua\\table-save.lua");
  459. RolePreviewWindow.SaveToLua(luaState, outputPath, ltab, cfg[0].CfgName, "1");
  460. }
  461. else
  462. {
  463. LuaState luaState = runTime;
  464. luaState.DoFile("Assets\\Editor\\CsvToLua\\table-save.lua");
  465. RolePreviewWindow.SaveToLua(luaState, outputPath, ltab, cfg[0].CfgName, "");
  466. }
  467. });
  468. }
  469. }
  470. private static void SetLuaLine(string[] rowDatas,int id,string key,string data,string dataF = "'{0}',")
  471. {
  472. string idkey = $"[{id}]";
  473. string keykey = $"'{key}'";
  474. string wdata = string.Format(dataF,data);//$"'{data}',";
  475. bool isFind = false;
  476. for (int line = 0; line < rowDatas.Length; line++)
  477. {
  478. if (rowDatas[line].Trim().IndexOf("--") == 0)
  479. {
  480. Debug.Log("注释跳过");
  481. }
  482. if (rowDatas[line].Contains(idkey))
  483. {
  484. isFind = true;
  485. }
  486. if (isFind && rowDatas[line].Contains(keykey))
  487. {
  488. int s = rowDatas[line].IndexOf('[');
  489. string p = "";
  490. if (s > 0)
  491. {
  492. for (int i = 0; i < s; i++)
  493. {
  494. p += " ";
  495. }
  496. }
  497. string newstr = $"{p}[{keykey}]={wdata}" ;
  498. rowDatas[line] = newstr;
  499. break;
  500. }
  501. }
  502. }
  503. private static void CheckLauCfg_CS(List<CfgLanguageCfg> cfg, string path, Dictionary<string, LanguageCfg> language, string outputPath)
  504. {
  505. string[] rowDatas = File.ReadAllLines(path);
  506. bool iswrite = true;
  507. using (LuaState runTime = new LuaState())
  508. {
  509. runTime.Start();
  510. RolePreviewWindow.LuaForEach<int, LuaTable>(runTime, path, (id, luatable) =>
  511. {
  512. for (int i = 0; i < cfg.Count; i++)
  513. {
  514. if (cfg[i].Enable == 0)
  515. {
  516. iswrite = false;
  517. continue;
  518. }
  519. string value = luatable.RawGet<string, string>(cfg[i].Field);
  520. if (string.IsNullOrEmpty(value))
  521. {
  522. continue;
  523. }
  524. KeyValuePair<string, LanguageCfg> valuePair = language.FirstOrDefault(it =>
  525. {
  526. return string.Equals(it.Value.Language, value);
  527. });
  528. if (!string.IsNullOrEmpty(valuePair.Key))
  529. {
  530. luatable.RawSet<string, string>(cfg[i].Field, valuePair.Key);
  531. SetLuaLine(rowDatas,id, cfg[i].Field, valuePair.Key);
  532. }
  533. else
  534. {
  535. string key = cfg[i].CfgID + id;
  536. luatable.RawSet<string, string>(cfg[i].Field, key);
  537. if (value.Contains("\n"))
  538. {
  539. //Debug.Log(value);
  540. value = value.Replace("\n", "\\n");
  541. //Debug.Log(value);
  542. }
  543. if (!language.ContainsKey(key))
  544. {
  545. valuePair = language.FirstOrDefault(it =>
  546. {
  547. return string.Equals(it.Value.key, value);
  548. });
  549. if (string.IsNullOrEmpty(valuePair.Key))
  550. {
  551. SetLuaLine(rowDatas, id, cfg[i].Field, key);
  552. language.Add(key, new LanguageCfg() { key = key, Language = value });
  553. }
  554. }
  555. }
  556. }
  557. });
  558. }
  559. if (iswrite)
  560. File.WriteAllLines(outputPath,rowDatas);
  561. }
  562. private static void CheckCsvCfg(List<CfgLanguageCfg> cfg, string path, Dictionary<string, LanguageCfg> language, string outputPath)
  563. {
  564. CsvReader csvReader = new CsvReader(path,1,2,3);
  565. string[][] datas = csvReader.RowDatas;
  566. for (int i = csvReader.StartLine; i < datas.Length; i++)
  567. {
  568. string[] curLine = datas[i];
  569. for (int j = 0; j < cfg.Count; j++)
  570. {
  571. if (cfg[j].Enable == 0)
  572. continue;
  573. string value = csvReader.GetDataByFieldName(cfg[j].Field,i);
  574. if (string.IsNullOrEmpty(value))
  575. {
  576. continue;
  577. }
  578. KeyValuePair<string, LanguageCfg> valuePair = language.FirstOrDefault(it =>
  579. {
  580. return string.Equals(it.Value.Language, value);
  581. });
  582. if (!string.IsNullOrEmpty(valuePair.Key))
  583. {
  584. csvReader.SetDataByFieldName(cfg[j].Field, valuePair.Key, i);
  585. }
  586. else
  587. {
  588. string key = cfg[j].CfgID + i;
  589. csvReader.SetDataByFieldName(cfg[j].Field, key,i);
  590. language.Add(key, new LanguageCfg() { key = key, Language = value });
  591. }
  592. }
  593. }
  594. FileHelper.WirteStringToFile(outputPath,csvReader.GetString());
  595. }
  596. private static void ChangeLuaCfg(string luacfgpath,string luachagepath,string outputPath)
  597. {
  598. string[] rowDatas = File.ReadAllLines(luacfgpath);
  599. using (LuaState runTime = new LuaState())
  600. {
  601. runTime.Start();
  602. LuaTable luaTable = runTime.DoFile<LuaTable>(luachagepath);
  603. RolePreviewWindow.LuaForEach<int, LuaTable>(runTime, luacfgpath, (id, luatable) =>
  604. {
  605. LuaFunction luaFunction = luaTable.GetLuaFunction("IsChangefg");
  606. bool ischange = luaFunction.Invoke<LuaTable,LuaTable, bool>(luaTable,luatable);
  607. if (ischange)
  608. {
  609. LuaTable fieldValue = luaTable.Invoke<LuaTable,LuaTable>("GetFieldAddValue", luaTable);
  610. string field = fieldValue.RawGet<string, string>("field");
  611. string value = fieldValue.RawGet<string, string>("value");
  612. SetLuaLine(rowDatas,id,field,value.ToString(),"{0},");
  613. }
  614. });
  615. }
  616. File.WriteAllLines(outputPath, rowDatas);
  617. }
  618. struct lgInfo
  619. {
  620. public int index;
  621. public int off;
  622. }
  623. private static void MergeLanauage(string oldPath,string newPath, string outputPath)
  624. {
  625. List<string> oldLg = File.ReadAllLines(oldPath).ToList();
  626. List<string> newLg = File.ReadAllLines(newPath).ToList();
  627. Dictionary<string, lgInfo> cfgmap = new Dictionary<string, lgInfo>();
  628. int length = oldLg.Count;
  629. int off = -1;
  630. for (int i = 0; i < length; i++)
  631. {
  632. off = oldLg[i].IndexOf(',');
  633. if (off < 0)
  634. {
  635. continue;
  636. }
  637. string key = oldLg[i].Substring(0,off);
  638. if (!cfgmap.ContainsKey(key))
  639. {
  640. lgInfo info = new lgInfo();
  641. info.index = i;
  642. info.off = off;
  643. cfgmap.Add(key, info);
  644. }
  645. }
  646. foreach (var item in newLg)
  647. {
  648. if (item == "" || item == ","||item == "key"||item == "string")
  649. continue;
  650. off = item.IndexOf(',');
  651. if (off < 0)
  652. {
  653. continue;
  654. }
  655. string key = item.Substring(0,off);
  656. if (!cfgmap.ContainsKey(key))
  657. {
  658. Debug.Log($"不包含:{key} off = {off}");
  659. oldLg.Add(item);
  660. }
  661. else
  662. {
  663. lgInfo lgIf = cfgmap[key];
  664. oldLg[lgIf.index] = item;
  665. }
  666. }
  667. string data = FileHelper.CatStringArray(oldLg,"\r\n");
  668. FileHelper.WirteStringToFile(outputPath, data);
  669. Debug.Log("合并完成");
  670. }
  671. }