Beispiel #1
0
 /// <summary>
 /// 读取配置
 /// </summary>
 private static void LoadSettingsFromPlayerPrefs(AssetBundleBuilder builder)
 {
     builder.CompressOption          = EditorTools.PlayerGetEnum <AssetBundleBuilder.ECompressOption>(StrEditorCompressOption, AssetBundleBuilder.ECompressOption.Uncompressed);
     builder.IsForceRebuild          = EditorTools.PlayerGetBool(StrEditorIsForceRebuild, false);
     builder.IsAppendHash            = EditorTools.PlayerGetBool(StrEditorIsAppendHash, false);
     builder.IsDisableWriteTypeTree  = EditorTools.PlayerGetBool(StrEditorIsDisableWriteTypeTree, false);
     builder.IsIgnoreTypeTreeChanges = EditorTools.PlayerGetBool(StrEditorIsIgnoreTypeTreeChanges, false);
 }
Beispiel #2
0
 /// <summary>
 /// 存储配置
 /// </summary>
 private static void SaveSettingsToPlayerPrefs(AssetBundleBuilder builder)
 {
     EditorTools.PlayerSetEnum <AssetBundleBuilder.ECompressOption>(StrEditorCompressOption, builder.CompressOption);
     EditorTools.PlayerSetBool(StrEditorIsForceRebuild, builder.IsForceRebuild);
     EditorTools.PlayerSetBool(StrEditorIsAppendHash, builder.IsAppendHash);
     EditorTools.PlayerSetBool(StrEditorIsDisableWriteTypeTree, builder.IsDisableWriteTypeTree);
     EditorTools.PlayerSetBool(StrEditorIsIgnoreTypeTreeChanges, builder.IsIgnoreTypeTreeChanges);
 }
        /// <summary>
        /// 复制更新文件到补丁包目录
        /// </summary>
        private void CopyUpdateFiles(AssetBundleBuilder.BuildParametersContext buildParameters)
        {
            string packageDirectory = buildParameters.GetPackageDirectory();

            BuildLogger.Log($"开始复制更新文件到补丁包目录:{packageDirectory}");

            // 复制Readme文件
            {
                string sourcePath = $"{buildParameters.OutputDirectory}/{PatchDefine.ReadmeFileName}";
                string destPath   = $"{packageDirectory}/{PatchDefine.ReadmeFileName}";
                EditorTools.CopyFile(sourcePath, destPath, true);
                BuildLogger.Log($"复制Readme文件到:{destPath}");
            }

            // 复制PatchManifest文件
            {
                string sourcePath = $"{buildParameters.OutputDirectory}/{PatchDefine.PatchManifestFileName}";
                string destPath   = $"{packageDirectory}/{PatchDefine.PatchManifestFileName}";
                EditorTools.CopyFile(sourcePath, destPath, true);
                BuildLogger.Log($"复制PatchManifest文件到:{destPath}");
            }

            // 复制UnityManifest文件
            {
                string sourcePath = $"{buildParameters.OutputDirectory}/{PatchDefine.UnityManifestFileName}";
                string destPath   = $"{packageDirectory}/{PatchDefine.UnityManifestFileName}";
                EditorTools.CopyFile(sourcePath, destPath, true);
                BuildLogger.Log($"复制UnityManifest文件到:{destPath}");
            }

            // 复制Manifest文件
            {
                string sourcePath = $"{buildParameters.OutputDirectory}/{PatchDefine.UnityManifestFileName}.manifest";
                string destPath   = $"{packageDirectory}/{PatchDefine.UnityManifestFileName}.manifest";
                EditorTools.CopyFile(sourcePath, destPath, true);
            }

            // 复制所有更新文件
            int           progressBarCount    = 0;
            PatchManifest patchFile           = AssetBundleBuilder.LoadPatchManifestFile(buildParameters);
            int           patchFileTotalCount = patchFile.BundleList.Count;

            foreach (var patchBundle in patchFile.BundleList)
            {
                if (patchBundle.Version == buildParameters.BuildVersion)
                {
                    string sourcePath = $"{buildParameters.OutputDirectory}/{patchBundle.BundleName}";
                    string destPath   = $"{packageDirectory}/{patchBundle.Hash}";
                    EditorTools.CopyFile(sourcePath, destPath, true);
                    BuildLogger.Log($"复制更新文件到补丁包:{sourcePath}");

                    progressBarCount++;
                    EditorUtility.DisplayProgressBar("进度", $"拷贝更新文件 : {sourcePath}", (float)progressBarCount / patchFileTotalCount);
                }
            }
            EditorUtility.ClearProgressBar();
        }
