From b59fb0d81190f8294391fba38a383e4def4be614 Mon Sep 17 00:00:00 2001 From: hevinci Date: Fri, 17 Jun 2022 12:05:14 +0800 Subject: [PATCH] Optimize share bundle pack logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化了共享资源的打包逻辑。 --- .../Editor/AssetBundleBuilder/BuildAssetInfo.cs | 16 +++++++--------- .../Editor/AssetBundleBuilder/BuildMapCreater.cs | 2 +- .../AssetBundleCollector/DefaultPackRule.cs | 2 ++ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs index 30beae0..913ac92 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs @@ -9,9 +9,9 @@ namespace YooAsset.Editor { private string _mainBundleName; private string _shareBundleName; - private readonly HashSet _referenceBundleNames = new HashSet(); private bool _isAddAssetTags = false; - + private readonly HashSet _referenceBundleNames = new HashSet(); + /// /// 收集器类型 /// @@ -68,9 +68,9 @@ namespace YooAsset.Editor else IsShaderAsset = false; } - public BuildAssetInfo(ECollectorType collectorType, string assetPath) + public BuildAssetInfo(string assetPath) { - CollectorType = collectorType; + CollectorType = ECollectorType.None; Address = string.Empty; AssetPath = assetPath; IsRawAsset = false; @@ -185,11 +185,9 @@ namespace YooAsset.Editor if (_referenceBundleNames.Count > 1) { - var bundleNameList = _referenceBundleNames.ToList(); - bundleNameList.Sort(); - string combineName = string.Join("|", bundleNameList); - var combineNameHash = HashUtility.StringSHA1(combineName); - var shareBundleName = $"share_{combineNameHash}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}"; + IPackRule packRule = PackDirectory.StaticPackRule; + var bundleName = packRule.GetBundleName(new PackRuleData(AssetPath)); + var shareBundleName = $"share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}"; _shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower(); } } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs index 5ff7128..4a1ac2b 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs @@ -65,7 +65,7 @@ namespace YooAsset.Editor } else { - var buildAssetInfo = new BuildAssetInfo(ECollectorType.None, dependAssetPath); + var buildAssetInfo = new BuildAssetInfo(dependAssetPath); buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags); buildAssetInfo.AddReferenceBundleName(collectAssetInfo.BundleName); buildAssetDic.Add(dependAssetPath, buildAssetInfo); diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs index 0be3ecb..d081c58 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/DefaultPackRule.cs @@ -28,6 +28,8 @@ namespace YooAsset.Editor /// public class PackDirectory : IPackRule { + public static PackDirectory StaticPackRule = new PackDirectory(); + string IPackRule.GetBundleName(PackRuleData data) { return Path.GetDirectoryName(data.AssetPath);