コード例 #1
0
        /// <summary>
        /// 自动构建ab
        /// </summary>
        /// <param name="assets"></param>
        /// <param name="outPath"></param>
        /// <param name="abName"></param>
        /// <param name="bbo"></param>
        static public void BuildABs(string[] assets, string outPath, string abName, BuildAssetBundleOptions bbo)
        {
            AssetBundleBuild[] bab = new AssetBundleBuild[1];
            bab[0].assetBundleName = abName; //打包的资源包名称 随便命名
            bab[0].assetNames      = assets;
            if (string.IsNullOrEmpty(outPath))
            {
                outPath = EditorUtils.GetOutPutPath();
            }

            string tmpPath = EditorUtils.GetProjectTempPath();

            EditorUtils.CheckDirectory(tmpPath);
            string tmpFileName = Path.Combine(tmpPath, abName);

            BuildPipeline.BuildAssetBundles(tmpPath, bab, bbo, target);

            string   targetFileName = Path.Combine(outPath, abName);
            FileInfo tInfo          = new FileInfo(targetFileName);

            if (tInfo.Exists)
            {
                tInfo.Delete();
            }
            FileInfo fino = new FileInfo(tmpFileName);

            fino.CopyTo(targetFileName);
        }
コード例 #2
0
        /// <summary>
        /// 自动构建abs
        /// </summary>
        /// <param name="assets"></param>
        /// <param name="outPath"></param>
        /// <param name="abName"></param>
        /// <param name="bbo"></param>
        static public void BuildABs(AssetBundleBuild[] bab, string outPath, BuildAssetBundleOptions bbo)
        {
            if (string.IsNullOrEmpty(outPath))
            {
                outPath = EditorUtils.GetOutPutPath();
            }

            string tmpPath = EditorUtils.GetProjectTempPath();

            EditorUtils.CheckDirectory(tmpPath);

            BuildPipeline.BuildAssetBundles(tmpPath, bab, bbo, target);

            foreach (AssetBundleBuild abb in bab)
            {
                string   abName         = abb.assetBundleName;
                string   tmpFileName    = Path.Combine(tmpPath, abName);
                string   targetFileName = Path.Combine(outPath, abName);
                FileInfo tInfo          = new FileInfo(targetFileName);
                if (tInfo.Exists)
                {
                    tInfo.Delete();
                }
                FileInfo fino = new FileInfo(tmpFileName);
                fino.CopyTo(targetFileName);
            }
        }
コード例 #3
0
ファイル: BuildScript.cs プロジェクト: lonecolonel/hugula
        /// <summary>
        /// 自动构建abs
        /// </summary>
        /// <param name="assets"></param>
        /// <param name="outPath"></param>
        /// <param name="abName"></param>
        /// <param name="bbo"></param>
        static public void BuildABs(AssetBundleBuild[] bab, string outPath, BuildAssetBundleOptions bbo)
        {
            if (string.IsNullOrEmpty(outPath))
            {
                outPath = EditorUtils.GetOutPutPath();
            }

            string tmpPath = EditorUtils.GetProjectTempPath();

            EditorUtils.CheckDirectory(tmpPath);

            var assetBundleManifest = BuildPipeline.BuildAssetBundles(tmpPath, bab, bbo, target);


            var abNames = assetBundleManifest.GetAllAssetBundles();

            foreach (var abName in abNames)
            {
                string   tmpFileName    = Path.Combine(tmpPath, abName);
                string   targetFileName = Path.Combine(outPath, abName);
                FileInfo tInfo          = new FileInfo(targetFileName);
                if (tInfo.Exists)
                {
                    tInfo.Delete();
                }
                FileInfo fino = new FileInfo(tmpFileName);
                fino.CopyTo(targetFileName);
                Debug.LogFormat("Build assetbundle : {0} ", targetFileName);
            }
        }