Beispiel #4
0
        private void OnGUI()
        {
            // 初始化
            InitInternal();

            // 标题
            EditorGUILayout.LabelField("Build setup", _centerStyle);
            EditorGUILayout.Space();

            // 输出路径
            string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRootPath();
            string outputDirectory   = AssetBundleBuilder.MakeOutputDirectory(defaultOutputRoot, BuildTarget);

            EditorGUILayout.LabelField("Build Output", outputDirectory);

            BuildVersion   = EditorGUILayout.IntField("Build Version", BuildVersion, GUILayout.MaxWidth(250));
            CompressOption = (ECompressOption)EditorGUILayout.EnumPopup("Compression", CompressOption, GUILayout.MaxWidth(250));
            IsForceRebuild = GUILayout.Toggle(IsForceRebuild, "Froce Rebuild", GUILayout.MaxWidth(120));

            // 构建按钮
            EditorGUILayout.Space();
            if (GUILayout.Button("Build", GUILayout.MaxHeight(40)))
            {
                string title;
                string content;
                if (IsForceRebuild)
                {
                    title   = "警告";
                    content = "确定开始强制构建吗,这样会删除所有已有构建的文件";
                }
                else
                {
                    title   = "提示";
                    content = "确定开始增量构建吗";
                }
                if (EditorUtility.DisplayDialog(title, content, "Yes", "No"))
                {
                    // 清空控制台
                    EditorTools.ClearUnityConsole();

                    // 存储配置
                    SaveSettingsToPlayerPrefs();

                    EditorApplication.delayCall += ExecuteBuild;
                }
                else
                {
                    Debug.LogWarning("[Build] 打包已经取消");
                }
            }

            // 绘制工具栏部分
            OnDrawGUITools();
        }
        /// <summary>
        /// 获取资源包列表
        /// </summary>
        private List <PatchBundle> GetAllPatchBundle(AssetBundleBuilder.BuildParametersContext buildParameters,
                                                     TaskGetBuildMap.BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext,
                                                     AssetBundleManifest unityManifest)
        {
            List <PatchBundle> result = new List <PatchBundle>();

            // 加载DLC
            DLCManager dlcManager = new DLCManager();

            dlcManager.LoadAllDLC();

            // 加载旧补丁清单
            PatchManifest oldPatchManifest = AssetBundleBuilder.LoadPatchManifestFile(buildParameters);

            // 获取加密列表
            List <string> encryptList = encryptionContext.EncryptList;

            string[] allAssetBundles = unityManifest.GetAllAssetBundles();
            foreach (var bundleName in allAssetBundles)
            {
                string   path      = $"{buildParameters.OutputDirectory}/{bundleName}";
                string   hash      = HashUtility.FileMD5(path);
                string   crc       = HashUtility.FileCRC32(path);
                long     size      = FileUtility.GetFileSize(path);
                int      version   = buildParameters.BuildVersion;
                string[] assets    = buildMapContext.GetCollectAssetPaths(bundleName);
                string[] depends   = unityManifest.GetDirectDependencies(bundleName);
                string[] dlcLabels = dlcManager.GetAssetBundleDLCLabels(bundleName);

                // 创建标记位
                bool isEncrypted = encryptList.Contains(bundleName);
                int  flags       = PatchBundle.CreateFlags(isEncrypted);

                // 注意:如果文件没有变化使用旧版本号
                if (oldPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle oldElement))
                {
                    if (oldElement.Hash == hash)
                    {
                        version = oldElement.Version;
                    }
                }

                PatchBundle newElement = new PatchBundle(bundleName, hash, crc, size, version, flags, assets, depends, dlcLabels);
                result.Add(newElement);
            }

            return(result);
        }
