/// <summary> /// 加载配置文件 /// </summary> private static void LoadSettingData() { // 加载配置文件 _setting = AssetDatabase.LoadAssetAtPath <AssetBundleCollectorSetting>(EditorDefine.AssetBundleCollectorSettingFilePath); if (_setting == null) { Debug.LogWarning($"Create new {nameof(AssetBundleCollectorSetting)}.asset : {EditorDefine.AssetBundleCollectorSettingFilePath}"); _setting = ScriptableObject.CreateInstance <AssetBundleCollectorSetting>(); EditorTools.CreateFileDirectory(EditorDefine.AssetBundleCollectorSettingFilePath); AssetDatabase.CreateAsset(Setting, EditorDefine.AssetBundleCollectorSettingFilePath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } else { Debug.Log($"Load {nameof(AssetBundleCollectorSetting)}.asset ok"); } // IPackRule { // 清空缓存集合 _cachePackRuleTypes.Clear(); _cachePackRuleInstance.Clear(); // 获取所有类型 List <Type> types = new List <Type>(100) { typeof(PackExplicit), typeof(PackDirectory) }; var customTypes = AssemblyUtility.GetAssignableTypes(AssemblyUtility.UnityDefaultAssemblyEditorName, typeof(IPackRule)); types.AddRange(customTypes); for (int i = 0; i < types.Count; i++) { Type type = types[i]; if (_cachePackRuleTypes.ContainsKey(type.Name) == false) { _cachePackRuleTypes.Add(type.Name, type); } } } // IFilterRule { // 清空缓存集合 _cacheFilterRuleTypes.Clear(); _cacheFilterRuleInstance.Clear(); // 获取所有类型 List <Type> types = new List <Type>(100) { typeof(CollectAll), typeof(CollectScene), typeof(CollectPrefab), typeof(CollectSprite) }; var customTypes = AssemblyUtility.GetAssignableTypes(AssemblyUtility.UnityDefaultAssemblyEditorName, typeof(IFilterRule)); types.AddRange(customTypes); for (int i = 0; i < types.Count; i++) { Type type = types[i]; if (_cacheFilterRuleTypes.ContainsKey(type.Name) == false) { _cacheFilterRuleTypes.Add(type.Name, type); } } } }
public BundleLabelAndVariant(string label, string variant) { BundleLabel = EditorTools.GetRegularPath(label); BundleVariant = variant; }
void IBuildTask.Run(BuildContext context) { var buildParameters = context.GetContextObject <AssetBundleBuilder.BuildParametersContext>(); // 检测构建平台是否合法 if (buildParameters.Parameters.BuildTarget == BuildTarget.NoTarget) { throw new Exception("请选择目标平台"); } // 检测构建版本是否合法 if (buildParameters.Parameters.BuildVersion <= 0) { throw new Exception("请先设置版本号"); } // 检测输出目录是否为空 if (string.IsNullOrEmpty(buildParameters.PipelineOutputDirectory)) { throw new Exception("输出目录不能为空"); } // 检测资源收集配置文件 if (AssetBundleCollectorSettingData.GetCollecterCount() == 0) { throw new Exception("配置的资源收集路径为空"); } // 增量更新时候的必要检测 if (buildParameters.Parameters.IsForceRebuild == false) { // 检测历史版本是否存在 if (AssetBundleBuilderHelper.HasAnyPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot) == false) { throw new Exception("没有发现任何历史版本,请尝试强制重建"); } // 检测构建版本是否合法 int maxPackageVersion = AssetBundleBuilderHelper.GetMaxPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot); if (buildParameters.Parameters.BuildVersion <= maxPackageVersion) { throw new Exception("构建版本不能小于历史版本"); } // 检测补丁包是否已经存在 string packageDirectory = buildParameters.GetPackageDirectory(); if (Directory.Exists(packageDirectory)) { throw new Exception($"补丁包已经存在:{packageDirectory}"); } // 检测内置资源标记是否一致 PatchManifest oldPatchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory); if (buildParameters.Parameters.BuildinTags != oldPatchManifest.BuildinTags) { throw new Exception($"增量更新时内置资源标记必须一致:{buildParameters.Parameters.BuildinTags} != {oldPatchManifest.BuildinTags}"); } } // 如果是强制重建 if (buildParameters.Parameters.IsForceRebuild) { // 删除平台总目录 string platformDirectory = $"{buildParameters.Parameters.OutputRoot}/{buildParameters.Parameters.BuildTarget}"; if (EditorTools.DeleteDirectory(platformDirectory)) { BuildLogger.Log($"删除平台总目录:{platformDirectory}"); } } // 如果输出目录不存在 if (EditorTools.CreateDirectory(buildParameters.PipelineOutputDirectory)) { BuildLogger.Log($"创建输出目录:{buildParameters.PipelineOutputDirectory}"); } }
/// <summary> /// 2. 创建补丁清单文件到输出目录 /// </summary> private void CreatePatchManifestFile(AssetBundleManifest unityManifest, List <AssetInfo> buildMap, List <string> encryptList) { string[] allAssetBundles = unityManifest.GetAllAssetBundles(); // 创建DLC管理器 DLCManager dlcManager = new DLCManager(); dlcManager.LoadAllDLC(); // 加载旧补丁清单 PatchManifest oldPatchManifest = LoadPatchManifestFile(); // 创建新补丁清单 PatchManifest newPatchManifest = new PatchManifest(); // 写入版本信息 newPatchManifest.ResourceVersion = BuildVersion; // 写入所有AssetBundle文件的信息 for (int i = 0; i < allAssetBundles.Length; i++) { string bundleName = allAssetBundles[i]; string path = $"{OutputDirectory}/{bundleName}"; string md5 = HashUtility.FileMD5(path); uint crc32 = HashUtility.FileCRC32(path); long sizeBytes = EditorTools.GetFileSize(path); int version = BuildVersion; string[] assetPaths = GetBundleAssetPaths(buildMap, bundleName); string[] depends = unityManifest.GetDirectDependencies(bundleName); string[] dlcLabels = dlcManager.GetAssetBundleDLCLabels(bundleName); // 创建标记位 bool isEncrypted = encryptList.Contains(bundleName); bool isCollected = IsCollectBundle(buildMap, bundleName); int flags = PatchElement.CreateFlags(isEncrypted, isCollected); // 注意:如果文件没有变化使用旧版本号 if (oldPatchManifest.Elements.TryGetValue(bundleName, out PatchElement oldElement)) { if (oldElement.MD5 == md5) { version = oldElement.Version; } } PatchElement newElement = new PatchElement(bundleName, md5, crc32, sizeBytes, version, flags, assetPaths, depends, dlcLabels); newPatchManifest.ElementList.Add(newElement); } // 写入所有变体信息 { Dictionary <string, List <string> > variantInfos = GetVariantInfos(allAssetBundles); foreach (var pair in variantInfos) { if (pair.Value.Count > 0) { string bundleName = $"{pair.Key}.{ PatchDefine.AssetBundleDefaultVariant}"; List <string> variants = pair.Value; newPatchManifest.VariantList.Add(new PatchVariant(bundleName, variants)); } } } // 创建新文件 string filePath = OutputDirectory + $"/{PatchDefine.PatchManifestFileName}"; Log($"创建补丁清单文件:{filePath}"); PatchManifest.Serialize(filePath, newPatchManifest); }
/// <summary> /// 1. 创建补丁清单文件到输出目录 /// </summary> private void CreatePatchManifestFile(string[] allAssetBundles) { // 加载旧文件 PatchManifest patchManifest = LoadPatchManifestFile(); // 删除旧文件 string filePath = OutputPath + $"/{PatchDefine.PatchManifestFileName}"; if (File.Exists(filePath)) { File.Delete(filePath); } // 创建新文件 Log($"创建补丁清单文件:{filePath}"); using (FileStream fs = File.Create(filePath)) { StreamWriter sw = new StreamWriter(fs); // 写入版本信息 sw.Write(BuildVersion); sw.Write("\n"); sw.Flush(); // 写入UnityManifest文件的信息 { string assetName = PatchDefine.UnityManifestFileName; string path = $"{OutputPath}/{assetName}"; string md5 = HashUtility.FileMD5(path); long sizeKB = EditorTools.GetFileSize(path) / 1024; int version = BuildVersion; sw.Write($"{assetName}={md5}={sizeKB}={version}"); sw.Write("\n"); sw.Flush(); } // 写入所有AssetBundle文件的信息 foreach (string assetName in allAssetBundles) { string path = $"{OutputPath}/{assetName}"; string md5 = HashUtility.FileMD5(path); long sizeKB = EditorTools.GetFileSize(path) / 1024; int version = BuildVersion; // 注意:如果文件没有变化使用旧版本号 PatchElement element; if (patchManifest.Elements.TryGetValue(assetName, out element)) { if (element.MD5 == md5) { version = element.Version; } } sw.Write($"{assetName}={md5}={sizeKB}={version}"); sw.Write("\n"); sw.Flush(); } // 关闭文件流 sw.Close(); fs.Close(); } }
private void OnGUI() { // 搜索路径 EditorGUILayout.Space(); if (GUILayout.Button("设置搜索目录", GUILayout.MaxWidth(80))) { string resultPath = EditorTools.OpenFolderPanel("搜索目录", _searchFolderPath); if (resultPath != null) { _searchFolderPath = EditorTools.AbsolutePathToAssetPath(resultPath); } } EditorGUILayout.LabelField($"搜索目录:{_searchFolderPath}"); // 搜索类型 _serachType = (EAssetSearchType)EditorGUILayout.EnumPopup("搜索类型", _serachType); // 搜索目标 _searchObject = EditorGUILayout.ObjectField($"搜索目标", _searchObject, typeof(UnityEngine.Object), false); if (_searchObject != null && _searchObject.GetType() == typeof(Texture2D)) { string assetPath = AssetDatabase.GetAssetPath(_searchObject.GetInstanceID()); var spriteObject = AssetDatabase.LoadAssetAtPath <Sprite>(assetPath); if (spriteObject != null) { _searchObject = spriteObject; } } // 递归检测 _recursive = EditorGUILayout.Toggle("递归检测", _recursive); // 执行搜索 EditorGUILayout.Space(); if (GUILayout.Button("搜索")) { if (_searchObject == null) { EditorUtility.DisplayDialog("错误", "请先设置搜索目标", "确定"); return; } string assetPath = AssetDatabase.GetAssetPath(_searchObject.GetInstanceID()); FindReferenceInProject(assetPath, _searchFolderPath, _serachType); } EditorGUILayout.Space(); // 如果字典类为空 if (_collection == null) { return; } // 如果收集列表为空 if (CheckCollectIsEmpty()) { EditorGUILayout.LabelField("提示:没有找到任何被依赖资源。"); return; } _scrollPos = GUILayout.BeginScrollView(_scrollPos); // 显示依赖列表 foreach (EAssetFileExtension value in Enum.GetValues(typeof(EAssetFileExtension))) { List <string> collect = _collection[value]; if (collect.Count == 0) { continue; } string HeaderName = value.ToString(); if (value == EAssetFileExtension.prefab) { HeaderName = "预制体"; } else if (value == EAssetFileExtension.unity) { HeaderName = "场景"; } else if (value == EAssetFileExtension.fbx) { HeaderName = "模型"; } else if (value == EAssetFileExtension.anim) { HeaderName = "动画"; } else if (value == EAssetFileExtension.controller) { HeaderName = "控制器"; } else if (value == EAssetFileExtension.png || value == EAssetFileExtension.jpg) { HeaderName = "图片"; } else if (value == EAssetFileExtension.mat) { HeaderName = "材质球"; } else if (value == EAssetFileExtension.shader) { HeaderName = "着色器"; } else if (value == EAssetFileExtension.ttf) { HeaderName = "字体"; } else if (value == EAssetFileExtension.cs) { HeaderName = "脚本"; } else { throw new NotImplementedException(value.ToString()); } // 绘制头部 if (EditorTools.DrawHeader(HeaderName)) { // 绘制预制体专属按钮 if (value == EAssetFileExtension.prefab) { if (GUILayout.Button("过滤", GUILayout.MaxWidth(80))) { FilterReference(); } if (GUILayout.Button("FindAll", GUILayout.MaxWidth(80))) { FindAll(collect); } } // 绘制依赖列表 foreach (string item in collect) { EditorGUILayout.BeginHorizontal(); UnityEngine.Object go = AssetDatabase.LoadAssetAtPath(item, typeof(UnityEngine.Object)); if (value == EAssetFileExtension.unity) { EditorGUILayout.ObjectField(go, typeof(SceneView), true); } else { EditorGUILayout.ObjectField(go, typeof(UnityEngine.Object), false); } // 绘制预制体专属按钮 if (value == EAssetFileExtension.prefab) { if (GUILayout.Button("Find", GUILayout.MaxWidth(80))) { FindOne(go as GameObject); } } EditorGUILayout.EndHorizontal(); } } } GUILayout.EndScrollView(); }
/// <summary> /// 存储配置 /// </summary> private void SaveSettingsToPlayerPrefs() { EditorTools.PlayerSetEnum <ECompressOption>(StrEditorCompressOption, CompressOption); EditorTools.PlayerSetBool(StrEditorIsForceRebuild, IsForceRebuild); }
/// <summary> /// 读取配置 /// </summary> private void LoadSettingsFromPlayerPrefs() { _compressOption = EditorTools.PlayerGetEnum <ECompressOption>(StrEditorCompressOption, ECompressOption.Uncompressed); _isForceRebuild = EditorPrefs.GetBool(StrEditorIsForceRebuild, false); _buildinTags = EditorPrefs.GetString(StrEditorBuildinTags, string.Empty); }
private void CreatePatchManifestBytesFile(string[] allAssetBundles, Dictionary <string, List <string> > variantInfos) { ByteBuffer fileBuffer = new ByteBuffer(PatchManifest.FileStreamMaxLen); ByteBuffer tableBuffer = new ByteBuffer(PatchManifest.TableStreamMaxLen); // 加载补丁清单 PatchManifest oldPatchManifest = LoadPatchManifestFile(); // 删除旧文件 string filePath = OutputPath + $"/{PatchDefine.PatchManifestBytesFileName}"; if (File.Exists(filePath)) { File.Delete(filePath); } // 创建新文件 Log($"创建补丁清单文件:{filePath}"); // 写入版本信息 fileBuffer.WriteInt(BuildVersion); // 写入元素总数 fileBuffer.WriteInt(allAssetBundles.Length + 1); // 写入UnityManifest文件的信息 { string assetName = PatchDefine.UnityManifestFileName; string path = $"{OutputPath}/{assetName}"; string md5 = HashUtility.FileMD5(path); long sizeBytes = EditorTools.GetFileSize(path); int version = BuildVersion; List <string> variantList = null; tableBuffer.Clear(); tableBuffer.WriteUTF(assetName); tableBuffer.WriteUTF(md5); tableBuffer.WriteLong(sizeBytes); tableBuffer.WriteInt(version); tableBuffer.WriteListUTF(variantList); // 写入到总缓存 int tabSize = tableBuffer.ReadableBytes(); fileBuffer.WriteShort(PatchManifest.TableStreamHead); fileBuffer.WriteInt(tabSize); fileBuffer.WriteBytes(tableBuffer.ReadBytes(tabSize)); } // 写入所有AssetBundle文件的信息 foreach (string assetName in allAssetBundles) { string path = $"{OutputPath}/{assetName}"; string md5 = HashUtility.FileMD5(path); long sizeBytes = EditorTools.GetFileSize(path); int version = BuildVersion; string variants = GetVariants(variantInfos, assetName); List <string> variantList = null; if (string.IsNullOrEmpty(variants) == false) { variantList = variants.Split('|').ToList(); } // 注意:如果文件没有变化使用旧版本号 if (oldPatchManifest.Elements.TryGetValue(assetName, out PatchElement element)) { if (element.MD5 == md5) { version = element.Version; } } tableBuffer.Clear(); tableBuffer.WriteUTF(assetName); tableBuffer.WriteUTF(md5); tableBuffer.WriteLong(sizeBytes); tableBuffer.WriteInt(version); tableBuffer.WriteListUTF(variantList); // 写入到总缓存 int tabSize = tableBuffer.ReadableBytes(); fileBuffer.WriteShort(PatchManifest.TableStreamHead); fileBuffer.WriteInt(tabSize); fileBuffer.WriteBytes(tableBuffer.ReadBytes(tabSize)); } // 创建文件 using (FileStream fs = new FileStream(filePath, FileMode.Create)) { byte[] data = fileBuffer.Buf; int length = fileBuffer.ReadableBytes(); fs.Write(data, 0, length); } }
/// <summary> /// 获取构建的资源列表 /// </summary> private List <AssetInfo> GetBuildAssets() { Dictionary <string, AssetInfo> buildAssets = new Dictionary <string, AssetInfo>(); Dictionary <string, string> references = new Dictionary <string, string>(); // 1. 获取主动收集的资源 List <AssetCollectInfo> allCollectAssets = AssetBundleCollectorSettingData.GetAllCollectAssets(); // 2. 对收集的资源进行依赖分析 int progressValue = 0; foreach (AssetCollectInfo collectInfo in allCollectAssets) { string mainAssetPath = collectInfo.AssetPath; List <AssetInfo> depends = GetDependencies(mainAssetPath); for (int i = 0; i < depends.Count; i++) { AssetInfo assetInfo = depends[i]; string assetPath = assetInfo.AssetPath; // 如果已经存在,则增加该资源的依赖计数 if (buildAssets.ContainsKey(assetPath)) { buildAssets[assetPath].DependCount++; } else { buildAssets.Add(assetPath, assetInfo); references.Add(assetPath, mainAssetPath); } // 添加资源标记 buildAssets[assetPath].AddAssetTags(collectInfo.AssetTags); // 注意:检测是否为主动收集资源 if (assetPath == mainAssetPath) { buildAssets[assetPath].IsCollectAsset = true; buildAssets[assetPath].DontWriteAssetPath = collectInfo.DontWriteAssetPath; } } EditorTools.DisplayProgressBar("依赖文件分析", ++progressValue, allCollectAssets.Count); } EditorTools.ClearProgressBar(); // 3. 移除零依赖的资源 List <AssetInfo> undependentAssets = new List <AssetInfo>(); foreach (KeyValuePair <string, AssetInfo> pair in buildAssets) { if (pair.Value.IsCollectAsset) { continue; } if (pair.Value.DependCount == 0) { undependentAssets.Add(pair.Value); } } foreach (var assetInfo in undependentAssets) { buildAssets.Remove(assetInfo.AssetPath); } // 4. 设置资源标签和变种 progressValue = 0; foreach (KeyValuePair <string, AssetInfo> pair in buildAssets) { var assetInfo = pair.Value; var bundleLabelAndVariant = AssetBundleCollectorSettingData.GetBundleLabelAndVariant(assetInfo.AssetPath); assetInfo.SetBundleLabelAndVariant(bundleLabelAndVariant.BundleLabel, bundleLabelAndVariant.BundleVariant); EditorTools.DisplayProgressBar("设置资源标签", ++progressValue, buildAssets.Count); } EditorTools.ClearProgressBar(); // 5. 补充零依赖的资源 foreach (var assetInfo in undependentAssets) { var referenceAssetPath = references[assetInfo.AssetPath]; var referenceAssetInfo = buildAssets[referenceAssetPath]; assetInfo.SetBundleLabelAndVariant(referenceAssetInfo.AssetBundleLabel, referenceAssetInfo.AssetBundleVariant); buildAssets.Add(assetInfo.AssetPath, assetInfo); } // 6. 返回结果 return(buildAssets.Values.ToList()); }
/// <summary> /// 清空流文件夹 /// </summary> public static void ClearStreamingAssetsFolder() { string streamingPath = Application.dataPath + "/StreamingAssets"; EditorTools.ClearFolder(streamingPath); }
/// <summary> /// 获取默认的导出根路径 /// </summary> public static string GetDefaultOutputRootPath() { string projectPath = EditorTools.GetProjectPath(); return($"{projectPath}/BuildBundles"); }
private void OnDrawCollector() { // 列表显示 EditorGUILayout.Space(); _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos); for (int i = 0; i < AssetBundleCollectorSettingData.Setting.Collectors.Count; i++) { var collector = AssetBundleCollectorSettingData.Setting.Collectors[i]; string directory = collector.CollectDirectory; string packRuleName = collector.PackRuleName; string filterRuleName = collector.FilterRuleName; bool dontWriteAssetPath = collector.DontWriteAssetPath; string assetTags = collector.AssetTags; EditorGUILayout.BeginHorizontal(); { // Directory EditorGUILayout.LabelField(directory, GUILayout.MinWidth(GuiDirecotryMinSize), GUILayout.MaxWidth(GuiDirecotryMaxSize)); // IPackRule { int index = PackRuleNameToIndex(packRuleName); int newIndex = EditorGUILayout.Popup(index, _packRuleArray, GUILayout.MinWidth(GuiPackRuleSize), GUILayout.MaxWidth(GuiPackRuleSize)); if (newIndex != index) { packRuleName = IndexToPackRuleName(newIndex); AssetBundleCollectorSettingData.ModifyCollector(directory, packRuleName, filterRuleName, dontWriteAssetPath, assetTags); } } // IFilterRule { int index = FilterRuleNameToIndex(filterRuleName); int newIndex = EditorGUILayout.Popup(index, _filterRuleArray, GUILayout.MinWidth(GuiFilterRuleSize), GUILayout.MaxWidth(GuiFilterRuleSize)); if (newIndex != index) { filterRuleName = IndexToFilterRuleName(newIndex); AssetBundleCollectorSettingData.ModifyCollector(directory, packRuleName, filterRuleName, dontWriteAssetPath, assetTags); } } // DontWriteAssetPath { bool newToggleValue = EditorGUILayout.Toggle(dontWriteAssetPath, GUILayout.MinWidth(GuiDontWriteAssetPathSize), GUILayout.MaxWidth(GuiDontWriteAssetPathSize)); if (newToggleValue != dontWriteAssetPath) { dontWriteAssetPath = newToggleValue; AssetBundleCollectorSettingData.ModifyCollector(directory, packRuleName, filterRuleName, dontWriteAssetPath, assetTags); } } // AssetTags { string newTextValue = EditorGUILayout.TextField(assetTags, GUILayout.MinWidth(GuiAssetTagsMinSize), GUILayout.MaxWidth(GuiAssetTagsMaxSize)); if (newTextValue != assetTags) { assetTags = newTextValue; AssetBundleCollectorSettingData.ModifyCollector(directory, packRuleName, filterRuleName, dontWriteAssetPath, assetTags); } } if (GUILayout.Button("-", GUILayout.MinWidth(GuiBtnSize), GUILayout.MaxWidth(GuiBtnSize))) { AssetBundleCollectorSettingData.RemoveCollector(directory); break; } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); // 添加按钮 if (GUILayout.Button("+")) { string resultPath = EditorTools.OpenFolderPanel("Select Folder", _lastOpenFolderPath); if (resultPath != null) { _lastOpenFolderPath = EditorTools.AbsolutePathToAssetPath(resultPath); string defaultPackRuleName = nameof(PackExplicit); string defaultFilterRuleName = nameof(CollectAll); bool defaultDontWriteAssetPathValue = false; string defaultAssetTag = string.Empty; AssetBundleCollectorSettingData.AddCollector(_lastOpenFolderPath, defaultPackRuleName, defaultFilterRuleName, defaultDontWriteAssetPathValue, defaultAssetTag); } } // 导入配置按钮 if (GUILayout.Button("Import Config")) { string resultPath = EditorTools.OpenFilePath("Select File", "Assets/", "xml"); if (resultPath != null) { CollectorConfigImporter.ImportXmlConfig(resultPath); } } }
private void OnDrawCollector() { // 着色器选项 EditorGUILayout.Space(); bool isCollectAllShader = EditorGUILayout.Toggle("收集所有着色器", AssetBundleCollectorSettingData.Setting.IsCollectAllShaders); if (isCollectAllShader != AssetBundleCollectorSettingData.Setting.IsCollectAllShaders) { AssetBundleCollectorSettingData.ModifyShader(isCollectAllShader, AssetBundleCollectorSettingData.Setting.ShadersBundleName); } if (isCollectAllShader) { string shadersBundleName = EditorGUILayout.TextField("AssetBundle名称", AssetBundleCollectorSettingData.Setting.ShadersBundleName); if (shadersBundleName != AssetBundleCollectorSettingData.Setting.ShadersBundleName) { AssetBundleCollectorSettingData.ModifyShader(isCollectAllShader, shadersBundleName); } } // 列表显示 EditorGUILayout.Space(); EditorGUILayout.LabelField($"[ Collector ]"); _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos); for (int i = 0; i < AssetBundleCollectorSettingData.Setting.Collectors.Count; i++) { var collector = AssetBundleCollectorSettingData.Setting.Collectors[i]; string directory = collector.CollectDirectory; string packRuleClassName = collector.PackRuleClassName; string filterRuleClassName = collector.FilterRuleClassName; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(directory); // IPackRule { int index = PackRuleClassNameToIndex(packRuleClassName); int newIndex = EditorGUILayout.Popup(index, _packRuleClassArray, GUILayout.MaxWidth(200)); if (newIndex != index) { packRuleClassName = IndexToPackRuleClassName(newIndex); AssetBundleCollectorSettingData.ModifyCollector(directory, packRuleClassName, filterRuleClassName); } } // IFilterRule { int index = FilterRuleClassNameToIndex(filterRuleClassName); int newIndex = EditorGUILayout.Popup(index, _filterRuleClassArray, GUILayout.MaxWidth(150)); if (newIndex != index) { filterRuleClassName = IndexToFilterRuleClassName(newIndex); AssetBundleCollectorSettingData.ModifyCollector(directory, packRuleClassName, filterRuleClassName); } } if (GUILayout.Button("-", GUILayout.MaxWidth(40))) { AssetBundleCollectorSettingData.RemoveCollector(directory); break; } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); // 添加按钮 if (GUILayout.Button("+")) { string resultPath = EditorTools.OpenFolderPanel("Select Folder", _lastOpenFolderPath); if (resultPath != null) { _lastOpenFolderPath = EditorTools.AbsolutePathToAssetPath(resultPath); string defaultPackRuleClassName = nameof(PackExplicit); string defaultFilterRuleClassName = nameof(CollectAll); AssetBundleCollectorSettingData.AddCollector(_lastOpenFolderPath, defaultPackRuleClassName, defaultFilterRuleClassName); } } // 导入配置按钮 if (GUILayout.Button("Import Config")) { string resultPath = EditorTools.OpenFilePath("Select Folder", _lastOpenFolderPath); if (resultPath != null) { CollectorConfigImporter.ImportXmlConfig(resultPath); } } }
/// <summary> /// 读取配置 /// </summary> private void LoadSettingsFromPlayerPrefs() { CompressOption = EditorTools.PlayerGetEnum <ECompressOption>(StrEditorCompressOption, ECompressOption.Uncompressed); IsForceRebuild = EditorTools.PlayerGetBool(StrEditorIsForceRebuild, false); }
private void OnGUI() { // 初始化 InitInternal(); // 标题 EditorGUILayout.LabelField("Build setup", _centerStyle); EditorGUILayout.Space(); // 构建版本 _assetBuilder.BuildVersion = EditorGUILayout.IntField("Build Version", _assetBuilder.BuildVersion, GUILayout.MaxWidth(250)); // 输出路径 EditorGUILayout.LabelField("Build Output", _assetBuilder.OutputDirectory); // 构建选项 EditorGUILayout.Space(); _assetBuilder.IsForceRebuild = GUILayout.Toggle(_assetBuilder.IsForceRebuild, "Froce Rebuild", GUILayout.MaxWidth(120)); // 高级选项 using (new EditorGUI.DisabledScope(false)) { EditorGUILayout.Space(); _showSettingFoldout = EditorGUILayout.Foldout(_showSettingFoldout, "Advanced Settings"); if (_showSettingFoldout) { int indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 1; _assetBuilder.CompressOption = (AssetBundleBuilder.ECompressOption)EditorGUILayout.EnumPopup("Compression", _assetBuilder.CompressOption); _assetBuilder.IsAppendHash = EditorGUILayout.ToggleLeft("Append Hash", _assetBuilder.IsAppendHash, GUILayout.MaxWidth(120)); _assetBuilder.IsDisableWriteTypeTree = EditorGUILayout.ToggleLeft("Disable Write Type Tree", _assetBuilder.IsDisableWriteTypeTree, GUILayout.MaxWidth(200)); _assetBuilder.IsIgnoreTypeTreeChanges = EditorGUILayout.ToggleLeft("Ignore Type Tree Changes", _assetBuilder.IsIgnoreTypeTreeChanges, GUILayout.MaxWidth(200)); EditorGUI.indentLevel = indent; } } // 构建按钮 EditorGUILayout.Space(); if (GUILayout.Button("Build", GUILayout.MaxHeight(40))) { string title; string content; if (_assetBuilder.IsForceRebuild) { title = "警告"; content = "确定开始强制构建吗,这样会删除所有已有构建的文件"; } else { title = "提示"; content = "确定开始增量构建吗"; } if (EditorUtility.DisplayDialog(title, content, "Yes", "No")) { // 清空控制台 EditorTools.ClearUnityConsole(); // 存储配置 SaveSettingsToPlayerPrefs(_assetBuilder); EditorApplication.delayCall += ExecuteBuild; } else { Debug.LogWarning("[Build] 打包已经取消"); } } // 绘制工具栏部分 OnDrawGUITools(); }
/// <summary> /// 存储配置 /// </summary> private void SaveSettingsToPlayerPrefs() { EditorTools.PlayerSetEnum <ECompressOption>(StrEditorCompressOption, _compressOption); EditorPrefs.SetBool(StrEditorIsForceRebuild, _isForceRebuild); EditorPrefs.SetString(StrEditorBuildinTags, _buildinTags); }