예제 #1
0
        /// <summary>
        /// 模拟构建
        /// </summary>
        public static void SimulateBuild()
        {
            string          defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
            BuildParameters buildParameters   = new BuildParameters();

            buildParameters.OutputRoot        = defaultOutputRoot;
            buildParameters.BuildTarget       = EditorUserBuildSettings.activeBuildTarget;
            buildParameters.BuildMode         = EBuildMode.SimulateBuild;
            buildParameters.BuildVersion      = 999;
            buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;

            AssetBundleBuilder builder = new AssetBundleBuilder();
            bool buildResult           = builder.Run(buildParameters);

            if (buildResult)
            {
                string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(buildParameters.OutputRoot, buildParameters.BuildTarget);
                _manifestFilePath = $"{pipelineOutputDirectory}_{EBuildMode.SimulateBuild}/{YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildVersion)}";
            }
            else
            {
                _manifestFilePath = null;
            }
        }
        /// <summary>
        /// 创建补丁清单文件到输出目录
        /// </summary>
        private void CreatePatchManifestFile(AssetBundleBuilder.BuildParametersContext buildParameters,
                                             BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext)
        {
            int resourceVersion = buildParameters.Parameters.BuildVersion;

            // 创建新补丁清单
            PatchManifest patchManifest = new PatchManifest();

            patchManifest.EnableAddressable = buildParameters.Parameters.EnableAddressable;
            patchManifest.ResourceVersion   = buildParameters.Parameters.BuildVersion;
            patchManifest.BuildinTags       = buildParameters.Parameters.BuildinTags;
            patchManifest.BundleList        = GetAllPatchBundle(buildParameters, buildMapContext, encryptionContext);
            patchManifest.AssetList         = GetAllPatchAsset(buildParameters, buildMapContext, patchManifest);

            // 创建补丁清单文件
            string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";

            BuildRunner.Log($"创建补丁清单文件:{manifestFilePath}");
            PatchManifest.Serialize(manifestFilePath, patchManifest);

            // 创建补丁清单哈希文件
            string manifestHashFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}";
            string manifestHash         = HashUtility.FileMD5(manifestFilePath);

            BuildRunner.Log($"创建补丁清单哈希文件:{manifestHashFilePath}");
            FileUtility.CreateFile(manifestHashFilePath, manifestHash);

            // 创建静态版本文件
            string staticVersionFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}";
            string staticVersion         = resourceVersion.ToString();

            BuildRunner.Log($"创建静态版本文件:{staticVersionFilePath}");
            FileUtility.CreateFile(staticVersionFilePath, staticVersion);
        }