コード例 #4
0
ファイル: ExportResources.cs プロジェクト: xubingyue/hugula
        public static void doExportLua(string rootPath)
        {
            EditorUtils.CheckstreamingAssetsPath();
            string OutLuaBytesPath = EditorUtils.GetLuaBytesResourcesPath();

            AssetDatabase.DeleteAsset(OutLuaBytesPath);
            EditorUtils.GetLuaBytesResourcesPath();

            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            var files   = Directory.GetFiles(rootPath, "*.lua", SearchOption.AllDirectories);
            var dests   = new string[files.Length];
            var dests64 = new string[files.Length];

            for (int i = 0; i < files.Length; i++)
            {
                string xfile = files[i].Remove(0, rootPath.Length + 1);
                xfile = xfile.Replace("\\", "+").Replace("/", "+");
                string xfile64 = CUtils.InsertAssetBundleName(xfile, "_64");

                string file     = files[i].Replace("\\", "/");
                string dest     = OutLuaBytesPath + "/" + CUtils.GetRightFileName(xfile);
                string destName = dest.Substring(0, dest.Length - 3) + "bytes";

                string dest64     = OutLuaBytesPath + "/" + CUtils.GetRightFileName(xfile64);
                string destName64 = dest64.Substring(0, dest64.Length - 3) + "bytes";


                files[i]   = file;
                dests[i]   = destName;
                dests64[i] = destName64;
                sb.AppendLine("[\"" + xfile + "\"]");
                sb.Append(" = {path = \"" + CUtils.GetRightFileName(xfile) + "\", ");
                sb.Append("out path64 = \"" + CUtils.GetRightFileName(xfile64) + "\"},");

                UnityEngine.Debug.Log(xfile + ":" + destName + " 64=" + destName64);
            }

            #if UNITY_ANDROID || UNITY_IPHONE
            SLua.LuajitGen.compileLuaJit(files, dests64, SLua.JITBUILDTYPE.GC64);
            SLua.LuajitGen.compileLuaJit(files, dests, SLua.JITBUILDTYPE.X86);
            #else
            SLua.LuajitGen.compileLuaJit(files, dests64, SLua.JITBUILDTYPE.X64);
            SLua.LuajitGen.compileLuaJit(files, dests, SLua.JITBUILDTYPE.X86);
            #endif

            //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();
        }
コード例 #5
0
        public static uint CreateStreamingFileManifest(AssetBundleManifest assetBundleManifest)
        {
            var allABs             = assetBundleManifest.GetAllAssetBundles();
            var bundlesWithVariant = assetBundleManifest.GetAllAssetBundlesWithVariant();

            var streamingManifest = ScriptableObject.CreateInstance(typeof(FileManifest)) as FileManifest;
            //读取 bundlesWithVariant
            var MyVariant = new string[bundlesWithVariant.Length];

            for (int i = 0; i < bundlesWithVariant.Length; i++)
            {
                var curSplit = bundlesWithVariant[i].Split('.');
                MyVariant[i] = bundlesWithVariant[i];
            }
            //读取abinfo
            List <ABInfo> allABInfos = new List <ABInfo>();

            foreach (var abs in allABs)
            {
                var abInfo       = new ABInfo(abs, 0, 0, 0);
                var dependencies = assetBundleManifest.GetAllDependencies(abs);
                abInfo.dependencies = dependencies;
                allABInfos.Add(abInfo);
            }

            //fill data
            streamingManifest.allAbInfo = allABInfos;
            streamingManifest.allAssetBundlesWithVariant = bundlesWithVariant;
            streamingManifest.appNumVersion    = CodeVersion.APP_NUMBER;
            streamingManifest.newAppNumVersion = CodeVersion.APP_NUMBER;
            streamingManifest.version          = CodeVersion.APP_VERSION;

            //create asset
            string tmpPath = EditorUtils.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath);

            EditorUtils.CheckDirectory(tmpPath);
            var    crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME);
            string assetPath     = "Assets/" + EditorUtils.TmpPath + crc32filename + ".asset";

            AssetDatabase.CreateAsset(streamingManifest, assetPath);
            //build assetbundle
            string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME);

            BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, DefaultBuildAssetBundleOptions);

            streamingManifest.WriteToFile("Assets/" + EditorUtils.TmpPath + "BuildStreamingAssetsManifest.txt");
            Debug.LogFormat("FileManifest  Path = {0}/{1};", CUtils.realStreamingAssetsPath, crc32outfilename);
            return(0);
        }
