Exemple #1
0
        static void exportLuajit(string res, string ext, string jitluadir, JITBUILDTYPE buildType)
        {
            // delete
            AssetDatabase.DeleteAsset(jitluadir);

            var files = Directory.GetFiles(res, ext, SearchOption.AllDirectories);
            var dests = new string[files.Length];

            for (int i = 0; i < files.Length; i++)
            {
                string xfile = files[i].Remove(0, res.Length);
                xfile = xfile.Replace("\\", "/");
                string file = files[i].Replace("\\", "/");

                string dest     = jitluadir + "/" + xfile;
                string destName = dest.Substring(0, dest.Length - 3) + "bytes";

                string destDir = Path.GetDirectoryName(destName);

                if (!Directory.Exists(destDir))
                {
                    Directory.CreateDirectory(destDir);
                }

                files[i] = file;
                dests[i] = destName;
                // Debug.Log(file + ":" + destName);
            }


            compileLuaJit(files, dests, buildType);
            AssetDatabase.Refresh();
        }
Exemple #2
0
        public static void compileLuaJit(string[] src, string[] dst, JITBUILDTYPE buildType)
        {
            UnityEngine.Debug.Log("compileLuajit");
#if !UNITY_EDITOR_OSX
            string workDir = Application.dataPath + "/../jit/";
            Dictionary <JITBUILDTYPE, string> build = new Dictionary <JITBUILDTYPE, string>
            {
                { JITBUILDTYPE.X86, Application.dataPath + "/../jit/win/x86/luajit.exe" },
                { JITBUILDTYPE.X64, Application.dataPath + "/../jit/win/x64/luajit.exe" },
                { JITBUILDTYPE.GC64, Application.dataPath + "/../jit/win/gc64/luajit.exe" },
            };
            string    exePath = build[buildType];
            Process[] psList  = new Process[src.Length];
#else
            string workDir = Application.dataPath + "/../jit/";
            Dictionary <JITBUILDTYPE, string> build = new Dictionary <JITBUILDTYPE, string>
            {
                { JITBUILDTYPE.X86, Application.dataPath + "/../jit/mac/x86/luajit" },
                { JITBUILDTYPE.X64, Application.dataPath + "/../jit/mac/x64/luajit" },
                { JITBUILDTYPE.GC64, Application.dataPath + "/../jit/mac/gc64/luajit" },
            };

            string exePath = build[buildType];
            // Process[] psList = new Process[ src.Length ];
#endif

            for (int i = 0; i < src.Length; i++)
            {
                string srcLua = Application.dataPath + "/../" + src[i];
                string dstLua = Application.dataPath + "/../" + dst[i];
                string cmd    = " -b " + srcLua + " " + dstLua;


#if !UNITY_EDITOR_OSX
                psList[i] = StartProcess(exePath, cmd, workDir);
#else
                var ps = StartProcess(exePath, cmd, workDir);
                ps.WaitForExit();
#endif
            }


#if !UNITY_EDITOR_OSX
            foreach (var ps in psList)
            {
                if (ps != null && !ps.HasExited)
                {
                    ps.WaitForExit();
                }
            }
#endif
        }
