/// <summary> /// delete res folder /// </summary> public static void DeleteSplitPackageResFolder() { string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName); Debug.Log("Delete directory " + updateOutPath); EditorUtils.DirectoryDelete(updateOutPath); string updateOutVersionPath = Path.Combine(UpdateOutVersionPath, ResFolderName); Debug.Log("Delete directory " + updateOutVersionPath); EditorUtils.DirectoryDelete(updateOutVersionPath); }
public static void doExportLua(string[] childrens) { EditorUtils.CheckstreamingAssetsPath(); string info = "luac"; string title = "build lua"; EditorUtility.DisplayProgressBar(title, info, 0); var checkChildrens = AssetDatabase.GetAllAssetPaths().Where(p => (p.StartsWith("Assets/Lua") || p.StartsWith("Assets/Config")) && (p.EndsWith(".lua")) ).ToArray(); string path = "Assets/Lua/"; //lua path string path1 = "Assets/Config/"; //config path string root = CurrentRootFolder; //Application.dataPath.Replace("Assets", ""); string crypName = "", crypEditorName = "", fileName = "", outfilePath = "", arg = ""; System.Text.StringBuilder sb = new System.Text.StringBuilder(); //refresh directory if (checkChildrens.Length == childrens.Length) { EditorUtils.DirectoryDelete(OutLuaPath); } EditorUtils.CheckDirectory(OutLuaPath); float allLen = childrens.Length; float i = 0; Debug.Log("luajit32Path:" + luajit32Path); Debug.Log("luajit64Path:" + luajit64Path); Debug.Log("luacPath:" + luacPath); string OutLuaBytesPath = EditorUtils.GetLuaBytesResourcesPath(); string luabytesParentPath = OutLuaBytesPath.Substring(0, OutLuaBytesPath.LastIndexOf("/")); string streamingAssetsPath = Path.Combine(CurrentRootFolder, OutLuaBytesPath); //Path.Combine(CurrentRootFolder, LuaTmpPath); EditorUtils.DirectoryDelete(luabytesParentPath); EditorUtils.CheckDirectory(luabytesParentPath); EditorUtils.CheckDirectory(streamingAssetsPath); Debug.Log(streamingAssetsPath); List <System.Diagnostics.Process> listPc = new List <System.Diagnostics.Process>(); List <string> luabytesAssets32 = new List <string>(); List <string> luabytesAssets64 = new List <string>(); foreach (string file in childrens) { string filePath = Path.Combine(root, file); fileName = CUtils.GetAssetName(filePath); crypName = file.Replace(path, "").Replace(path1, "").Replace(".lua", ".bytes").Replace("\\", "+").Replace("/", "+"); crypEditorName = file.Replace(path, "").Replace(path1, "").Replace(".lua", "." + Common.ASSETBUNDLE_SUFFIX).Replace("\\", "+").Replace("/", "+"); if (!string.IsNullOrEmpty(luajit32Path))// luajit32 { string override_name = CUtils.GetRightFileName(crypName); string override_lua = streamingAssetsPath + "/" + override_name; arg = "-b " + filePath + " " + override_lua; //for jit // Debug.Log(arg); listPc.Add(CreateProcess(arg, luajit32Path)); luabytesAssets32.Add(Path.Combine(OutLuaBytesPath, override_name)); sb.AppendLine("[\"" + crypName + "\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},"); } if (!string.IsNullOrEmpty(luajit64Path)) //luajit64 { string crypName_64 = CUtils.InsertAssetBundleName(crypName, "_64"); string override_name = CUtils.GetRightFileName(crypName_64); string override_lua = streamingAssetsPath + "/" + override_name; arg = "-b " + filePath + " " + override_lua; //for jit // Debug.Log(arg); listPc.Add(CreateProcess(arg, luajit64Path)); luabytesAssets64.Add(Path.Combine(OutLuaBytesPath, override_name)); sb.AppendLine("[\"" + crypName_64 + "\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},"); } if (!string.IsNullOrEmpty(luacPath)) //for editor { string override_name = CUtils.GetRightFileName(crypEditorName); //CUtils.GetRightFileName(CUtils.InsertAssetBundleName(crypName,"_64")); string override_lua = OutLuaPath + "/" + override_name; #if UNITY_EDITOR_OSX && !UNITY_STANDALONE_WIN arg = "-o " + override_lua + " " + filePath; //for lua #else arg = "-b " + filePath + " " + override_lua; //for jit #endif // Debug.Log(arg); listPc.Add(CreateProcess(arg, luacPath)); sb.AppendLine("[\"" + crypEditorName + "(editor)\"] = { name = \"" + override_name + "\", path = \"" + file + "\", out path = \"" + override_lua + "\"},"); } i++; // EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen); } //compile lua int total = listPc.Count; int workThreadCount = System.Environment.ProcessorCount * 2 + 2; int batchCount = (int)System.Math.Ceiling(total / (float)workThreadCount); for (int batchIndex = 0; batchIndex < batchCount; ++batchIndex) { int processIndex; int offset = batchIndex * workThreadCount; for (processIndex = 0; processIndex < workThreadCount; ++processIndex) { int fileIndex = offset + processIndex; if (fileIndex >= total) { break; } var ps = listPc[fileIndex]; ps.Start(); } bool fail = false; fileName = null; string arguments = null; for (int j = offset; j < offset + processIndex; ++j) { var ps = listPc[j]; ps.WaitForExit(); EditorUtility.DisplayProgressBar(title, info + "=>" + j.ToString() + "/" + total.ToString(), j / total); if (ps.ExitCode != 0 && !fail) { fail = true; fileName = ps.StartInfo.FileName; arguments = ps.StartInfo.Arguments; } ps.Dispose(); } if (fail) { throw new System.Exception(string.Format("Luajit Compile Fail.FileName={0},Arg={1}", fileName, arguments)); } } Debug.Log("lua:" + path + "files=" + childrens.Length + " completed"); System.Threading.Thread.Sleep(100); // AssetDatabase.Refresh(); //all luabytes in one asset // var luaBytesAsset = ScriptableObject.CreateInstance<LuaBytesAsset>(); // foreach (var file in luabytesAssets32) // { // var bytes = File.ReadAllBytes(file); // var fn = CUtils.GetAssetName(file); // luaBytesAsset.GenerateBytes(bytes, fn); // Debug.LogFormat("lua 32 bytes name ={0},len={1}", fn, bytes.Length); // } // string luaAssetPath = Path.Combine(luabytesParentPath, Common.LUA_BUNDLE_NAME_X86 + ".asset"); // AssetDatabase.DeleteAsset(luaAssetPath); // AssetDatabase.CreateAsset(luaBytesAsset, luaAssetPath); // Debug.LogFormat("lua32:{0}", luaAssetPath); // if (luabytesAssets64.Count > 0) // { // var luaBytesAsset64 = ScriptableObject.CreateInstance<LuaBytesAsset>(); // foreach (var file in luabytesAssets64) // { // var bytes = File.ReadAllBytes(file); // var fn = CUtils.GetAssetName(file); // luaBytesAsset.GenerateBytes(bytes, fn); // Debug.LogFormat("lua 64 bytes name ={0},len={1}", fn, bytes.Length); // } // luaAssetPath = Path.Combine(luabytesParentPath, Common.LUA_BUNDLE_NAME_X64 + ".asset"); // AssetDatabase.DeleteAsset(luaAssetPath); // AssetDatabase.CreateAsset(luaBytesAsset64, luaAssetPath); // Debug.LogFormat("lua64:{0}", luaAssetPath); // } //out md5 mapping file string tmpPath = EditorUtils.GetAssetTmpPath(); EditorUtils.CheckDirectory(tmpPath); string outPath = Path.Combine(tmpPath, "lua_md5mapping.txt"); Debug.Log("write to path=" + outPath); using (StreamWriter sr = new StreamWriter(outPath, false)) { sr.Write(sb.ToString()); } EditorUtility.ClearProgressBar(); }