コード例 #6
0
ファイル: ExportResources.cs プロジェクト: lonecolonel/hugula
        public static void doExportLua(string rootPath)
        {
            EditorUtils.CheckstreamingAssetsPath();
            string OutLuaBytesPath = EditorUtils.GetLuaBytesResourcesPath();

            AssetDatabase.DeleteAsset(OutLuaBytesPath);
            EditorUtils.GetLuaBytesResourcesPath();

            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            var files   = Directory.GetFiles(rootPath, "*.lua", SearchOption.AllDirectories);
            var dests   = new string[files.Length];
            var dests64 = new string[files.Length];

            for (int i = 0; i < files.Length; i++)
            {
                string xfile = files[i].Remove(0, rootPath.Length + 1);
                xfile = xfile.Replace("\\", "+").Replace("/", "+");
                string file     = files[i].Replace("\\", "/");
                string dest     = OutLuaBytesPath + "/" + CUtils.GetRightFileName(xfile);
                string destName = dest.Substring(0, dest.Length - 3) + "bytes";

                System.IO.File.Copy(file, destName, true);

                sb.AppendFormat("\r\n {0}   ({1}) ", file, destName);
            }

            string tmpPath = EditorUtils.GetAssetTmpPath();

            EditorUtils.CheckDirectory(tmpPath);
            string outPath = Path.Combine(tmpPath, "lua_export_log.txt");

            Debug.Log("write to path=" + outPath);
            using (StreamWriter sr = new StreamWriter(outPath, false)) {
                sr.Write(sb.ToString());
            }

            EditorUtility.ClearProgressBar();
        }
