Browse Source

Merge branch 'localizetexture' of ssh://192.168.0.8:29418/xianjing into hy_dny_localized

gdl_123 2 months ago
parent
commit
b2ed33a1dc
2 changed files with 108 additions and 1 deletions
  1. 66 0
      Assets/Editor/CsvToLua/CsvToLua.cs
  2. 42 1
      Assets/Editor/CsvToLua/luaCopyFileCfg.lua

+ 66 - 0
Assets/Editor/CsvToLua/CsvToLua.cs

@@ -214,6 +214,11 @@ return aaa";
         {
             CopyFleByLuaCfg("Assets\\Editor\\CsvToLua\\luaCopyFileCfg.lua", "", "D:/项目/图/仙境/cn/","_cn");
         }
+
+        if (GUILayout.Button("添加图片配置"))
+        {
+            AddLocalizTextureCfgByFileCfg("Assets\\Editor\\CsvToLua\\luaCopyFileCfg.lua");
+        }
     }
 
     public static string GetFilePath()
@@ -984,4 +989,65 @@ return aaa";
             writer.Write(reader.ReadToEnd()); // 读取并写入文本文件
         }
     }
+
+
+    public static void AddLocalizTextureCfgByFileCfg(string luacfgpath)
+    {
+        string luaPath = "Assets/Lua/Config/";
+        string csvPath = "Assets/Content/Config/";
+        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();
+    }
 }

+ 42 - 1
Assets/Editor/CsvToLua/luaCopyFileCfg.lua

@@ -1281,7 +1281,13 @@ luaCopyFileCfg.FileCfg ={
 
 }
 
-
+luaCopyFileCfg.AddlocaizedCfg = 
+{
+    paths={'Buff'},
+    addCfg = {
+        ['Buff']= {ex = ".png",Namer= "",basepath = "Assets/Content/Icons",other = "",setN = "0"}
+    }
+}
 
 
 function luaCopyFileCfg:Init()
@@ -1309,4 +1315,39 @@ function luaCopyFileCfg:GetNextCfg()
     return {result = true,path = path,outputPath = outputPath}
 end
 
+function luaCopyFileCfg:GetNextAddlocaizedCfg()
+      if self.curindex > self.MaxIndex then
+        return {result = 0}
+    end
+
+    local curCfg = self.FileCfg[self.curindex]
+    self.curindex = self.curindex + 1
+
+    for _, value in pairs(self.AddlocaizedCfg.paths) do
+        if value == curCfg.path then
+            local adCfg = self.AddlocaizedCfg.addCfg[value]
+            local s,e =string.find(curCfg.fileName,adCfg.ex)
+            if  s~=nil and s > 0 then
+                local key = ""
+                local f = string.sub(curCfg.fileName,1,s-1)
+                local Language = curCfg.path..'/'..f
+                if adCfg.Namer == "" then
+                    key = Language
+                else
+                    key = string.format(adCfg.Namer,f) 
+                end
+               
+                local AssetPath = adCfg.basepath
+                local other = adCfg.other
+                local setN = adCfg.setN
+
+                return {result = 1,key = key,Language = Language,AssetPath = AssetPath,other = other,setN = setN}
+            end
+        end
+    end
+
+    return {result = 2}
+end
+
+
 return luaCopyFileCfg