From 67eeae31c794610f4dae0e35718931a7eae78a85 Mon Sep 17 00:00:00 2001 From: hevinci Date: Wed, 11 May 2022 16:23:31 +0800 Subject: [PATCH] Update patch manifest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新资源清单:资源对象增加分类标签。 --- .../AssetBundleBuilder/BuildAssetInfo.cs | 32 +++++++++++++++++-- .../AssetBundleBuilder/BuildBundleInfo.cs | 6 ++-- .../AssetBundleBuilder/BuildMapContext.cs | 6 ++-- .../AssetBundleBuilder/BuildMapCreater.cs | 14 ++++---- .../BuildReport/ReportAssetInfo.cs | 5 +++ .../BuildTasks/TaskCreatePatchManifest.cs | 3 +- .../BuildTasks/TaskCreateReport.cs | 1 + .../Runtime/PatchSystem/PatchAsset.cs | 25 +++++++++++++++ .../Runtime/PatchSystem/PatchBundle.cs | 2 +- 9 files changed, 77 insertions(+), 17 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs index d360fc5..30beae0 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs @@ -10,7 +10,8 @@ namespace YooAsset.Editor private string _mainBundleName; private string _shareBundleName; private readonly HashSet _referenceBundleNames = new HashSet(); - + private bool _isAddAssetTags = false; + /// /// 收集器类型 /// @@ -37,10 +38,15 @@ namespace YooAsset.Editor public bool IsShaderAsset { private set; get; } /// - /// 资源分类标签列表 + /// 资源的分类标签 /// public readonly List AssetTags = new List(); + /// + /// 资源包的分类标签 + /// + public readonly List BundleTags = new List(); + /// /// 依赖的所有资源 /// 注意:包括零依赖资源和冗余资源(资源包名无效) @@ -89,10 +95,15 @@ namespace YooAsset.Editor } /// - /// 添加资源分类标签 + /// 添加资源的分类标签 + /// 说明:原始定义的资源分类标签 /// public void AddAssetTags(List tags) { + if (_isAddAssetTags) + throw new Exception("Should never get here !"); + _isAddAssetTags = true; + foreach (var tag in tags) { if (AssetTags.Contains(tag) == false) @@ -101,6 +112,21 @@ namespace YooAsset.Editor } } } + + /// + /// 添加资源包的分类标签 + /// 说明:传染算法统计到的分类标签 + /// + public void AddBundleTags(List tags) + { + foreach (var tag in tags) + { + if (BundleTags.Contains(tag) == false) + { + BundleTags.Add(tag); + } + } + } /// /// 资源包名是否存在 diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs index de88bc6..b5b1b70 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs @@ -68,14 +68,14 @@ namespace YooAsset.Editor } /// - /// 获取资源标签列表 + /// 获取资源包的分类标签列表 /// - public string[] GetAssetTags() + public string[] GetBundleTags() { List result = new List(BuildinAssets.Count); foreach (var assetInfo in BuildinAssets) { - foreach (var assetTag in assetInfo.AssetTags) + foreach (var assetTag in assetInfo.BundleTags) { if (result.Contains(assetTag) == false) result.Add(assetTag); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs index 44e4995..ceab13f 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs @@ -55,13 +55,13 @@ namespace YooAsset.Editor } /// - /// 获取AssetBundle内包含的标记列表 + /// 获取资源包的分类标签列表 /// - public string[] GetAssetTags(string bundleName) + public string[] GetBundleTags(string bundleName) { if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo)) { - return bundleInfo.GetAssetTags(); + return bundleInfo.GetBundleTags(); } throw new Exception($"Not found {nameof(BuildBundleInfo)} : {bundleName}"); } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs index faf5935..5ff7128 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs @@ -18,7 +18,7 @@ namespace YooAsset.Editor // 1. 检测配置合法性 AssetBundleCollectorSettingData.Setting.CheckConfigError(); - // 2. 获取所有主动收集的资源 + // 2. 获取所有收集器收集的资源 List allCollectAssets = AssetBundleCollectorSettingData.Setting.GetAllCollectAssets(buildMode); // 3. 剔除未被引用的依赖资源 @@ -36,13 +36,15 @@ namespace YooAsset.Editor allCollectAssets.Remove(removeValue); } - // 4. 录入主动收集的资源 + // 4. 录入所有收集器收集的资源 foreach (var collectAssetInfo in allCollectAssets) { if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false) { - var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName, collectAssetInfo.Address, collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset); + var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName, + collectAssetInfo.Address, collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset); buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags); + buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags); buildAssetDic.Add(collectAssetInfo.AssetPath, buildAssetInfo); } else @@ -58,13 +60,13 @@ namespace YooAsset.Editor { if (buildAssetDic.ContainsKey(dependAssetPath)) { - buildAssetDic[dependAssetPath].AddAssetTags(collectAssetInfo.AssetTags); + buildAssetDic[dependAssetPath].AddBundleTags(collectAssetInfo.AssetTags); buildAssetDic[dependAssetPath].AddReferenceBundleName(collectAssetInfo.BundleName); } else { var buildAssetInfo = new BuildAssetInfo(ECollectorType.None, dependAssetPath); - buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags); + buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags); buildAssetInfo.AddReferenceBundleName(collectAssetInfo.BundleName); buildAssetDic.Add(dependAssetPath, buildAssetInfo); } @@ -92,7 +94,7 @@ namespace YooAsset.Editor pair.Value.CalculateFullBundleName(); } - // 8. 移除未参与构建的资源 + // 8. 移除不参与构建的资源 List removeBuildList = new List(); foreach (KeyValuePair pair in buildAssetDic) { diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportAssetInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportAssetInfo.cs index aef363d..b23823b 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportAssetInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportAssetInfo.cs @@ -22,6 +22,11 @@ namespace YooAsset.Editor /// 说明:Meta文件记录的GUID /// public string AssetGUID; + + /// + /// 资源的分类标签 + /// + public string[] AssetTags; /// /// 所属资源包名称 diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs index 9be9aa4..bbe7984 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs @@ -70,7 +70,7 @@ namespace YooAsset.Editor string hash = GetFileHash(filePath, standardBuild); string crc32 = GetFileCRC(filePath, standardBuild); long size = GetFileSize(filePath, standardBuild); - string[] tags = buildMapContext.GetAssetTags(bundleName); + string[] tags = buildMapContext.GetBundleTags(bundleName); bool isEncrypted = encryptionContext.IsEncryptFile(bundleName); bool isBuildin = IsBuildinBundle(tags, buildinTags); bool isRawFile = bundleInfo.IsRawFile; @@ -141,6 +141,7 @@ namespace YooAsset.Editor else patchAsset.Address = string.Empty; patchAsset.AssetPath = assetInfo.AssetPath; + patchAsset.AssetTags = assetInfo.AssetTags.ToArray(); patchAsset.BundleID = GetAssetBundleID(assetInfo.GetBundleName(), patchManifest); patchAsset.DependIDs = GetAssetBundleDependIDs(patchAsset.BundleID, assetInfo, patchManifest); result.Add(patchAsset); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs index 3b457ab..c0b895f 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs @@ -75,6 +75,7 @@ namespace YooAsset.Editor ReportAssetInfo reportAssetInfo = new ReportAssetInfo(); reportAssetInfo.Address = patchAsset.Address; reportAssetInfo.AssetPath = patchAsset.AssetPath; + reportAssetInfo.AssetTags = patchAsset.AssetTags; reportAssetInfo.AssetGUID = AssetDatabase.AssetPathToGUID(patchAsset.AssetPath); reportAssetInfo.MainBundleName = mainBundle.BundleName; reportAssetInfo.MainBundleSize = mainBundle.SizeBytes; diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchAsset.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchAsset.cs index e06f712..6cd35d9 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchAsset.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PatchAsset.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; namespace YooAsset { @@ -15,6 +16,11 @@ namespace YooAsset /// public string AssetPath; + /// + /// 资源的分类标签 + /// + public string[] AssetTags; + /// /// 所属资源包ID /// @@ -24,5 +30,24 @@ namespace YooAsset /// 依赖的资源包ID列表 /// public int[] DependIDs; + + + /// + /// 是否包含Tag + /// + public bool HasTag(string[] tags) + { + if (tags == null || tags.Length == 0) + return false; + if (AssetTags == null || AssetTags.Length == 0) + return false; + + foreach (var tag in tags) + { + if (AssetTags.Contains(tag)) + return true; + } + return false; + } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs index 9d95f8e..a343fa9 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs @@ -27,7 +27,7 @@ namespace YooAsset public long SizeBytes; /// - /// Tags + /// 资源包的分类标签 /// public string[] Tags;