Esempio n. 1
0
    /// <summary>
    /// save hotfixUrl and hotfix macro
    /// </summary>
    /// <param name="para"></param>
    /// <returns></returns>
    private static bool HandleHotFix(GameBuilderParameter para)
    {
        if (para.EnableHotFix)
        {
            var url = para.HotFixUrl;

            if (String.IsNullOrEmpty(url))
            {
                Debug.LogError("BuildGame HotFixUrl is empty");
                return(false);
            }

            FileUtils.WriteFile(GameConst.GameResourceRootDir + "/" + VersionConst.CustomSeverUrlFileName, url);

            url = FileUtils.RemoveLastSeparator(url);
            FileUtils.DelFile(GameConst.GameResourceRootDir + "/" + VersionConst.CustomSeverUrlFileName);
            FileUtils.WriteFile(GameConst.GameResourceRootDir + "/" + VersionConst.CustomSeverUrlFileName, url);

            para.MacroDefines = BuilderEditorUtils.RemoveMacro(para.MacroDefines, BuilderEditorUtils.NoHotFixMacro);
            para.MacroDefines =
                BuilderEditorUtils.AddMacro(para.MacroDefines, BuilderEditorUtils.CustomServerHotFixMacro);
        }
        else
        {
            para.MacroDefines =
                BuilderEditorUtils.RemoveMacro(para.MacroDefines, BuilderEditorUtils.CustomServerHotFixMacro);
            para.MacroDefines = BuilderEditorUtils.AddMacro(para.MacroDefines, BuilderEditorUtils.NoHotFixMacro);
        }
        return(true);
    }
Esempio n. 2
0
    /// <summary>
    /// 构建设置
    /// </summary>
    /// <param name="para"></param>
    private static void SetupSetting(GameBuilderParameter para)
    {
        Debug.Log("SetupSetting");
        BuildTarget      buildTarget      = para.BuildTarget;
        BuildTargetGroup buildTargetGroup = PlatformEditorUtils.GetSelectedBuildTargetGroup(buildTarget);

        //EditorUserBuildSettings.SwitchActiveBuildTarget(buildTargetGroup, buildTarget);
        EditorUserBuildSettings.SwitchActiveBuildTarget(buildTarget);

        // 仅当有出包时才处理
        if (para.BuildMode != BuildMode.Patch)
        {
            // 版本号
            PlayerSettings.bundleVersion = para.BuildVersion.GetVersionString();
            //PlayerSettings.applicationIdentifier = para.BundleIdentifier;

            if (buildTarget == BuildTarget.Android)
            {
                PlayerSettings.Android.bundleVersionCode = para.BuildVersion.GetVersionCode();

                if (para.ExportProject)
                {
                    EditorUserBuildSettings.androidBuildSystem =
                        para.UseGradle ? AndroidBuildSystem.Gradle : AndroidBuildSystem.ADT;
                }
                else
                {
                    EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Internal;
                }
            }
            else if (buildTarget == BuildTarget.iOS)
            {
                PlayerSettings.iOS.buildNumber = para.BuildVersion.GetVersionCode().ToString();
            }

            //-如果是多线程渲染版本开启多线程渲染-//
            //PlayerSettings.SetMobileMTRendering(buildTargetGroup, para.Multithreaded);
            PlayerSettings.MTRendering = para.Multithreaded;

            //-打包之前先设置一下 预定义标签, 这时设置的宏,后面的代码不能马上生效,但BuildPlayer可以生效
            string macroDefines = para.MacroDefines;
            if (!String.IsNullOrEmpty(macroDefines))
            {
                macroDefines = para.UseMono2X ?
                               BuilderEditorUtils.AddMacro(macroDefines, "USE_MONO") :
                               BuilderEditorUtils.RemoveMacro(macroDefines, "USE_MONO");

                PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, macroDefines);
            }

            DoMonoSetting(para.UseMono2X, buildTargetGroup);
        }
    }