コード例 #7
0
        private static void CopyFileToSplitFolder(Dictionary <string, ABInfo> updateList)
        {
            string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName);  //总的资源目录
            // ExportResources.CheckDirectory(updateOutPath);
            string verPath = Path.Combine(UpdateOutVersionPath, ResFolderName); //特定版本资源目录用于资源备份
            // ExportResources.CheckDirectory(verPath);

            int allLen = updateList.Count;
            int i      = 0;

            Debug.LogFormat("CopyFileToSplitFolder.Count = {0}", updateList.Count);
            EditorUtility.DisplayProgressBar("Copy Change AssetBundle File", "copy file to " + updateOutPath + updateList.Count, 0.09f);

            string        sourcePath;
            string        outfilePath, outfileVerionPath;
            string        key, extension;
            uint          crc  = 0;
            StringBuilder erro = new StringBuilder();

            foreach (var k in updateList)
            {
                key = k.Key;//CUtils.GetAssetBundleName(k.Key);
                // Debug.LogFormat(" update file = {0},{1},{2};", k.Key, k.Value.abName, k.Value.assetPath);
                if (string.IsNullOrEmpty(k.Value.assetPath))
                {
                    continue;
                }
                sourcePath = Path.Combine(Application.dataPath, k.Value.assetPath);
                if (!File.Exists(sourcePath)) //
                {
                    string e = string.Format("copy file ({0}) not Exists ", sourcePath);
                    Debug.LogWarning(e);
                    erro.AppendLine(e);
                    continue;
                }
                extension = System.IO.Path.GetExtension(key);
                crc       = (uint)k.Value.crc32;
                if (crc != 0)
                {
                    if (string.IsNullOrEmpty(extension))
                    {
                        key = EditorUtils.InsertAssetBundleName(key + Common.CHECK_ASSETBUNDLE_SUFFIX, "_" + crc.ToString());
                    }
                    else if (extension == Common.DOT_BYTES)
                    {
                        key = key.Replace(extension, Common.CHECK_ASSETBUNDLE_SUFFIX);
                        key = EditorUtils.InsertAssetBundleName(key, "_" + crc.ToString());//
                    }
                    else
                    {
                        key = EditorUtils.InsertAssetBundleName(key, "_" + crc.ToString());//
                    }
                }
                outfilePath       = Path.Combine(updateOutPath, key);
                outfileVerionPath = Path.Combine(verPath, key);
                // Debug.LogFormat("{0} copy to {1}", outfilePath, outfileVerionPath);
                //
                uint filelen     = 0;
                uint copyFileCrc = 0;

                // var resType = HugulaSetting.instance.backupResType;
                // if (resType == CopyResType.VerResFolder)
                // {
                FileHelper.CheckCreateFilePathDirectory(outfileVerionPath);
                File.Copy(sourcePath, outfileVerionPath, true);    // copy to v{d}/res folder
                copyFileCrc = CrcCheck.GetLocalFileCrc(outfileVerionPath, out filelen);
                // }

                // if (resType == CopyResType.OneResFolder)
                // {
                //     FileHelper.CheckCreateFilePathDirectory(outfilePath);
                //     File.Copy(sourcePath, outfilePath, true);// copy to /res folder
                //     copyFileCrc = CrcCheck.GetLocalFileCrc(outfilePath, out filelen);
                // }

                //check file crc
                if (copyFileCrc != crc)
                {
                    string e = string.Format("crc(source{0}!=copy{1}),path={2}", crc, copyFileCrc, outfilePath);
                    Debug.LogError(e);
                    erro.AppendLine(e);
                }
                EditorUtility.DisplayProgressBar("copy file to split folder " + updateOutPath, " copy file  =>" + i.ToString() + "/" + allLen.ToString(), i / allLen);
                i++;
            }
            Debug.Log(" copy  file complete!");
            EditorUtility.ClearProgressBar();
            string errContent = erro.ToString();

            if (!string.IsNullOrEmpty(errContent))
            {
                string tmpPath = EditorUtils.GetAssetTmpPath();
                EditorUtils.CheckDirectory(tmpPath);
                string outPath = Path.Combine(tmpPath, "error.txt");
                Debug.Log("write to path=" + outPath);
                using (StreamWriter sr = new StreamWriter(outPath, true))
                {
                    sr.WriteLine(" Error : " + System.DateTime.Now.ToString());
                    sr.Write(errContent);
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// Creates the streaming crc list.
        /// </summary>
        /// <param name="sb">Sb.</param>
        public static uint CreateStreamingCrcList(FileManifest sb, string fileListName, bool firstExists = false, bool copyToResFolder = false)
        {
            sb.appNumVersion    = CodeVersion.APP_NUMBER;
            sb.newAppNumVersion = CodeVersion.APP_NUMBER;
            sb.version          = CodeVersion.APP_VERSION;

            var    crc32filename = CUtils.GetAssetName(fileListName);
            string tmpPath       = EditorUtils.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath);

            EditorUtils.CheckDirectory(tmpPath);

            string assetPath = "Assets/" + EditorUtils.TmpPath + crc32filename + ".asset";

            EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f);
            AssetDatabase.CreateAsset(sb, assetPath);

            string crc32outfilename = CUtils.GetRightFileName(fileListName);
            // Debug.Log("write to path=" + outPath);
            //读取crc
            string abPath     = string.Empty;
            string resOutPath = null;
            uint   fileSize   = 0;
            uint   fileCrc    = 0;

            if (copyToResFolder)
            {
                resOutPath = tmpPath;//Path.Combine(tmpPath, ResFolderName); //Path.Combine(SplitPackage.UpdateOutPath, ResFolderName);
                abPath     = Path.Combine(resOutPath, crc32outfilename);
                BuildScript.BuildABs(new string[] { assetPath }, resOutPath, crc32outfilename, DefaultBuildAssetBundleOptions);
                fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize);

                //copy crc list
                FileInfo finfo = new FileInfo(abPath);
                // var resType = HugulaSetting.instance.backupResType;
                // if (resType == CopyResType.VerResFolder)
                // {
                string verPath = Path.Combine(UpdateOutVersionPath, ResFolderName);    //特定版本资源目录用于资源备份
                string newName = Path.Combine(verPath, EditorUtils.InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString()));
                FileHelper.CheckCreateFilePathDirectory(newName);
                if (File.Exists(newName))
                {
                    File.Delete(newName);
                }
                finfo.CopyTo(newName);
                // }

                // if (resType == CopyResType.OneResFolder)
                // {
                //     string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName);//总的资源目录
                //     string newName = Path.Combine(updateOutPath, EditorUtils.InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString()));
                //     FileHelper.CheckCreateFilePathDirectory(newName);
                //     if (File.Exists(newName)) File.Delete(newName);
                //     finfo.CopyTo(newName);
                // }
            }
            else
            {
                abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename);
                BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, DefaultBuildAssetBundleOptions);
                fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize);
            }
            // CrcCheck.Clear();

            //copy first crc list
            if (!firstExists && File.Exists(abPath)) //如果没有首包 copy first package
            {
                string crc32FirstOutName = CUtils.InsertAssetBundleName(crc32outfilename, "_v" + CodeVersion.CODE_VERSION.ToString());
                string destFirst         = Path.Combine(UpdateOutPath, crc32FirstOutName);
                Debug.LogFormat("abpath={0},destFirst={1}:", abPath, destFirst);
                File.Copy(abPath, destFirst, true);
            }

            EditorUtility.ClearProgressBar();
            // File.Delete(assetPath);

            Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath);

            return(fileCrc);
        }
