Пример #1
0
        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();
        }
Пример #2
0
        public static void BuildAssetBundles()
        {
            CUtils.DebugCastTime("Time HandleUpdateMaterail End");
            EditorUtils.CheckstreamingAssetsPath();
            CUtils.DebugCastTime("Time CheckstreamingAssetsPath End");
            var ab = BuildPipeline.BuildAssetBundles(EditorUtils.GetOutPutPath(), SplitPackage.DefaultBuildAssetBundleOptions, target);

            SplitPackage.CreateStreamingFileManifest(ab);
            CUtils.DebugCastTime("Time BuildPipeline.BuildAssetBundles End");
        }
Пример #3
0
        public static void exportConfig()
        {
            var files = AssetDatabase.GetAllAssetPaths().Where(p =>
                                                               p.StartsWith("Assets/Config") && !p.StartsWith("Assets/Config/Lan") &&
                                                               p.EndsWith(".bytes")
                                                               ).ToArray();

            EditorUtils.CheckstreamingAssetsPath();

            if (files.Length > 0)
            {
                string cname = CUtils.GetRightFileName(Common.CONFIG_CSV_NAME);
                BuildScript.BuildABsOneByOne(files.ToArray(), null, SplitPackage.DefaultBuildAssetBundleOptions);
                Debug.LogFormat(" Config export {0}", files.Length);
            }
        }
Пример #4
0
        public static void exportLanguage()
        {
            var files = AssetDatabase.GetAllAssetPaths().Where(p =>
                                                               p.StartsWith("Assets/Config/Lan") &&
                                                               p.EndsWith(".csv")
                                                               ).ToArray();

            EditorUtils.CheckstreamingAssetsPath();
            // BuildScript.ch
            foreach (string abPath in files)
            {
                string            name   = CUtils.GetAssetName(abPath);
                string            abName = CUtils.GetRightFileName(name + Common.CHECK_ASSETBUNDLE_SUFFIX);
                Hugula.BytesAsset bytes  = (Hugula.BytesAsset)ScriptableObject.CreateInstance(typeof(Hugula.BytesAsset));
                bytes.bytes = File.ReadAllBytes(abPath);
                string bytesPath = string.Format("Assets/Tmp/{0}.asset", name);
                AssetDatabase.CreateAsset(bytes, bytesPath);
                BuildScript.BuildABs(new string[] { bytesPath }, null, abName, SplitPackage.DefaultBuildAssetBundleOptions);
                Debug.Log(name + " " + abName + " export");
            }
        }
Пример #5
0
        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();
        }
Пример #6
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();
        }