Esempio n. 3
0
    public static bool BuildGame(GameBuilderParameter para)
    {
        Debug.Log("Build Game Start and Para is:" + para);

        if (!para.BuildVersion.CheckConstraint())
        {
            Debug.LogError("BuildVersion not pass constraint! version:" + para.BuildVersion.GetVersionString());
            return(false);
        }

        try
        {
            if (para.BuildTarget == BuildTarget.iOS)
            {
                para.UseMono2X = false;
                Debug.Log("ios platform always use IL2ccpp. is not will compiler error");
            }

            // 处理热更url
            if (!HandleHotFix(para))
            {
                return(false);
            }
            Debug.Log("Clear " + Application.streamingAssetsPath);
            FileUtils.ClearDirectoryReadOnly(Application.streamingAssetsPath);
            FileUtils.ClearDirectory(Application.streamingAssetsPath);
            SetupSetting(para);

            // build lua bundle
            Debug.Log("Start MarkBundlesNames ");
            ToLuaMenu.MarkBundlesNames();
            Debug.Log("End MarkBundlesNames ");

            if (para.ApplyAllRule)
            {
                Debug.Log("Start ApplyAllRule ");
                AssetBundleRuleUtils.ApplyAll(null, true);
                Debug.Log("ApplyAllRule finish ");
            }

            string sourcePath = Path.Combine(Utility.AssetBundlesOutputPath, Utility.GetPlatformName());
            if (!para.IncreativeBuildAssetBundles)
            {
                Debug.Log("Clear Assetbundle dir:" + sourcePath);
                FileUtils.ClearDirectoryReadOnly(sourcePath);
                FileUtils.ClearDirectory(sourcePath);
                Debug.Log("finish Clear Assetbundle dir:");
            }

            Debug.Log("BuildAssetBundles to " + sourcePath);
            BuildScript.BuildAssetBundles(null, para.BundleCompress ? ToLuaMenu.GetBuildAssetBundleOptions(): BuildAssetBundleOptions.None);
            Debug.Log("BuildAssetBundles finish ");

            Debug.Log("Start CopyDirectory to Streaming");
            FileUtils.CopyDirectory(sourcePath, VersionConst.StreamingVersionPath);
            Debug.Log("Finish CopyDirectory to Streaming");

            // 这个放在下面,不然会被前面的删除掉
            if (para.CopyFmod)
            {
                // -音效引擎相关代码,放在打包资源之后因为会清理打包资源-//
                Debug.Log("CopyToStreamingAssets---------------------------------------");
                //EventManager.DoCopyToStreamingAssets();
                Debug.Log("MasterBankName---------------------------------------");
            }
            Debug.Log("GenHotFixFileListAndCheckConflict");
            AssetBundleRuleUtils.GenHotFixFileListAndCheckConflict();
            bool bOk = true;
            if (para.BuildMode == BuildMode.Patch || para.BuildMode == BuildMode.All)
            {
                Debug.Log("开始生成补丁");
                VersionPatchBuilder patchBuilder = new VersionPatchBuilder(para.BuildTarget, para.BuildVersion, para.BuildNumber);
                if (!patchBuilder.Build())
                {
                    bOk = false;
                }

                Debug.Log("结束生成补丁");
            }

            // 如果要求生成补丁,但补丁失败,则包也
            if (bOk && (para.BuildMode == BuildMode.Package || para.BuildMode == BuildMode.All))
            {
                Debug.Log("开始写入发布时版本信息:" + VersionConst.ReleasedVersionPath);
                // 写入发布版本信息
                SaveReleasedVersionFile(para.BuildVersion, VersionConst.ReleasedVersionPath);
                Debug.Log("结束写入发布时版本信息");

                Debug.Log("开始生成安装包");
                string[] levels = BuilderEditorUtils.GetBuildScenes();
                var      error  = BuildPipeline.BuildPlayer(levels
                                                            , para.OutputPath
                                                            , para.BuildTarget
                                                            , para.BuildOptions);
                if (!string.IsNullOrEmpty(error))
                {
                    Debug.LogError("Build failed: " + error);
                    bOk = false;
                }
                Debug.Log("结束生成安装包");
            }

            return(bOk);
        }
        catch (Exception e)
        {
            Debug.LogError("error BuildGame stderror exception: " + e.Message);
            return(false);
        }
    }