Beispiel #6
0
        private void InitInternal()
        {
            if (_assetBuilder != null)
            {
                return;
            }

            // GUI相关
            _centerStyle           = new GUIStyle(GUI.skin.GetStyle("Label"));
            _centerStyle.alignment = TextAnchor.UpperCenter;
            _leftStyle             = new GUIStyle(GUI.skin.GetStyle("Label"));
            _leftStyle.alignment   = TextAnchor.MiddleLeft;

            // 创建资源打包器
            var appVersion   = new Version(Application.version);
            var buildVersion = appVersion.Revision;
            var buildTarget  = EditorUserBuildSettings.activeBuildTarget;

            _assetBuilder = new AssetBundleBuilder(buildTarget, buildVersion);

            // 读取配置
            LoadSettingsFromPlayerPrefs(_assetBuilder);
        }
Beispiel #7
0
        /// <summary>
        /// 创建Readme文件到输出目录
        /// </summary>
        private void CreateReadmeFile(AssetBundleBuilder.BuildParametersContext buildParameters, AssetBundleBuilder.BuildOptionsContext buildOptions, AssetBundleManifest unityManifest)
        {
            string[] allAssetBundles = unityManifest.GetAllAssetBundles();

            // 删除旧文件
            string filePath = $"{buildParameters.OutputDirectory}/{PatchDefine.ReadmeFileName}";

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            BuildLogger.Log($"创建说明文件:{filePath}");

            StringBuilder content = new StringBuilder();

            AppendData(content, $"构建平台:{buildParameters.BuildTarget}");
            AppendData(content, $"构建版本:{buildParameters.BuildVersion}");
            AppendData(content, $"构建时间:{DateTime.Now}");

            AppendData(content, "");
            AppendData(content, $"--着色器--");
            AppendData(content, $"IsCollectAllShaders:{AssetBundleCollectorSettingData.Setting.IsCollectAllShaders}");
            AppendData(content, $"ShadersBundleName:{AssetBundleCollectorSettingData.Setting.ShadersBundleName}");

            AppendData(content, "");
            AppendData(content, $"--配置信息--");
            for (int i = 0; i < AssetBundleCollectorSettingData.Setting.Collectors.Count; i++)
            {
                AssetBundleCollectorSetting.Collector wrapper = AssetBundleCollectorSettingData.Setting.Collectors[i];
                AppendData(content, $"Directory : {wrapper.CollectDirectory} | {wrapper.PackRuleClassName} | {wrapper.FilterRuleClassName}");
            }

            AppendData(content, "");
            AppendData(content, $"--构建参数--");
            AppendData(content, $"CompressOption:{buildOptions.CompressOption}");
            AppendData(content, $"IsForceRebuild:{buildOptions.IsForceRebuild}");
            AppendData(content, $"IsDisableWriteTypeTree:{buildOptions.IsDisableWriteTypeTree}");
            AppendData(content, $"IsIgnoreTypeTreeChanges:{buildOptions.IsIgnoreTypeTreeChanges}");

            AppendData(content, "");
            AppendData(content, $"--构建清单--");
            for (int i = 0; i < allAssetBundles.Length; i++)
            {
                AppendData(content, allAssetBundles[i]);
            }

            PatchManifest patchFile = AssetBundleBuilder.LoadPatchManifestFile(buildParameters);

            {
                AppendData(content, "");
                AppendData(content, $"--更新清单--");
                foreach (var patchBundle in patchFile.BundleList)
                {
                    if (patchBundle.Version == buildParameters.BuildVersion)
                    {
                        AppendData(content, patchBundle.BundleName);
                    }
                }

                AppendData(content, "");
                AppendData(content, $"--变体列表--");
                foreach (var variant in patchFile.VariantList)
                {
                    AppendData(content, variant.ToString());
                }
            }

            // 创建新文件
            File.WriteAllText(filePath, content.ToString(), Encoding.UTF8);
        }