示例#1
0
    public static void EncodeLuaFile(string srcFile, string outFile)
    {
        if (!srcFile.ToLower().EndsWith(".lua"))
        {
            File.Copy(srcFile, outFile, true);
            return;
        }
        bool   isWin   = true;
        string luaexe  = string.Empty;
        string args    = string.Empty;
        string exedir  = string.Empty;
        string currDir = Directory.GetCurrentDirectory();

        if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            isWin  = true;
            luaexe = "luajit.exe";
            args   = "-b " + srcFile + " " + outFile;
            exedir = AppDataPath.Replace("assets", "") + "LuaEncoder/luajit/";
        }
        else if (Application.platform == RuntimePlatform.OSXEditor)
        {
            isWin  = false;
            luaexe = "./luac";
            args   = "-o " + outFile + " " + srcFile;
            exedir = AppDataPath.Replace("assets", "") + "LuaEncoder/luavm/";
        }
        Directory.SetCurrentDirectory(exedir);
        ProcessStartInfo info = new ProcessStartInfo();

        info.FileName        = luaexe;
        info.Arguments       = args;
        info.WindowStyle     = ProcessWindowStyle.Hidden;
        info.ErrorDialog     = true;
        info.UseShellExecute = isWin;
        LuaUtil.Log(info.FileName + " " + info.Arguments);

        Process pro = Process.Start(info);

        pro.WaitForExit();
        Directory.SetCurrentDirectory(currDir);
    }