| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.IO;
- using UnityEditor;
- using System.Text;
- using System;
- using Game.Config;
- using RO.Editor;
- using LuaInterface;
- using System.Linq;
- using System.Text.RegularExpressions;
- public class CfgLanguageCfg : GameData<CfgLanguageCfg>
- {
- public string CfgName;
- public string Field;
- public string CfgID;
- public int CfgType;
- public int Enable;
- public string AssetPath;
- public string AssetName;
- public CfgLanguageCfg()
- {
- CfgName = "";
- Field = "";
- CfgID = "";
- CfgType = 0;
- Enable = 0;
- AssetPath = "";
- AssetName = "";
- }
- public static void OnCsvLoad(CsvReader csvReader)
- {
- CfgLanguageCfg.Onload(csvReader);
- }
- public static string FileName_S()
- {
- return "";
- }
- }
- public class LanguageCfg : GameData<LanguageCfg>
- {
- public string key;
- public string Language;
-
- public LanguageCfg()
- {
- key = "";
- Language = "";
- }
- public static void OnCsvLoad(CsvReader csvReader)
- {
- LanguageCfg.Onload(csvReader);
- }
- public static string FileName_S()
- {
- return "";
- }
- }
- public class LocalizedTextureCfg :GameData<LocalizedTextureCfg>
- {
- public string key;
- public string Language;
- public string AssetPath;
- public string OtherSetting;
- public string SetNativeSize;
- public LocalizedTextureCfg()
- {
- key = "";
- Language = "";
- AssetPath = "";
- OtherSetting = "";
- SetNativeSize = "0";
- }
- public static void OnCsvLoad(CsvReader csvReader)
- {
- Onload(csvReader);
- }
- public static string FileName_S()
- {
- return "";
- }
- }
- public class CsvToLua : EditorWindow
- {
- public static string CSV_PATH = "csv path";
- public static string LUA_PATH = "lua path";
- public static string START_LINE = "start line";
- public string tableDirectoryName;
- public string luaDirectoryName;
- public int startDataLine = 1;
- public static bool IsObj;
- [MenuItem("Tools/CsvToLua")]
- static void Init()
- {
- CsvToLua window = (CsvToLua)GetWindow(typeof(CsvToLua));
- window.Show();
- }
- void OnEnable()
- {
- tableDirectoryName = EditorPrefs.GetString(CSV_PATH);
- luaDirectoryName = EditorPrefs.GetString(LUA_PATH);
- startDataLine = EditorPrefs.GetInt(START_LINE);
- }
- void OnDisable()
- {
- EditorPrefs.SetString(CSV_PATH, tableDirectoryName);
- EditorPrefs.SetString(LUA_PATH, luaDirectoryName);
- EditorPrefs.SetInt(START_LINE, startDataLine);
- }
- private void OnGUI()
- {
- GUILayout.Label("Base Settings", EditorStyles.boldLabel);
- EditorGUILayout.BeginHorizontal();
- tableDirectoryName = EditorGUILayout.TextField("TableDirectory Name", tableDirectoryName);
- if (GUILayout.Button("选择csv路径", GUILayout.Width(200)))
- {
- tableDirectoryName = GetFilePath();
- }
- EditorGUILayout.EndHorizontal();
- EditorGUILayout.BeginHorizontal();
- luaDirectoryName = EditorGUILayout.TextField("LuaDirectory Name", luaDirectoryName);
- if (GUILayout.Button("选择到处table路径", GUILayout.Width(200)))
- {
- luaDirectoryName = GetFilePath();
- }
- EditorGUILayout.EndHorizontal();
- startDataLine = EditorGUILayout.IntField("StartDataLine", startDataLine);
- if (GUILayout.Button("CsvToLua"))
- Change();
- if (GUILayout.Button("测试"))
- {
- string lua = @"local aaa =
- {
- [1] =
- {
- ['a'] = 1,
- ['b'] = '2',
- ['c'] = 'asd' ,
- ['d'] = {1,2,3,{{1,2},{3,4},{1.2,0},{0}}},
- ['aId'] = 1,
- } ,
- }
- return aaa";
- using (LuaState runTime = new LuaState())
- {
- runTime.Start();
- //LuaState runTime = LuaClient.Instance.luaState;
- runTime.DoFile("Assets\\Editor\\CsvToLua\\table-save.lua");
- LuaTable luaTable = runTime.DoString<LuaTable>(lua);
- RolePreviewWindow.SaveToLua(runTime, "aaa.lua", luaTable, "AAA","");
- }
- }
- if (GUILayout.Button("提取语言配置"))
- {
- CheckCgf();
- }
- if (GUILayout.Button("提取图片配置"))
- {
- CheckTextureCgf();
- }
- IsObj = GUILayout.Toggle(IsObj,"运行时启动");
- if (GUILayout.Button("更改CardCfg"))
- {
- ChangeLuaCfg("Assets/Lua/Config/CardCfg.lua", "Assets\\Editor\\CsvToLua\\LuaCfg.lua", "Build/NewCfg/CardCfg.lua");
- }
- if (GUILayout.Button("合并Language"))
- {
- //MergeLanauage("Assets/Content/Config/LanguagePackage_cn.csv", "Build/NewCfg/ROLanguagePackage_cn.csv", "Build/NewCfg/Language_merge.csv");
- MergeLanauage("Assets/Content/Config/LanguagePackage_vi.csv", "D:/项目/其他/最新语言表/LanguagePackage_vi_e.csv", "Build/NewCfg/Language_merge_VI.csv");
- ///MergeLanauage("Build/NewCfg/Language.csv", "Assets/Content/Config/LanguagePackage_cn.csv", "Build/NewCfg/Language_merge_cn.csv");
- }
- if (GUILayout.Button("二进制转换"))
- {
- B2T("D:/项目/其他/Language15000-19000.csv", "D:/项目/其他/111.csv",Encoding.UTF8);
- }
- if (GUILayout.Button("复制luacfg文件"))
- {
- CopyFleByLuaCfg("Assets\\Editor\\CsvToLua\\luaCopyFileCfg.lua", "D:/项目/图/仙境/11/", "D:/项目/图/仙境/vi/", "_vi");
- }
- if (GUILayout.Button("检查luacfg文件"))
- {
- CopyFleByLuaCfg("Assets\\Editor\\CsvToLua\\luaCopyFileCfg.lua", "D:/项目/图/仙境/11/", "D:/项目/图/仙境/vi_1/", "_vi",true);
- }
- if (GUILayout.Button("复制luacfg文件缺少的图片"))
- {
- CopyFleByLuaCfg("Assets\\Editor\\CsvToLua\\luaCopyFileCfg.lua", "D:/项目/图/仙境/11/", "D:/项目/图/仙境/vi_1/", "_vi", true,true);
- }
- if (GUILayout.Button("添加图片配置"))
- {
- AddLocalizTextureCfgByFileCfg("Assets\\Editor\\CsvToLua\\luaCopyFileCfg.lua");
- }
- if (GUILayout.Button("复制图片到对应文件夹"))
- {
- CopycpfCfgFileToDir("Assets\\Editor\\CsvToLua\\luaCopyFileCfg.lua", "D:/项目/图/仙境/11/22/", "D:/项目/图/仙境/11/");
- }
- }
- public static string GetFilePath()
- {
- OpenDialogDir ofn2 = new OpenDialogDir();
- ofn2.pszDisplayName = new string(new char[2000]); ; // 存放目录路径缓冲区
- ofn2.lpszTitle = "Open Project";// 标题
- //ofn2.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; // 新的样式,带编辑框
- IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(ofn2);
- char[] charArray = new char[2000];
- for (int i = 0; i < 2000; i++)
- charArray[i] = '\0';
- DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray);
- string fullDirPath = new String(charArray);
- fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0'));
- return fullDirPath;
- }
- public void Change()
- {
- Debug.Log(tableDirectoryName);
- foreach (var item in Directory.GetFiles(tableDirectoryName))
- {
- if (item.Contains(".meta"))
- continue;
- CreatLuaTable(item);
- }
- }
- void CreatLuaTable(string filePath)
- {
- CreatDirectory();
- Save(GetSavePath(filePath), GetSaveContext(filePath));
- }
- void CreatDirectory()
- {
- string path = luaDirectoryName;
- if (!Directory.Exists(path))
- {
- Directory.CreateDirectory(path);
- AssetDatabase.Refresh();
- }
- }
- string GetSavePath(string filePath)
- {
- string fileName = GetFileName(filePath);
- return luaDirectoryName + "/" + fileName + ".lua";
- }
- string GetFileName(string filePath)
- {
- string targetPath = filePath.Replace(@"\", "/");
- string[] strs = targetPath.Split('/');
- targetPath = strs[strs.Length - 1];
- strs = targetPath.Split('.');
- string fileName = strs[0];
- return fileName;
- }
- string GetSaveContext(string filePath)
- {
- string fileName = GetFileName(filePath);
- List<string> context = GetContext(filePath);
- string[] propertyName = GetPropertyName(context[1]);
- string[] typeName = GetPropertyName(context[2]);
- StringBuilder sb = new StringBuilder();
- sb.Append("local " + fileName + " = {" + "\n");
- for (int i = startDataLine; i < context.Count; i++)
- {
- context[i] = context[i].Replace(" ", "");
- string[] details = context[i].Split(',');
- sb.Append("[" + details[0] + "]={" + "\n");
- for (int j = 0; j < propertyName.Length; j++)
- {
- sb.Append("['" + propertyName[j] + "']=");
- if (typeName[j].Equals("string"))
- sb.Append("'" + details[j] + "'," + "\n");
- else if (typeName[j].Equals("bool"))
- {
- sb.Append(details[j].ToLower() + "," + "\n");
- }
- else if (typeName[j].Equals("list"))
- {
- if (details[j].IndexOf(';') > 0)
- {
- ParseTable(sb, details[j], ';');
- }
- else if (details[j].IndexOf(':') > 0 && details[j].IndexOf(';') < 0)
- {
- sb.Append("{");
- ParseTable(sb, details[j], ':');
- sb.Append("}");
- }
- else
- {
- sb.Append("{");
- try
- {
- if (details[j].IndexOf('.') > 0)
- {
- Convert.ToDouble(details[j]);
- }
- else
- {
- Convert.ToInt32(details[j]);
- }
- sb.Append(details[j]);
- }
- catch
- {
- if (!string.IsNullOrEmpty(details[j]))
- sb.Append("'" + details[j] + "'");
- }
- sb.Append("}");
- }
- sb.Append(",\n");
- }
- else if (typeName[j].Equals("enum"))
- {
- sb.Append("Enum." + propertyName[j] + "." + details[j] + "," + "\n");
- }
- else
- {
- string num = "0";
- if (details[j] != "")
- {
- num = details[j];
- }
- sb.Append(num + "," + "\n");
- }
- }
- sb.Append("}," + "\n");
- }
- sb.Append("}" + "\n");
- sb.Append("return " + fileName);
- return sb.ToString();
- }
- void ParseTable(StringBuilder sb, string content, char split)
- {
- string[] strs = content.Split(split);
- sb.Append("{");
- for (int m = 0; m < strs.Length; ++m)
- {
- try
- {
- if (strs[m].IndexOf(':') > 0)
- {
- ParseTable(sb, strs[m], ':');
- }
- else
- {
- if (strs[m].IndexOf('.') > 0)
- {
- Convert.ToDouble(strs[m]);
- }
- else
- {
- Convert.ToInt32(strs[m]);
- }
- sb.Append(strs[m]);
- }
- }
- catch
- {
- if (!string.IsNullOrEmpty(strs[m]))
- sb.Append("'" + strs[m] + "'");
- }
- if (m < strs.Length - 1)
- {
- sb.Append(",");
- }
- }
- sb.Append("}");
- }
- List<string> GetContext(string filePath)
- {
- StreamReader sr = new StreamReader(filePath);
- List<string> contexts = new List<string>();
- string line;
- while ((line = sr.ReadLine()) != null)
- contexts.Add(line);
- return contexts;
- }
- string[] GetPropertyName(string line)
- {
- string[] names = line.Split(',');
- return names;
- }
- void Save(string path, string information)
- {
- if (File.Exists(path))
- File.Delete(path);
- FileStream aFile = new FileStream(@"" + path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
- StreamWriter sw = new StreamWriter(aFile);
- sw.Write(information);
- sw.Close();
- sw.Dispose();
- aFile.Close();
- aFile.Dispose();
- sw = null;
- aFile = null;
- AssetDatabase.Refresh();
- }
- public static Dictionary<string, List<CfgLanguageCfg>> GetCfgLanguageCfg(string path)
- {
- Dictionary<string, List<CfgLanguageCfg>> ret = new Dictionary<string, List<CfgLanguageCfg>>();
-
- TextAsset ta = AssetDatabase.LoadAssetAtPath<TextAsset>(path);
- CsvReader csvReader = new CsvReader(CfgLanguageCfg.FileName_S(), ta.bytes);
- CfgLanguageCfg.OnCsvLoad(csvReader);
- CfgLanguageCfg.Foreach(it =>
- {
- if (it.Enable == 0)
- {
- return;
- }
- if (ret.ContainsKey(it.CfgName))
- {
- ret[it.CfgName].Add(it);
- }
- else
- {
- List<CfgLanguageCfg> cfgs = new List<CfgLanguageCfg>();
- cfgs.Add(it);
- ret.Add(it.CfgName,cfgs);
- }
- //Debug.Log(it.BaseName);
- });
- CfgLanguageCfg.Clear();
- return ret;
- }
- public static Dictionary<string, LanguageCfg> GetLanguageCfg(string path)
- {
- Dictionary<string, LanguageCfg> ret = new Dictionary<string, LanguageCfg>();
-
- TextAsset ta = AssetDatabase.LoadAssetAtPath<TextAsset>(path);
- CsvReader csvReader = new CsvReader(LanguageCfg.FileName_S(), ta.bytes,1,2,3);
- LanguageCfg.OnCsvLoad(csvReader);
- LanguageCfg.Foreach(it =>
- {
- if (!ret.ContainsKey(it.key))
- {
- ret.Add(it.key, it);
- }
- else
- {
- ret.Add(it.key+ret.Count,it);
- Debug.Log("重复项:" + it.key);
- }
-
- //Debug.Log(it.BaseName);
- });
- LanguageCfg.Clear(false);
- return ret;
- }
- public static Dictionary<string, LocalizedTextureCfg> GetLanguageTextureCfg(string path)
- {
- Dictionary<string, LocalizedTextureCfg> ret = new Dictionary<string, LocalizedTextureCfg>();
- TextAsset ta = AssetDatabase.LoadAssetAtPath<TextAsset>(path);
- CsvReader csvReader = new CsvReader(LanguageCfg.FileName_S(), ta.bytes, 1, 2, 3);
- LocalizedTextureCfg.OnCsvLoad(csvReader);
- LocalizedTextureCfg.Foreach(it =>
- {
- if (!ret.ContainsKey(it.key))
- {
- ret.Add(it.key, it);
- }
- else
- {
- ret.Add(it.key + ret.Count, it);
- Debug.Log("重复项:" + it.key);
- }
- //Debug.Log(it.BaseName);
- });
- LocalizedTextureCfg.Clear(false);
- return ret;
- }
- public static void CheckCgf()
- {
- string luaPath = "Assets/Lua/Config/";
- string csvPath = "Assets/Content/Config/";
- string OutPutPath = "Build/NewCfg/";
- Dictionary<string, List<CfgLanguageCfg>> cfgs = GetCfgLanguageCfg("Assets/Editor/CsvToLua/CfgLanguageCfg.csv");
- Dictionary<string, LanguageCfg> language = GetLanguageCfg("Assets/Content/Config/LanguagePackage_cn.csv");
- float ckcount = 0;
- foreach (var item in cfgs)
- {
- ckcount+=1;
- List<CfgLanguageCfg> value = item.Value;
-
- EditorUtility.DisplayProgressBar("检测配置中", $"检测:{item.Key}...", ckcount/cfgs.Count);
- string cfgPath = "";
- if (value[0].CfgType == 1)
- {
- cfgPath = luaPath + item.Key + ".lua";
- CheckLauCfg_CS(value,cfgPath,language, $"{OutPutPath}lua/{value[0].CfgName}.lua",(it,_v) => string.Equals(it.Value.Language, _v),(obj,key,_value,cfg)=>
- {
- obj.key = key;
- obj.Language = _value;
- });
- }
- else
- {
- cfgPath = csvPath + item.Key + ".csv";
- CheckCsvCfg(value, cfgPath, language, $"{OutPutPath}csv/{value[0].CfgName}.csv", (it, _v) => string.Equals(it.Value.Language, _v), (obj, key, _value, cfg) =>
- {
- obj.key = key;
- obj.Language = _value;
- });
- }
- }
- EditorUtility.ClearProgressBar();
- CsvWriter<LanguageCfg> csvWriter = new CsvWriter<LanguageCfg>(OutPutPath+ "Language.csv", "Language.csv",language.Values.ToList(), LanguageCfg.GetFormatInfo());
- csvWriter.Write();
- }
- public static void CheckTextureCgf()
- {
- string luaPath = "Assets/Lua/Config/";
- string csvPath = "Assets/Content/Config/";
- string OutPutPath = "Build/NewCfg/";
- Dictionary<string, List<CfgLanguageCfg>> cfgs = GetCfgLanguageCfg("Assets/Editor/CsvToLua/CfgLanguageTextureCfg.csv");
- Dictionary<string, LocalizedTextureCfg> language = GetLanguageTextureCfg("Assets/Content/Config/LocalizeTextureCfg_base.csv");
- float ckcount = 0;
- foreach (var item in cfgs)
- {
- ckcount += 1;
- List<CfgLanguageCfg> value = item.Value;
- EditorUtility.DisplayProgressBar("检测配置中", $"检测:{item.Key}...", ckcount / cfgs.Count);
- string cfgPath = "";
- if (value[0].CfgType == 1)
- {
- cfgPath = luaPath + item.Key + ".lua";
- CheckLauCfg_CS(value, cfgPath, language, $"{OutPutPath}lua/{value[0].CfgName}.lua", (it, _v) => string.Equals(it.Value.Language, _v), (obj, key, _value, cfg) =>
- {
- obj.key = key;
- obj.Language = _value;
- obj.AssetPath = cfg.AssetPath;
- });
- }
- else
- {
- cfgPath = csvPath + item.Key + ".csv";
- CheckCsvCfg(value, cfgPath, language, $"{OutPutPath}csv/{value[0].CfgName}.csv", (it, _v) => string.Equals(it.Value.Language, _v), (obj, key, _value, cfg) =>
- {
- obj.key = key;
- obj.Language = _value;
- obj.AssetPath = cfg.AssetPath;
- });
- }
- }
- EditorUtility.ClearProgressBar();
- CsvWriter<LocalizedTextureCfg> csvWriter = new CsvWriter<LocalizedTextureCfg>(OutPutPath + "LocalizedTextureCfg.csv", "LocalizedTextureCfg.csv", language.Values.ToList(), LocalizedTextureCfg.GetFormatInfo());
- csvWriter.Write();
- }
- private static void CheckLauCfg(List<CfgLanguageCfg> cfg,string path, Dictionary<string, LanguageCfg> language,string outputPath)
- {
- using (LuaState runTime = new LuaState())
- {
- runTime.Start();
- RolePreviewWindow.LuaForEach<int, LuaTable>(runTime, path, (id,luatable) =>
- {
- for (int i = 0; i < cfg.Count; i++)
- {
- if (cfg[i].Enable == 0)
- continue;
- string value = luatable.RawGet<string, string>(cfg[i].Field);
- if (string.IsNullOrEmpty(value))
- {
- continue;
- }
- KeyValuePair<string,LanguageCfg> valuePair = language.FirstOrDefault(it =>
- {
- return string.Equals(it.Value.Language, value);
- });
- if (!string.IsNullOrEmpty(valuePair.Key))
- {
- luatable.RawSet<string, string>(cfg[i].Field, valuePair.Key);
- }
- else
- {
- string key = cfg[i].CfgID + id;
- luatable.RawSet<string, string>(cfg[i].Field, key);
- if (value.Contains("\n"))
- {
- Debug.Log(value);
- value = value.Replace("\n","\\n");
- Debug.Log(value);
- }
- language.Add(key,new LanguageCfg() { key = key,Language = value});
- }
- }
- },(ltab)=>
- {
- bool useObj = IsObj;
- if (useObj)
- {
- LuaState luaState = LuaClient.Instance.luaState;
- luaState.DoFile("Assets\\Editor\\CsvToLua\\table-save.lua");
- RolePreviewWindow.SaveToLua(luaState, outputPath, ltab, cfg[0].CfgName, "1");
- }
- else
- {
- LuaState luaState = runTime;
- luaState.DoFile("Assets\\Editor\\CsvToLua\\table-save.lua");
- RolePreviewWindow.SaveToLua(luaState, outputPath, ltab, cfg[0].CfgName, "");
- }
-
- });
- }
-
- }
- private static void SetLuaLine(string[] rowDatas,int id,string key,string data,string dataF = "'{0}',")
- {
- string idkey = $"[{id}]";
- string keykey = $"'{key}'";
- string wdata = string.Format(dataF,data);//$"'{data}',";
- bool isFind = false;
- for (int line = 0; line < rowDatas.Length; line++)
- {
- if (rowDatas[line].Trim().IndexOf("--") == 0)
- {
- //Debug.Log("注释跳过");
- }
-
- if (rowDatas[line].Contains(idkey))
- {
- isFind = true;
- }
- if (isFind && rowDatas[line].Contains(keykey))
- {
- int s = rowDatas[line].IndexOf('[');
- string p = "";
- if (s > 0)
- {
- for (int i = 0; i < s; i++)
- {
- p += " ";
- }
- }
- string newstr = $"{p}[{keykey}]={wdata}" ;
- rowDatas[line] = newstr;
- break;
- }
- }
- }
- private static void CheckLauCfg_CS<T>(List<CfgLanguageCfg> cfg, string path, Dictionary<string, T> language, string outputPath,Func<KeyValuePair<string,T>,string,bool> findcb, Action<T,string,string, CfgLanguageCfg> cb) where T :GameData
- {
- string[] rowDatas = File.ReadAllLines(path);
- bool iswrite = true;
- using (LuaState runTime = new LuaState())
- {
- runTime.Start();
- RolePreviewWindow.LuaForEach<int, LuaTable>(runTime, path, (id, luatable) =>
- {
- for (int i = 0; i < cfg.Count; i++)
- {
- if (cfg[i].Enable == 0)
- {
- iswrite = false;
- continue;
- }
- string value = luatable.RawGet<string, string>(cfg[i].Field);
- if (string.IsNullOrEmpty(value))
- {
- continue;
- }
- KeyValuePair<string, T> valuePair = language.FirstOrDefault(it=>
- {
- return findcb(it,value);
- });
- if (!string.IsNullOrEmpty(valuePair.Key))
- {
- luatable.RawSet<string, string>(cfg[i].Field, valuePair.Key);
- SetLuaLine(rowDatas,id, cfg[i].Field, valuePair.Key);
- }
- else
- {
- string key = cfg[i].CfgID + id;
- luatable.RawSet<string, string>(cfg[i].Field, key);
- SetLuaLine(rowDatas, id, cfg[i].Field, key);
- if (value.Contains("\n"))
- {
- //Debug.Log(value);
- value = value.Replace("\n", "\\n");
- //Debug.Log(value);
- }
- if (!language.ContainsKey(key))
- {
- Type type = typeof(T);
- T obj = Activator.CreateInstance<T>();
- cb?.Invoke(obj,key,value, cfg[i]);
- language.Add(key, obj);
- }
- }
- }
- });
- }
- if (iswrite)
- File.WriteAllLines(outputPath,rowDatas);
- }
- private static void CheckCsvCfg<T>(List<CfgLanguageCfg> cfg, string path, Dictionary<string, T> language, string outputPath, Func<KeyValuePair<string, T>,string, bool> findcb, Action<T, string, string, CfgLanguageCfg> cb) where T : GameData
- {
- CsvReader csvReader = new CsvReader(path,1,2,3);
- string[][] datas = csvReader.RowDatas;
- for (int i = csvReader.StartLine; i < datas.Length; i++)
- {
-
- string[] curLine = datas[i];
- for (int j = 0; j < cfg.Count; j++)
- {
- if (cfg[j].Enable == 0)
- continue;
- string value = csvReader.GetDataByFieldName(cfg[j].Field,i);
- if (string.IsNullOrEmpty(value))
- {
- continue;
- }
- KeyValuePair<string, T> valuePair = language.FirstOrDefault(it =>
- {
- return findcb(it, value);
- });
- if (!string.IsNullOrEmpty(valuePair.Key))
- {
- csvReader.SetDataByFieldName(cfg[j].Field, valuePair.Key, i);
- }
- else
- {
- string key = cfg[j].CfgID + i;
- csvReader.SetDataByFieldName(cfg[j].Field, key,i);
- Type type = typeof(T);
- T obj = Activator.CreateInstance<T>();
- cb?.Invoke(obj, key, value, cfg[i]);
- language.Add(key,obj);
- }
- }
- }
- FileHelper.WirteStringToFile(outputPath,csvReader.GetString());
- }
- private static void ChangeLuaCfg(string luacfgpath,string luachagepath,string outputPath)
- {
- string[] rowDatas = File.ReadAllLines(luacfgpath);
- using (LuaState runTime = new LuaState())
- {
- runTime.Start();
- LuaTable luaTable = runTime.DoFile<LuaTable>(luachagepath);
- RolePreviewWindow.LuaForEach<int, LuaTable>(runTime, luacfgpath, (id, luatable) =>
- {
- LuaFunction luaFunction = luaTable.GetLuaFunction("IsChangefg");
- bool ischange = luaFunction.Invoke<LuaTable,LuaTable, bool>(luaTable,luatable);
- if (ischange)
- {
- LuaTable fieldValue = luaTable.Invoke<LuaTable,LuaTable>("GetFieldAddValue", luaTable);
- string field = fieldValue.RawGet<string, string>("field");
- string value = fieldValue.RawGet<string, string>("value");
-
- SetLuaLine(rowDatas,id,field,value.ToString(),"{0},");
-
- }
- });
-
- }
- File.WriteAllLines(outputPath, rowDatas);
- }
- private static void CopyFleByLuaCfg(string luacfgpath, string fileRootPath,string outputPath,string output,bool isCheck = false,bool copyqsFile = false)
- {
- using (LuaState runTime = new LuaState())
- {
- runTime.Start();
- LuaTable luaTable = runTime.DoFile<LuaTable>(luacfgpath);
- LuaFunction init_fun = luaTable.GetLuaFunction("Init");
- LuaFunction SetOutput_fun = luaTable.GetLuaFunction("SetOutput");
- LuaFunction GetNextCfg_fun = luaTable.GetLuaFunction("GetNextCfg");
- LuaFunction GetLen_fun = luaTable.GetLuaFunction("GetLen");
-
- init_fun.Call<LuaTable>(luaTable);
- SetOutput_fun.Call<LuaTable, string>(luaTable, output);
- int len = GetLen_fun.Invoke<LuaTable,int>(luaTable);
- int curindex = 1;
- EditorUtility.DisplayProgressBar("复制中", $"开始复制", 0);
- string metastr = ".meta";
- List<string> checkList = new List<string>();
- while (true)
- {
- EditorUtility.DisplayProgressBar("复制中", $"复制{curindex}/{len}", curindex/len);
- curindex++;
- LuaTable cfg = GetNextCfg_fun.Invoke<LuaTable, LuaTable>(luaTable);
- //{result = false,path = path,outputPath = outputPath}
- bool result = cfg.RawGet<string, bool>("result");
- if (result)
- {
- string path = cfg.RawGet<string, string>("path");
- string _outputPath = cfg.RawGet<string, string>("outputPath");
- string filePath = fileRootPath + path;
- string fileOutputPath = outputPath + _outputPath;
- if (path.Contains(".psd"))
- {
- Debug.Log($"不复制psd文件:[{path}]");
- continue;
- }
-
- FileHelper.CreateDir(FileHelper.PathRemoveBack(fileOutputPath));
- if (File.Exists(filePath))
- {
- if (isCheck)
- {
- continue;
- }
- File.Copy(filePath, fileOutputPath, true);
-
- if (!path.Contains(metastr)&& File.Exists(filePath + metastr))
- {
- File.Copy(filePath+ metastr, fileOutputPath+ metastr, true);
- }
- }
-
- else
- {
- if (isCheck&& !path.Contains(metastr))
- {
- checkList.Add(path+"\r\n");
- if (copyqsFile&& File.Exists(path))
- {
- File.Copy(path, fileOutputPath, true);
- }
- else
- {
- Debug.Log($"复制 不存在文件:[{path}]");
- }
- }
- Debug.Log($"不存在文件:[{filePath}]");
- }
- }
- else
- {
- break;
- }
- }
- if (isCheck)
- {
- FileHelper.WirteStringToFile(outputPath+"checkTxt.txt",FileHelper.CatStringArray(checkList,""));
- }
- EditorUtility.ClearProgressBar();
- }
- }
- struct lgInfo
- {
- public int index;
- public int off;
- }
- private static void MergeLanauage(string oldPath,string newPath, string outputPath)
- {
- List<string> oldLg = File.ReadAllLines(oldPath).ToList();
- List<string> newLg = File.ReadAllLines(newPath).ToList();
- Dictionary<string, lgInfo> cfgmap = new Dictionary<string, lgInfo>();
- int length = oldLg.Count;
- int off = -1;
- for (int i = 0; i < length; i++)
- {
- off = oldLg[i].IndexOf(',');
- if (off < 0)
- {
- continue;
- }
- string key = oldLg[i].Substring(0,off);
- if (!cfgmap.ContainsKey(key))
- {
- lgInfo info = new lgInfo();
- info.index = i;
- info.off = off;
- cfgmap.Add(key, info);
- }
- }
- foreach (var item in newLg)
- {
- if (item == "" || item == ","||item == "key"||item == "string")
- continue;
- off = item.IndexOf(',');
- if (off < 0)
- {
- continue;
- }
- string key = item.Substring(0,off);
- if (!cfgmap.ContainsKey(key))
- {
- Debug.Log($"不包含:{key} off = {off}");
- oldLg.Add(item);
- }
- else
- {
- lgInfo lgIf = cfgmap[key];
- oldLg[lgIf.index] = item;
- }
- }
- string data = FileHelper.CatStringArray(oldLg,"\r\n");
- FileHelper.WirteStringToFile(outputPath, data);
- Debug.Log("合并完成");
- }
- private void B2T(string bPath,string outPath, Encoding read)
- {
- using (FileStream binaryFileStream = new FileStream(bPath, FileMode.Open, FileAccess.Read))
- using (StreamReader reader = new StreamReader(binaryFileStream, read)) // 使用ASCII编码读取
- using (StreamWriter writer = new StreamWriter(outPath))
- {
- writer.Write(reader.ReadToEnd()); // 读取并写入文本文件
- }
- }
- public static void AddLocalizTextureCfgByFileCfg(string luacfgpath)
- {
- string OutPutPath = "Build/NewCfg/";
- Dictionary<string, LocalizedTextureCfg> language = GetLanguageTextureCfg("Assets/Content/Config/LocalizeTextureCfg_base.csv");
- using (LuaState runTime = new LuaState())
- {
- runTime.Start();
- LuaTable luaTable = runTime.DoFile<LuaTable>(luacfgpath);
- LuaFunction init_fun = luaTable.GetLuaFunction("Init");
- LuaFunction SetOutput_fun = luaTable.GetLuaFunction("SetOutput");
- LuaFunction GetNextCfg_fun = luaTable.GetLuaFunction("GetNextAddlocaizedCfg");
- LuaFunction GetLen_fun = luaTable.GetLuaFunction("GetLen");
- init_fun.Call<LuaTable>(luaTable);
- //SetOutput_fun.Call<LuaTable, string>(luaTable, output);
- int len = GetLen_fun.Invoke<LuaTable, int>(luaTable);
- int curindex = 1;
- EditorUtility.DisplayProgressBar("复制中", $"开始复制", 0);
- //string metastr = ".meta";
- while (true)
- {
- EditorUtility.DisplayProgressBar("复制中", $"复制{curindex}/{len}", curindex / len);
- curindex++;
- LuaTable cfg = GetNextCfg_fun.Invoke<LuaTable, LuaTable>(luaTable);
- //{result = false,path = path,outputPath = outputPath}
- int result = cfg.RawGet<string, int>("result");
- if (result ==1)
- {
- string key = cfg.RawGet<string, string>("key");
- string Languages = cfg.RawGet<string, string>("Language");
- string AssetPath = cfg.RawGet<string, string>("AssetPath");
- string other = cfg.RawGet<string, string>("other");
- string setN = cfg.RawGet<string, string>("setN");
- if (!language.ContainsKey(key))
- {
- language.Add(key,new LocalizedTextureCfg() {key = key,Language = Languages, AssetPath = AssetPath ,OtherSetting = other,SetNativeSize = setN});
- }
- else
- {
- Debug.Log("key重复:"+key);
- }
- }
- else if (result == 0)
- {
- break;
- }
- }
- EditorUtility.ClearProgressBar();
- }
- Debug.Log("完成检查");
- CsvWriter<LocalizedTextureCfg> csvWriter = new CsvWriter<LocalizedTextureCfg>(OutPutPath + "LocalizedTextureCfg.csv", "LocalizedTextureCfg.csv", language.Values.ToList(), LocalizedTextureCfg.GetFormatInfo());
- csvWriter.Write();
- }
- public static void CopycpfCfgFileToDir(string luacfgpath, string fileroot,string output)
- {
- using (LuaState runTime = new LuaState())
- {
- runTime.Start();
- LuaTable luaTable = runTime.DoFile<LuaTable>(luacfgpath);
- LuaFunction init_fun = luaTable.GetLuaFunction("Init");
- LuaFunction SetOutput_fun = luaTable.GetLuaFunction("SetOutput");
- LuaFunction GetNextCfg_fun = luaTable.GetLuaFunction("GetNextCpfCfg");
- LuaFunction GetLen_fun = luaTable.GetLuaFunction("GetLen");
- init_fun.Call<LuaTable>(luaTable);
- //SetOutput_fun.Call<LuaTable, string>(luaTable, output);
- int len = GetLen_fun.Invoke<LuaTable, int>(luaTable);
- int curindex = 1;
- EditorUtility.DisplayProgressBar("复制中", $"开始复制", 0);
- //string metastr = ".meta";
- while (true)
- {
- EditorUtility.DisplayProgressBar("复制中", $"复制{curindex}/{len}", curindex / len);
- curindex++;
- LuaTable cfg = GetNextCfg_fun.Invoke<LuaTable, LuaTable>(luaTable);
- int result = cfg.RawGet<string, int>("result");
- if (result == 1)
- {
- LuaTable copycfg = cfg.RawGet<string, LuaTable>("curCfg");
- string basepath = copycfg.RawGet<string, string>("basepath");
- string path = copycfg.RawGet<string, string>("path");
- string fileName = copycfg.RawGet<string, string>("fileName");
- if (fileName.Contains(".png")&& File.Exists(fileroot + fileName))
- {
- string opp = output + basepath + path + "/" + fileName;
- FileHelper.CreateDir(FileHelper.PathRemoveBack(opp));
- File.Copy(fileroot + fileName, opp, true);
- }
- }
- else if (result == 0)
- {
- break;
- }
- }
- EditorUtility.ClearProgressBar();
- }
- Debug.Log("完成检查");
-
- }
- }
|