Exemple #1
0
 private void DrawAssetUI()
 {
     GUILayout.BeginHorizontal("HelpBox");
     EditorGUILayout.LabelField("== 快捷功能 ==");
     GUILayout.EndHorizontal();
     GUILayout.BeginHorizontal();
     if (GUILayout.Button("Build Lua To StreamingAsset", GUILayout.ExpandWidth(true), GUILayout.MaxHeight(30)))
     {
         ColaEditHelper.BuildLuaToStreamingAsset();
     }
     GUILayout.EndHorizontal();
 }
    private void DrawAssetUI()
    {
        GUILayout.BeginHorizontal("HelpBox");
        EditorGUILayout.LabelField("== 快捷功能 ==");
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Build Lua To StreamingAsset", GUILayout.ExpandWidth(true), GUILayout.MaxHeight(30)))
        {
            ColaEditHelper.BuildLuaToStreamingAsset();
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Zip Lua", GUILayout.ExpandWidth(true), GUILayout.MaxHeight(30)))
        {
            var result = ZipHelper.Zip("Assets/Lua", Path.Combine(Application.dataPath, "../output/luaout.zip"));
            Debug.Log("Zip Lua结果:" + result);
        }
        if (GUILayout.Button("UnZip Lua", GUILayout.ExpandWidth(true), GUILayout.MaxHeight(30)))
        {
            var filePath = Path.Combine("Assets", "../output/luaout.zip");
            if (File.Exists(filePath))
            {
                var result = ZipHelper.UnZip(filePath, Path.Combine("Assets", "../output"));
                Debug.Log("UnZip Lua结果:" + result);
            }
            else
            {
                Debug.LogError("解压错误!要解压的文件不存在!路径:" + filePath);
            }
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("筛选出MD5码变化的lua文件", GUILayout.ExpandWidth(true), GUILayout.MaxHeight(30)))
        {
            var md5Dic         = new Dictionary <string, string>();
            var luaMd5FilePath = ColaEditHelper.TempCachePath + "/LuaMD5.txt";
            if (File.Exists(luaMd5FilePath))
            {
                using (var sm = new StreamReader(luaMd5FilePath, Encoding.UTF8))
                {
                    var fileLines = sm.ReadToEnd().Split('\n');
                    foreach (var item in fileLines)
                    {
                        if (string.IsNullOrEmpty(item))
                        {
                            continue;
                        }
                        var lineContent = item.Split('|');
                        if (lineContent.Length == 2)
                        {
                            md5Dic[lineContent[0]] = lineContent[1];
                        }
                        else
                        {
                            Debug.LogError("LuaMD5.txt格式错误!内容为: " + lineContent);
                        }
                    }
                }
            }

            var luaFiles = new List <string>(Directory.GetFiles(LuaLogicPath, "*.lua", SearchOption.AllDirectories));
            var fLength  = (float)luaFiles.Count;

            int diffCnt = 0;
            for (int i = 0; i < luaFiles.Count; i++)
            {
                var    fileName = luaFiles[i];
                string curMd5   = FileHelper.GetMD5Hash(fileName);
                if (md5Dic.ContainsKey(fileName) && curMd5 == md5Dic[fileName])
                {
                    continue;
                }
                diffCnt++;
                string destPath = Regex.Replace(fileName, "^Assets", "output");
                FileHelper.EnsureParentDirExist(destPath);
                File.Copy(fileName, destPath, true);
                md5Dic[fileName] = curMd5;
                EditorUtility.DisplayProgressBar("正在分析Lua差异化..", fileName, i / fLength);
            }

            var sb = new StringBuilder();
            foreach (var item in md5Dic)
            {
                sb.AppendFormat("{0}|{1}", item.Key, item.Value).AppendLine();
            }
            FileHelper.WriteString(luaMd5FilePath, sb.ToString());
            EditorUtility.ClearProgressBar();

            Debug.LogFormat("Lua差异化分析完毕!共有{0}个差异化文件!", diffCnt);
        }
        GUILayout.EndHorizontal();
    }