From 650d8689eeb766e340d9300a8cb15f20107c18ec Mon Sep 17 00:00:00 2001 From: hevinci Date: Sat, 30 Apr 2022 23:14:20 +0800 Subject: [PATCH] Optimize packaging bundle core logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化了打包的核心逻辑,支持设置依赖资源收集器。 --- .../AssetBundleBuilder/BuildAssetInfo.cs | 14 ++--- .../AssetBundleBuilder/BuildBundleInfo.cs | 2 +- .../{BuildMapHelper.cs => BuildMapCreater.cs} | 56 ++++++++++++++----- ...Helper.cs.meta => BuildMapCreater.cs.meta} | 0 .../BuildSystem/BuildRunner.cs | 3 + .../BuildSystem/TaskAttribute.cs | 14 +++++ .../BuildSystem/TaskAttribute.cs.meta | 11 ++++ .../BuildTasks/TaskBuilding.cs | 3 +- .../BuildTasks/TaskCopyBuildinFiles.cs | 6 +- .../BuildTasks/TaskCreatePatchManifest.cs | 4 +- .../BuildTasks/TaskCreatePatchPackage.cs | 12 +--- .../BuildTasks/TaskCreateReport.cs | 5 +- .../BuildTasks/TaskEncryption.cs | 4 +- .../BuildTasks/TaskGetBuildMap.cs | 4 +- .../BuildTasks/TaskPrepare.cs | 1 + .../BuildTasks/TaskVerifyBuildResult.cs | 1 + .../AssetBundleCollector.cs | 23 +++++--- .../AssetBundleGrouper/AssetBundleGrouper.cs | 2 +- .../AssetBundleGrouperRuntimeSupport.cs | 49 ++++++++-------- .../AssetBundleGrouperSetting.cs | 2 +- .../AssetBundleGrouperWindow.cs | 17 +++++- .../AssetBundleGrouper/ECollectorType.cs | 14 +++-- 22 files changed, 162 insertions(+), 85 deletions(-) rename Assets/YooAsset/Editor/AssetBundleBuilder/{BuildMapHelper.cs => BuildMapCreater.cs} (62%) rename Assets/YooAsset/Editor/AssetBundleBuilder/{BuildMapHelper.cs.meta => BuildMapCreater.cs.meta} (100%) create mode 100644 Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/TaskAttribute.cs create mode 100644 Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/TaskAttribute.cs.meta diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs index cc891c3..0daded9 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs @@ -9,7 +9,7 @@ namespace YooAsset.Editor { private string _mainBundleName; private string _shareBundleName; - private readonly HashSet _dependBundleNames = new HashSet(); + private readonly HashSet _referenceBundleNames = new HashSet(); /// /// 收集器类型 @@ -126,15 +126,15 @@ namespace YooAsset.Editor } /// - /// 设置依赖资源包名称 + /// 添加关联的资源包名称 /// - public void AddDependBundleName(string bundleName) + public void AddReferenceBundleName(string bundleName) { if (string.IsNullOrEmpty(bundleName)) throw new Exception("Should never get here !"); - if (_dependBundleNames.Contains(bundleName) == false) - _dependBundleNames.Add(bundleName); + if (_referenceBundleNames.Contains(bundleName) == false) + _referenceBundleNames.Add(bundleName); } /// @@ -157,9 +157,9 @@ namespace YooAsset.Editor } } - if (_dependBundleNames.Count > 1) + if (_referenceBundleNames.Count > 1) { - var bundleNameList = _dependBundleNames.ToList(); + var bundleNameList = _referenceBundleNames.ToList(); bundleNameList.Sort(); string combineName = string.Join("|", bundleNameList); var combineNameHash = HashUtility.StringSHA1(combineName); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs index 901f189..de88bc6 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs @@ -105,7 +105,7 @@ namespace YooAsset.Editor /// public BuildAssetInfo[] GetAllPatchAssetInfos() { - return BuildinAssets.Where(t => t.CollectorType == ECollectorType.MainCollector).ToArray(); + return BuildinAssets.Where(t => t.CollectorType == ECollectorType.MainAssetCollector).ToArray(); } /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs similarity index 62% rename from Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs rename to Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs index a16b4be..07b5bba 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs @@ -5,12 +5,12 @@ using System.Collections.Generic; namespace YooAsset.Editor { - public static class BuildMapHelper + public static class BuildMapCreater { /// /// 执行资源构建上下文 /// - public static BuildMapContext SetupBuildMap() + public static BuildMapContext CreateBuildMap() { BuildMapContext context = new BuildMapContext(); Dictionary buildAssetDic = new Dictionary(1000); @@ -21,7 +21,22 @@ namespace YooAsset.Editor // 2. 获取所有主动收集的资源 List allCollectAssets = AssetBundleGrouperSettingData.Setting.GetAllCollectAssets(); - // 3. 录入主动收集的资源 + // 3. 剔除未被引用的依赖资源 + List removeDependList = new List(); + foreach (var collectAssetInfo in allCollectAssets) + { + if (collectAssetInfo.CollectorType == ECollectorType.DependAssetCollector) + { + if (IsRemoveDependAsset(allCollectAssets, collectAssetInfo.AssetPath)) + removeDependList.Add(collectAssetInfo); + } + } + foreach (var removeValue in removeDependList) + { + allCollectAssets.Remove(removeValue); + } + + // 4. 录入主动收集的资源 foreach (var collectAssetInfo in allCollectAssets) { if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false) @@ -36,7 +51,7 @@ namespace YooAsset.Editor } } - // 4. 录入相关依赖的资源 + // 5. 录入相关依赖的资源 foreach (var collectAssetInfo in allCollectAssets) { foreach (var dependAssetPath in collectAssetInfo.DependAssets) @@ -44,20 +59,20 @@ namespace YooAsset.Editor if (buildAssetDic.ContainsKey(dependAssetPath)) { buildAssetDic[dependAssetPath].AddAssetTags(collectAssetInfo.AssetTags); - buildAssetDic[dependAssetPath].AddDependBundleName(collectAssetInfo.BundleName); + buildAssetDic[dependAssetPath].AddReferenceBundleName(collectAssetInfo.BundleName); } else { var buildAssetInfo = new BuildAssetInfo(ECollectorType.None, dependAssetPath); buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags); - buildAssetInfo.AddDependBundleName(collectAssetInfo.BundleName); + buildAssetInfo.AddReferenceBundleName(collectAssetInfo.BundleName); buildAssetDic.Add(dependAssetPath, buildAssetInfo); } } } context.AssetFileCount = buildAssetDic.Count; - // 5. 填充主动收集资源的依赖列表 + // 6. 填充主动收集资源的依赖列表 foreach (var collectAssetInfo in allCollectAssets) { var dependAssetInfos = new List(collectAssetInfo.DependAssets.Count); @@ -71,26 +86,26 @@ namespace YooAsset.Editor buildAssetDic[collectAssetInfo.AssetPath].SetAllDependAssetInfos(dependAssetInfos); } - // 6. 计算完整的资源包名 + // 7. 计算完整的资源包名 foreach (KeyValuePair pair in buildAssetDic) { pair.Value.CalculateFullBundleName(); } - // 7. 移除未参与构建的资源 - List removeList = new List(); + // 8. 移除未参与构建的资源 + List removeBuildList = new List(); foreach (KeyValuePair pair in buildAssetDic) { var buildAssetInfo = pair.Value; if (buildAssetInfo.HasBundleName() == false) - removeList.Add(buildAssetInfo); + removeBuildList.Add(buildAssetInfo); } - foreach (var removeValue in removeList) + foreach (var removeValue in removeBuildList) { buildAssetDic.Remove(removeValue.AssetPath); } - // 8. 构建资源包 + // 9. 构建资源包 var allBuildinAssets = buildAssetDic.Values.ToList(); if (allBuildinAssets.Count == 0) throw new Exception("构建的资源列表不能为空"); @@ -100,5 +115,20 @@ namespace YooAsset.Editor } return context; } + private static bool IsRemoveDependAsset(List allCollectAssets, string dependAssetPath) + { + foreach (var collectAssetInfo in allCollectAssets) + { + var collectorType = collectAssetInfo.CollectorType; + if (collectorType == ECollectorType.MainAssetCollector || collectorType == ECollectorType.StaticAssetCollector) + { + if (collectAssetInfo.DependAssets.Contains(dependAssetPath)) + return false; + } + } + + UnityEngine.Debug.Log($"发现未被依赖的资源并自动移除 : {dependAssetPath}"); + return true; + } } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs.meta b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs.meta similarity index 100% rename from Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs.meta rename to Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs.meta diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/BuildRunner.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/BuildRunner.cs index 1f129f9..94992a3 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/BuildRunner.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/BuildRunner.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Reflection; using UnityEngine; namespace YooAsset.Editor @@ -24,6 +25,8 @@ namespace YooAsset.Editor IBuildTask task = pipeline[i]; try { + var taskAttribute = task.GetType().GetCustomAttribute(); + Debug.Log($"---------------------------------------->{taskAttribute.Desc}"); task.Run(context); } catch (Exception e) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/TaskAttribute.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/TaskAttribute.cs new file mode 100644 index 0000000..629385f --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/TaskAttribute.cs @@ -0,0 +1,14 @@ +using System; + +namespace YooAsset.Editor +{ + [AttributeUsage(AttributeTargets.Class)] + public class TaskAttribute : Attribute + { + public string Desc; + public TaskAttribute(string desc) + { + Desc = desc; + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/TaskAttribute.cs.meta b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/TaskAttribute.cs.meta new file mode 100644 index 0000000..7e99097 --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/TaskAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 35749e57d9a3da84aa60c348bc6bbe9d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs index 74821e3..232aacf 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs @@ -8,6 +8,7 @@ using UnityEngine; namespace YooAsset.Editor { + [TaskAttribute("资源构建内容打包")] public class TaskBuilding : IBuildTask { public class UnityManifestContext : IContextObject @@ -20,12 +21,12 @@ namespace YooAsset.Editor var buildParametersContext = context.GetContextObject(); var buildMapContext = context.GetContextObject(); - Debug.Log($"开始构建......"); BuildAssetBundleOptions opt = buildParametersContext.GetPipelineBuildOptions(); AssetBundleManifest unityManifest = BuildPipeline.BuildAssetBundles(buildParametersContext.PipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), opt, buildParametersContext.Parameters.BuildTarget); if (unityManifest == null) throw new Exception("构建过程中发生错误!"); + Debug.Log("Unity引擎打包成功!"); UnityManifestContext unityManifestContext = new UnityManifestContext(); unityManifestContext.UnityManifest = unityManifest; context.SetContextObject(unityManifestContext); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCopyBuildinFiles.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCopyBuildinFiles.cs index 2f1efb1..0f3c0ea 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCopyBuildinFiles.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCopyBuildinFiles.cs @@ -6,9 +6,7 @@ using UnityEngine; namespace YooAsset.Editor { - /// - /// 拷贝内置文件到StreamingAssets - /// + [TaskAttribute("拷贝内置文件到流目录")] public class TaskCopyBuildinFiles : IBuildTask { void IBuildTask.Run(BuildContext context) @@ -38,7 +36,6 @@ namespace YooAsset.Editor string sourcePath = $"{pipelineOutputDirectory}/{patchBundle.BundleName}"; string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{patchBundle.Hash}"; - Debug.Log($"拷贝内置文件到流目录:{patchBundle.BundleName}"); EditorTools.CopyFile(sourcePath, destPath, true); } @@ -65,6 +62,7 @@ namespace YooAsset.Editor // 刷新目录 AssetDatabase.Refresh(); + Debug.Log($"内置文件拷贝完成:{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}"); } } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs index 188fc69..4ba3505 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs @@ -5,9 +5,7 @@ using System.Collections.Generic; namespace YooAsset.Editor { - /// - /// 创建补丁清单文件 - /// + [TaskAttribute("创建补丁清单文件")] public class TaskCreatePatchManifest : IBuildTask { void IBuildTask.Run(BuildContext context) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs index 546f910..6045b77 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs @@ -3,9 +3,7 @@ using System.Collections.Generic; namespace YooAsset.Editor { - /// - /// 制作补丁包 - /// + [TaskAttribute("制作补丁包")] public class TaskCreatePatchPackage : IBuildTask { void IBuildTask.Run(BuildContext context) @@ -24,7 +22,7 @@ namespace YooAsset.Editor { int resourceVersion = buildParameters.Parameters.BuildVersion; string packageDirectory = buildParameters.GetPackageDirectory(); - UnityEngine.Debug.Log($"准备开始拷贝补丁文件到补丁包目录:{packageDirectory}"); + UnityEngine.Debug.Log($"开始拷贝补丁文件到补丁包目录:{packageDirectory}"); // 拷贝Report文件 { @@ -32,7 +30,6 @@ namespace YooAsset.Editor string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{reportFileName}"; string destPath = $"{packageDirectory}/{reportFileName}"; EditorTools.CopyFile(sourcePath, destPath, true); - UnityEngine.Debug.Log($"拷贝构建报告文件到:{destPath}"); } // 拷贝补丁清单文件 @@ -40,7 +37,6 @@ namespace YooAsset.Editor string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; string destPath = $"{packageDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; EditorTools.CopyFile(sourcePath, destPath, true); - UnityEngine.Debug.Log($"拷贝补丁清单文件到:{destPath}"); } // 拷贝补丁清单哈希文件 @@ -48,7 +44,6 @@ namespace YooAsset.Editor string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}"; string destPath = $"{packageDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}"; EditorTools.CopyFile(sourcePath, destPath, true); - UnityEngine.Debug.Log($"拷贝补丁清单哈希文件到:{destPath}"); } // 拷贝静态版本文件 @@ -56,7 +51,6 @@ namespace YooAsset.Editor string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}"; string destPath = $"{packageDirectory}/{YooAssetSettings.VersionFileName}"; EditorTools.CopyFile(sourcePath, destPath, true); - UnityEngine.Debug.Log($"拷贝静态版本文件到:{destPath}"); } // 拷贝UnityManifest序列化文件 @@ -64,7 +58,6 @@ namespace YooAsset.Editor string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}"; string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}"; EditorTools.CopyFile(sourcePath, destPath, true); - UnityEngine.Debug.Log($"拷贝UnityManifest文件到:{destPath}"); } // 拷贝UnityManifest文本文件 @@ -83,7 +76,6 @@ namespace YooAsset.Editor string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{patchBundle.BundleName}"; string destPath = $"{packageDirectory}/{patchBundle.Hash}"; EditorTools.CopyFile(sourcePath, destPath, true); - UnityEngine.Debug.Log($"拷贝补丁文件到补丁包:{patchBundle.BundleName}"); EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, patchFileTotalCount); } EditorTools.ClearProgressBar(); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs index f3c0c14..44fb47b 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs @@ -4,9 +4,7 @@ using System.IO; namespace YooAsset.Editor { - /// - /// 创建报告文件 - /// + [TaskAttribute("创建构建报告文件")] public class TaskCreateReport : IBuildTask { void IBuildTask.Run(BuildContext context) @@ -93,6 +91,7 @@ namespace YooAsset.Editor // 序列化文件 BuildReport.Serialize(filePath, buildReport); + UnityEngine.Debug.Log($"资源构建报告文件创建完成:{filePath}"); } /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs index 6804b3a..619caef 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; namespace YooAsset.Editor { + [TaskAttribute("资源包加密")] public class TaskEncryption : IBuildTask { public class EncryptionContext : IContextObject @@ -54,7 +55,6 @@ namespace YooAsset.Editor if (encryptionServices == null) return encryptList; - UnityEngine.Debug.Log($"开始加密资源文件"); int progressValue = 0; foreach (var bundleInfo in buildMapContext.BundleInfos) { @@ -84,6 +84,8 @@ namespace YooAsset.Editor } EditorTools.ClearProgressBar(); + if(encryptList.Count == 0) + UnityEngine.Debug.LogWarning($"没有发现需要加密的文件!"); return encryptList; } } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs index 3ef2fed..c83aab8 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs @@ -7,12 +7,14 @@ using UnityEditor; namespace YooAsset.Editor { + [TaskAttribute("获取资源构建内容")] public class TaskGetBuildMap : IBuildTask { void IBuildTask.Run(BuildContext context) { - var buildMapContext = BuildMapHelper.SetupBuildMap(); + var buildMapContext = BuildMapCreater.CreateBuildMap(); context.SetContextObject(buildMapContext); + UnityEngine.Debug.Log("构建内容准备完毕!"); // 检测构建结果 CheckBuildMapContent(buildMapContext); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs index f8a9a55..e720bc7 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs @@ -6,6 +6,7 @@ using UnityEditor; namespace YooAsset.Editor { + [TaskAttribute("资源构建准备工作")] public class TaskPrepare : IBuildTask { void IBuildTask.Run(BuildContext context) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs index ea28328..4f8766f 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs @@ -8,6 +8,7 @@ using UnityEngine; namespace YooAsset.Editor { + [TaskAttribute("验证构建结果")] public class TaskVerifyBuildResult : IBuildTask { void IBuildTask.Run(BuildContext context) diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleCollector.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleCollector.cs index 72f1b09..06aea2c 100644 --- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleCollector.cs +++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleCollector.cs @@ -17,7 +17,7 @@ namespace YooAsset.Editor /// /// 收集器类型 /// - public ECollectorType CollectorType = ECollectorType.MainCollector; + public ECollectorType CollectorType = ECollectorType.MainAssetCollector; /// /// 寻址规则类名 @@ -47,12 +47,19 @@ namespace YooAsset.Editor { if (AssetDatabase.LoadAssetAtPath(CollectPath) == null) return false; - if (AssetBundleGrouperSettingData.HasPackRuleName(PackRuleName) == false) - return false; - if (AssetBundleGrouperSettingData.HasFilterRuleName(FilterRuleName) == false) + + if (CollectorType == ECollectorType.None) return false; + if (AssetBundleGrouperSettingData.HasAddressRuleName(AddressRuleName) == false) return false; + + if (AssetBundleGrouperSettingData.HasPackRuleName(PackRuleName) == false) + return false; + + if (AssetBundleGrouperSettingData.HasFilterRuleName(FilterRuleName) == false) + return false; + return true; } @@ -86,8 +93,8 @@ namespace YooAsset.Editor bool isRawAsset = PackRuleName == nameof(PackRawFile); // 检测原生资源包的收集器类型 - if (isRawAsset && CollectorType != ECollectorType.MainCollector) - throw new Exception($"The raw file must be set to {nameof(ECollectorType)}.{ECollectorType.MainCollector} : {CollectPath}"); + if (isRawAsset && CollectorType != ECollectorType.MainAssetCollector) + throw new Exception($"The raw file must be set to {nameof(ECollectorType)}.{ECollectorType.MainAssetCollector} : {CollectPath}"); // 收集打包资源 if (AssetDatabase.IsValidFolder(CollectPath)) @@ -130,7 +137,7 @@ namespace YooAsset.Editor HashSet adressTemper = new HashSet(); foreach (var collectInfoPair in result) { - if (collectInfoPair.Value.CollectorType == ECollectorType.MainCollector) + if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector) { string address = collectInfoPair.Value.Address; if (adressTemper.Contains(address) == false) @@ -189,7 +196,7 @@ namespace YooAsset.Editor } private string GetAddress(AssetBundleGrouper grouper, string assetPath) { - if (CollectorType != ECollectorType.MainCollector) + if (CollectorType != ECollectorType.MainAssetCollector) return string.Empty; IAddressRule addressRuleInstance = AssetBundleGrouperSettingData.GetAddressRuleInstance(AddressRuleName); diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouper.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouper.cs index 18f16e7..6f07d88 100644 --- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouper.cs +++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouper.cs @@ -68,7 +68,7 @@ namespace YooAsset.Editor HashSet adressTemper = new HashSet(); foreach (var collectInfoPair in result) { - if (collectInfoPair.Value.CollectorType == ECollectorType.MainCollector) + if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector) { string address = collectInfoPair.Value.Address; if (adressTemper.Contains(address) == false) diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperRuntimeSupport.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperRuntimeSupport.cs index 4b585a5..9e46f09 100644 --- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperRuntimeSupport.cs +++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperRuntimeSupport.cs @@ -22,14 +22,14 @@ namespace YooAsset.Editor var collectAssetList = AssetBundleGrouperSettingData.Setting.GetAllCollectAssets(); foreach (var collectAsset in collectAssetList) { - if(collectAsset.CollectorType != ECollectorType.MainCollector) - continue; - - string address = collectAsset.Address; - if (_locationDic.ContainsKey(address)) - UnityEngine.Debug.LogWarning($"Address have existed : {address}"); - else - _locationDic.Add(address, collectAsset); + if(collectAsset.CollectorType == ECollectorType.MainAssetCollector) + { + string address = collectAsset.Address; + if (_locationDic.ContainsKey(address)) + throw new Exception($"The address is existed : {address} in grouper setting."); + else + _locationDic.Add(address, collectAsset); + } } } else @@ -37,24 +37,25 @@ namespace YooAsset.Editor var collectAssetList = AssetBundleGrouperSettingData.Setting.GetAllCollectAssets(); foreach (var collectAsset in collectAssetList) { - if (collectAsset.CollectorType != ECollectorType.MainCollector) - continue; - - // 添加原始路径 - string assetPath = collectAsset.AssetPath; - if (_locationDic.ContainsKey(assetPath)) - UnityEngine.Debug.LogWarning($"Asset path have existed : {assetPath}"); - else - _locationDic.Add(assetPath, collectAsset); - - // 添加去掉后缀名的路径 - if (Path.HasExtension(assetPath)) + if (collectAsset.CollectorType == ECollectorType.MainAssetCollector) { - string assetPathWithoutExtension = StringUtility.RemoveExtension(assetPath); - if (_locationDic.ContainsKey(assetPathWithoutExtension)) - UnityEngine.Debug.LogWarning($"Asset path have existed : {assetPathWithoutExtension}"); + // 添加原始路径 + // 注意:我们不允许原始路径存在重名 + string assetPath = collectAsset.AssetPath; + if (_locationDic.ContainsKey(assetPath)) + throw new Exception($"Asset path have existed : {assetPath}"); else - _locationDic.Add(assetPathWithoutExtension, collectAsset); + _locationDic.Add(assetPath, collectAsset); + + // 添加去掉后缀名的路径 + if (Path.HasExtension(assetPath)) + { + string assetPathWithoutExtension = StringUtility.RemoveExtension(assetPath); + if (_locationDic.ContainsKey(assetPathWithoutExtension)) + UnityEngine.Debug.LogWarning($"Asset path have existed : {assetPathWithoutExtension}"); + else + _locationDic.Add(assetPathWithoutExtension, collectAsset); + } } } } diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSetting.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSetting.cs index 864afd8..449c5d7 100644 --- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSetting.cs +++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSetting.cs @@ -66,7 +66,7 @@ namespace YooAsset.Editor HashSet adressTemper = new HashSet(); foreach (var collectInfoPair in result) { - if (collectInfoPair.Value.CollectorType == ECollectorType.MainCollector) + if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector) { string address = collectInfoPair.Value.Address; if (adressTemper.Contains(address) == false) diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperWindow.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperWindow.cs index a841a6f..d554111 100644 --- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperWindow.cs @@ -39,7 +39,12 @@ namespace YooAsset.Editor VisualElement root = this.rootVisualElement; - _collectorTypeList = new List() { $"{nameof(ECollectorType.MainCollector)}", $"{nameof(ECollectorType.StaticCollector)}"}; + _collectorTypeList = new List() + { + $"{nameof(ECollectorType.MainAssetCollector)}", + $"{nameof(ECollectorType.StaticAssetCollector)}", + $"{nameof(ECollectorType.DependAssetCollector)}" + }; _addressRuleList = AssetBundleGrouperSettingData.GetAddressRuleNames(); _packRuleList = AssetBundleGrouperSettingData.GetPackRuleNames(); _filterRuleList = AssetBundleGrouperSettingData.GetFilterRuleNames(); @@ -371,7 +376,7 @@ namespace YooAsset.Editor var foldout = new Foldout(); foldout.name = "Foldout1"; foldout.value = false; - foldout.text = "Assets"; + foldout.text = "Main Assets"; elementFoldout.Add(foldout); } @@ -474,7 +479,13 @@ namespace YooAsset.Editor // 清空旧元素 foldout.Clear(); - if (collector.IsValid() && collector.CollectorType == ECollectorType.MainCollector) + if (collector.IsValid() == false) + { + Debug.LogWarning($"The collector is invalid : {collector.CollectPath} in grouper : {grouper.GrouperName}"); + return; + } + + if (collector.CollectorType == ECollectorType.MainAssetCollector || collector.CollectorType == ECollectorType.StaticAssetCollector) { List collectAssetInfos = null; diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/ECollectorType.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/ECollectorType.cs index 826c227..3bae9e4 100644 --- a/Assets/YooAsset/Editor/AssetBundleGrouper/ECollectorType.cs +++ b/Assets/YooAsset/Editor/AssetBundleGrouper/ECollectorType.cs @@ -6,14 +6,20 @@ namespace YooAsset.Editor public enum ECollectorType { /// - /// 收集参与打包构建的资源对象,并全部写入到资源清单的资源列表里(可以通过代码加载)。 + /// 收集参与打包的主资源对象,并写入到资源清单的资源列表里(可以通过代码加载)。 /// - MainCollector, + MainAssetCollector, /// - /// 收集参与打包构建的资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。 + /// 收集参与打包的主资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。 /// - StaticCollector, + StaticAssetCollector, + + /// + /// 收集参与打包的依赖资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。 + /// 注意:如果依赖资源对象没有被主资源对象引用,则不参与打包构建。 + /// + DependAssetCollector, /// /// 该收集器类型不能被设置