コード例 #9
0
        public static void GenerateAssetBundlesMd5Mapping(string[] allAssets)
        {
            string info = "Generate AssetBundles Md5Mapping ";

            EditorUtility.DisplayProgressBar("GenerateAssetBundlesMd5Mapping", info, 0);
            string        speciallyPath = "Assets/Config/Lan/";
            string        luaPath       = "Assets/Lua/";
            AssetImporter import        = null;
            float         i             = 0;
            float         allLen        = allAssets.Length;
            string        name          = "";
            string        nameMd5       = "";

            //name mapping
            StringBuilder nameSb = new StringBuilder();

            //asset map
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("return {");

            foreach (string path in allAssets)
            {
                import = AssetImporter.GetAtPath(path);
                string line = string.Empty;

                if (import != null && string.IsNullOrEmpty(import.assetBundleName) == false)
                {
                    string abName = import.assetBundleName;
                    name = CUtils.GetAssetName(path).ToLower();

                    if (!string.IsNullOrEmpty(import.assetBundleVariant))
                    {
                        abName = import.assetBundleName + "." + import.assetBundleVariant; // line = "{\"" + import.assetBundleName + "\" = { size = \"" + name + "\", path = \"" + path + "\"}},";
                    }
                    line = "[\"" + abName + "\"] = { size = " + GetAssetbundleSize(abName) + ", path = \"" + path + "\"},";
                    sb.AppendLine(line);
                    nameSb.AppendFormat("{0}={1}\r\n", CUtils.GetRightFileName(name), name);
                    if (name.Contains(" "))
                    {
                        Debug.LogWarning(name + " contains space");
                    }
                }
                else if (import != null && path.Contains(speciallyPath))
                {
                    name = CUtils.GetAssetName(path).ToLower();
                    string md5name = CUtils.GetRightFileName(name) + Common.CHECK_ASSETBUNDLE_SUFFIX;
                    line = "[\"" + md5name + "\"] = { size = " + GetAssetbundleSize(md5name) + ", path = \"" + path + "\"},";
                    sb.AppendLine(line);
                    nameSb.AppendFormat("{0}={1}\r\n", md5name, name);
                }
                else if (import != null && path.Contains(luaPath))
                {
                    string luaname    = path.Replace(luaPath, "").Replace("\\", ".").Replace("/", ".");
                    string luacname   = luaname.Replace(".lua", "").Replace(".", "+");
                    string luaMd5Name = CUtils.GetRightFileName(luacname);

                    line = "[\"" + luaMd5Name + "\"] = { size = " + GetAssetbundleSize(luaMd5Name + ".bytes") + ", path = \"" + path + "\"},";
                    sb.AppendLine(line);
                    nameSb.AppendFormat("{0}={1}\r\n", luaMd5Name, luaname);
                }
                EditorUtility.DisplayProgressBar("Generate AssetBundles Md5Mapping", info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);

                i++;
            }

            string[] special = new string[] { CUtils.platform, Common.CONFIG_CSV_NAME, Common.CRC32_FILELIST_NAME, Common.CRC32_VER_FILENAME };
            foreach (string p in special)
            {
                name    = EditorUtils.GetAssetBundleName(p);
                nameMd5 = CUtils.GetRightFileName(name);
                string line = "[\"" + nameMd5 + "\"] ={ size = 0, path = \"" + p + "\" },";
                sb.AppendLine(line);
                nameSb.AppendFormat("{0}={1}\r\n", CUtils.GetRightFileName(name), name);
            }

            sb.AppendLine("}");
            string tmpPath = Path.Combine(Application.dataPath, EditorUtils.TmpPath);

            EditorUtils.CheckDirectory(tmpPath);
            EditorUtility.DisplayProgressBar("Generate AssetBundles Md5Mapping", "write file to Assets/" + EditorUtils.TmpPath + "Md5Mapping.txt", 0.99f);

            string outPath = Path.Combine(tmpPath, "md5_asset_mapping.txt");

            Debug.Log("write to path=" + outPath);
            using (StreamWriter sr = new StreamWriter(outPath, false))
            {
                sr.Write(sb.ToString());
            }

            outPath = Path.Combine(tmpPath, "md5_name_mapping.txt");
            Debug.Log("write to path=" + outPath);
            using (StreamWriter sr = new StreamWriter(outPath, false))
            {
                sr.Write(nameSb.ToString());
            }
            EditorUtility.ClearProgressBar();
            Debug.Log(info + " Complete! Assets/" + EditorUtils.TmpPath + "md5_asset_mapping.txt");
        }
コード例 #10
0
        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();
        }