Exemple #3
0
        public static void compileLuaJit(string[] src, string[] dst, JITBUILDTYPE buildType)
        {
            UnityEngine.Debug.Log("compileLuajit");
            string workDir = Application.dataPath + "/../jit/";

#if !UNITY_EDITOR_OSX
            Dictionary <JITBUILDTYPE, string> build = new Dictionary <JITBUILDTYPE, string>
            {
                { JITBUILDTYPE.X86, Application.dataPath + "/../jit/win/x86/luajit.exe" },
                { JITBUILDTYPE.X64, Application.dataPath + "/../jit/win/x64/luajit.exe" },
                { JITBUILDTYPE.GC64, Application.dataPath + "/../jit/win/gc64/luajit.exe" },
            };
#else
            Dictionary <JITBUILDTYPE, string> build = new Dictionary <JITBUILDTYPE, string>
            {
                { JITBUILDTYPE.X86, Application.dataPath + "/../jit/mac/x86/luajit" },
                { JITBUILDTYPE.X64, Application.dataPath + "/../jit/mac/x64/luajit" },
                { JITBUILDTYPE.GC64, Application.dataPath + "/../jit/mac/gc64/luajit" },
            };
#endif
            string    exePath = build[buildType];
            Process[] psList  = new Process[src.Length];

            for (int i = 0; i < src.Length; i++)
            {
                string srcLua = Application.dataPath + "/../" + src[i];
                string dstLua = Application.dataPath + "/../" + dst[i];
                string cmd    = " -b " + srcLua + " " + dstLua;

                ProcessStartInfo StartInfo = new ProcessStartInfo();
                StartInfo.FileName         = exePath;
                StartInfo.Arguments        = cmd;
                StartInfo.CreateNoWindow   = true;
                StartInfo.UseShellExecute  = false;
                StartInfo.WorkingDirectory = workDir;
                Process ps = new Process();
                ps.StartInfo = StartInfo;
                psList[i]    = ps;
            }

            try
            {
                int totalSize       = src.Length;
                int workThreadCount = Environment.ProcessorCount * 2 + 2;
                int batchCount      = (int)Math.Ceiling(totalSize / (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 >= totalSize)
                        {
                            break;
                        }
                        var ps = psList[fileIndex];
                        ps.Start();
                    }

                    bool   fail      = false;
                    string fileName  = null;
                    string arguments = null;
                    for (int i = offset; i < offset + processIndex; ++i)
                    {
                        var ps = psList[i];
                        ps.WaitForExit();
                        if (ps.ExitCode != 0 && !fail)
                        {
                            fail      = true;
                            fileName  = ps.StartInfo.FileName;
                            arguments = ps.StartInfo.Arguments;
                        }
                        ps.Dispose();
                    }

                    if (fail)
                    {
                        throw new Exception(string.Format("Luajit Compile Fail.FileName={0},Arg={1}", fileName, arguments));
                    }
                }
            }
            finally
            {
                foreach (var ps in psList)
                {
                    ps.Dispose();
                }
            }
        }
    public static void ExportLua()
    {
        string path = Path.GetFullPath(Path.Combine(Application.dataPath, "Lua"));

        string tmpPath = Path.GetFullPath(Path.Combine(Application.dataPath, "tmp"));

        DirectoryDelete(tmpPath);
        CheckDirectory(tmpPath);

        List <string> sourceFiles = new List <string>();
        List <string> exportNames = new List <string>();

        List <string> files = getAllChildFiles(path, "lua");

        foreach (string filePath in files)
        {
            string file = Path.GetFullPath(filePath);
            if (!file.EndsWith(".lua"))
            {
                continue;
            }
            string byteFileName = file.Replace(path, "");
            if (byteFileName.StartsWith("\\") || byteFileName.StartsWith("/"))
            {
                byteFileName = byteFileName.Substring(1);
            }

            byteFileName = byteFileName.Replace(".lua", ".bytes").Replace("\\", "_").Replace("/", "_");
            exportNames.Add("Assets/tmp/" + byteFileName);
            //File.Copy(file, Path.Combine(tmpPath, byteFileName), true);
            string srcFile = file.Replace(Path.GetFullPath(Application.dataPath), "");
            srcFile = "Assets" + srcFile;
            Debug.Log(srcFile);
            sourceFiles.Add(srcFile);
        }
        //打包config
        string cfgPath = Path.GetFullPath(Path.Combine(Application.dataPath, "Config/config"));

        Debug.Log("Export Lua Path:" + cfgPath);
        List <string> cfgFiles = getAllChildFiles(cfgPath, "lua");

        foreach (string filePath in cfgFiles)
        {
            string file = Path.GetFullPath(filePath);
            if (!file.EndsWith(".lua"))
            {
                continue;
            }
            string byteFileName = file.Replace(cfgPath, "");
            if (byteFileName.StartsWith("\\") || byteFileName.StartsWith("/"))
            {
                byteFileName = byteFileName.Substring(1);
            }
            byteFileName = byteFileName.Replace(".lua", ".bytes").Replace("\\", "_").Replace("/", "_");
            byteFileName = "config_" + byteFileName;
            exportNames.Add("Assets/tmp/" + byteFileName);
            //File.Copy(file, Path.Combine(tmpPath, byteFileName), true);
            string srcFile = file.Replace(Path.GetFullPath(Application.dataPath), "");
            srcFile = "Assets" + srcFile;
            sourceFiles.Add(srcFile);
        }

        System.Threading.Thread.Sleep(1000);
        AssetDatabase.Refresh();

        JITBUILDTYPE jbt = GetLuaJitBuildType(EditorUserBuildSettings.activeBuildTarget);

        SLua.LuajitGen.compileLuaJit(sourceFiles.ToArray(), exportNames.ToArray(), jbt);

        System.Threading.Thread.Sleep(1000);
        AssetDatabase.Refresh();

        ExportAssetBundle.BuildAssetBundles(exportNames.ToArray(), "Assets/tmp", "luaout.bytes", optionsDefault);

        string strOutputPath = Path.Combine(Application.streamingAssetsPath, PathUtil.Platform);

        CheckDirectory(strOutputPath);

        string luaoutPath    = Path.Combine(Application.dataPath, "tmp/luaout.bytes");
        string luaExportPath = Path.GetFullPath(Path.Combine(strOutputPath, "lua.u3d"));

        byte[] by      = File.ReadAllBytes(luaoutPath);
        byte[] encrypt = CryptographHelper.Encrypt(by, KeyVData.Instance.KEY, KeyVData.Instance.IV);
        File.WriteAllBytes(luaExportPath, encrypt);

        DirectoryDelete(tmpPath);

        Debug.Log(luaExportPath + " export.");

        System.Threading.Thread.Sleep(100);
        AssetDatabase.Refresh();
    }