Exemplo n.º 1
0
    /// <summary>
    /// 压缩文件
    /// </summary>
    /// <param name="target"></param>
    /// <returns></returns>
    private static bool DoCompress(string srcDir, string destFileName, string saveAs)
    {
        if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
        {
            return(true);
        }

        try
        {
            EditorUtility.DisplayProgressBar("give me a sec", "ready to compress", 0.0f);

            string zip      = BUILD_ASSETS_PATH + "/Tools/7z.exe";
            string fileName = srcDir + "../" + saveAs;
            string dir      = Path.GetDirectoryName(fileName);
            fileName = CFile.GetUnusedFileName(dir + "/", Path.GetFileNameWithoutExtension(fileName), ".zip") + ".zip";
            fileName = dir + "/" + fileName;
            string args = string.Format("-tzip a {0} {1}/*", fileName, srcDir);

            using (var process = new System.Diagnostics.Process())
            {
                process.StartInfo.FileName  = zip;
                process.StartInfo.Arguments = args;
                //process.StartInfo.WorkingDirectory = BUILD_ASSETS_PATH + "Inno/";
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.CreateNoWindow         = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.StandardOutputEncoding = Encoding.GetEncoding("gb2312");
                process.Start();

                Debug.Log("exec=>" + zip + " " + args);

                float progress = 0.0f;
                while (!process.StandardOutput.EndOfStream)
                {
                    var str = process.StandardOutput.ReadLine();
                    progress += 0.001f;
                    EditorUtility.DisplayProgressBar("compressing", str, progress);
                }

                process.WaitForExit();

                if (process.ExitCode != 0)
                {
                    return(false);
                }
            }

            EditorUtility.ClearProgressBar();
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
            return(false);
        }

        return(true);
    }
Exemplo n.º 2
0
    public static bool BuildPlatform(ProjectBuildData data, bool compress, bool saveAs, bool encrypt, bool buildAsSetup)
    {
        Debug.Log(">------------------ start build : " + data.Name + "   target:" + data.Target.ToString());

        EditorUserBuildSettings.SwitchActiveBuildTarget(data.Target);

        string symDefine = data.SymbolDefine;

        if (!encrypt)
        {
            if (!symDefine.Contains("DISABLE_ENCRYPT_FILES"))
            {
                symDefine += ";DISABLE_ENCRYPT_FILES";
            }
        }

        ApplyPlayerSettings(data);

        PlayerSettings.SetScriptingDefineSymbolsForGroup(
            EditorUserBuildSettings.selectedBuildTargetGroup,
            symDefine
            );

        AssetDatabase.Refresh();

        //获取SDK目录
        //string sdkDirPath = GetSDKDir();
        //设置放置apk文件目录

        BuildOptions options = BuildOptions.None;

        string dir = RELEASE_PATH + PlayerSettings.companyName + "/" + EditorUserBuildSettings.activeBuildTarget + "/";

        if (saveAs)
        {
            dir = EditorUtility.OpenFolderPanel("Please select the target directory", dir, "") + "/";
        }

        string fileName       = "";
        string destFileName   = "";
        string saveAsFileName = "";
        bool   compressNeeds  = compress;

        //string apkPath = SettingAPKDir();
        if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
        {
            fileName  = CFile.GetUnusedFileName(dir, PlayerSettings.companyName, ".apk");
            fileName += "_V" + data.Version;
            if (!encrypt)
            {
                fileName += ".apk";
            }

            destFileName  += fileName;
            saveAsFileName = destFileName;
        }
        else if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows)
        {
            if (compressNeeds || buildAsSetup)
            {
                saveAsFileName = PlayerSettings.companyName + "_V" + data.Version;
                fileName       = CFile.GetUnusedFileName(dir, saveAsFileName, ".exe");
                saveAsFileName = fileName;
                destFileName   = PlayerSettings.companyName + ".exe";

                dir += "__tmp/";
            }
            else
            {
                fileName       = CFile.GetUnusedFileName(dir, PlayerSettings.companyName, ".exe");
                destFileName   = fileName;
                destFileName  += "_V" + data.Version + ".exe";
                saveAsFileName = destFileName;
            }
        }
        else if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS)
        {
            if (compressNeeds)
            {
                dir += "__tmp/";
            }

            destFileName  += PlayerSettings.companyName;
            destFileName  += "_" + data.Version;
            saveAsFileName = destFileName;
        }
        else
        {
            destFileName  += PlayerSettings.companyName;
            saveAsFileName = destFileName;
        }

        Debug.Log("destFileName:" + destFileName);
        Debug.Log("saveAsFileName:" + saveAsFileName);

        /*//SDK转移
         * if (!CopySDK(companyName, EditorUserBuildSettings.activeBuildTarget))
         * {
         *  Debug.LogError("CopySDK Error.");
         *  return false;
         * }*/

        //TODO 拷贝随包游戏

        /*if (!CopyAssetbundles(data))
         * {
         *  Debug.LogError("Copy Assetbundles Error");
         *  return false;
         * }*/


        //生成ab包

        /*if (!BuildAssetBundle(data))
         * {
         *  return false;
         * }*/

        //拷贝


        //标题画面更改
        if (!CopyLogo())
        {
            return(false);
        }

        if (!CopyAssetbundles(data))
        {
            return(false);
        }

        if (!CopyCustomAssets(data))
        {
            return(false);
        }

        //保存配置文件
        if (!SaveConfig(data, encrypt))
        {
            return(false);
        }


        if (encrypt)
        {
            options |= BuildOptions.AcceptExternalModificationsToPlayer;
        }

        //保存配置文件
        if (!BuildPlayer(dir, destFileName, options))
        {
            return(false);
        }

        if (encrypt && !Encrypt(dir, destFileName))
        {
            return(false);
        }

        //处理编译完成后问题
        if (compressNeeds && !DoCompress(dir, destFileName, saveAsFileName))
        {
            return(false);
        }

        if (buildAsSetup && !MakeSetup(dir, destFileName, saveAsFileName))
        {
            return(false);
        }

        //处理编译完成后问题
        if (!BuildEnd(dir))
        {
            return(false);
        }

        PlayerSettings.SetScriptingDefineSymbolsForGroup(
            EditorUserBuildSettings.selectedBuildTargetGroup,
            data.SymbolDefine
            );

        AssetDatabase.Refresh();

        Debug.Log(">------------------ Build finished! Name: " + data.Name + "   Target: " + EditorUserBuildSettings.activeBuildTarget);

        return(true);
    }