From b7a20d4bdb7c9f8f235269695ec8b4c9c1a0ae7a Mon Sep 17 00:00:00 2001 From: hevinci Date: Thu, 7 Apr 2022 19:15:24 +0800 Subject: [PATCH] Update AssetBundleTools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复了资源分组在特殊情况下打包报错的问题 --- .../AssetBundleBuilder/BuildBundleInfo.cs | 5 +--- .../AssetBundleBuilder/BuildMapHelper.cs | 2 +- .../AssetBundleCollector.cs | 30 +++++++++++++------ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs index 4e92e01..e43df92 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs @@ -89,10 +89,7 @@ namespace YooAsset.Editor /// public string GetAppendExtension() { - if (IsRawFile) - return $".{YooAssetSettingsData.Setting.RawFileVariant}"; - else - return $".{YooAssetSettingsData.Setting.AssetBundleFileVariant}"; + return System.IO.Path.GetExtension(BundleName); } /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs index d09141c..526903c 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs @@ -94,7 +94,7 @@ namespace YooAsset.Editor if (buildAssetInfo.BundleNameIsValid() == false) { string bundleName = defaultPackRule.GetBundleName(new PackRuleData(buildAssetInfo.AssetPath)); - bundleName = AssetBundleCollector.RevisedBundleName(bundleName); + bundleName = AssetBundleCollector.RevisedBundleName(bundleName, false); buildAssetInfo.SetBundleName(bundleName); } } diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleCollector.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleCollector.cs index ba62b63..0a8f497 100644 --- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleCollector.cs +++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleCollector.cs @@ -71,7 +71,7 @@ namespace YooAsset.Editor continue; if (result.ContainsKey(assetPath) == false) { - string bundleName = GetBundleName(grouper, assetPath); + string bundleName = GetBundleName(grouper, assetPath, isRawAsset); List assetTags = GetAssetTags(grouper); var collectAssetInfo = new CollectAssetInfo(bundleName, assetPath, assetTags, isRawAsset, NotWriteToAssetList); collectAssetInfo.DependAssets = GetAllDependencies(assetPath); @@ -91,7 +91,7 @@ namespace YooAsset.Editor if (isRawAsset && NotWriteToAssetList) UnityEngine.Debug.LogWarning($"Are you sure raw file are not write to asset list : {assetPath}"); - string bundleName = GetBundleName(grouper, assetPath); + string bundleName = GetBundleName(grouper, assetPath, isRawAsset); List assetTags = GetAssetTags(grouper); var collectAssetInfo = new CollectAssetInfo(bundleName, assetPath, assetTags, isRawAsset, NotWriteToAssetList); result.Add(assetPath, collectAssetInfo); @@ -139,7 +139,7 @@ namespace YooAsset.Editor IFilterRule filterRuleInstance = AssetBundleGrouperSettingData.GetFilterRuleInstance(FilterRuleName); return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetPath)); } - private string GetBundleName(AssetBundleGrouper grouper, string assetPath) + private string GetBundleName(AssetBundleGrouper grouper, string assetPath, bool isRawAsset) { // 如果收集全路径着色器 if (AssetBundleGrouperSettingData.Setting.AutoCollectShaders) @@ -147,14 +147,17 @@ namespace YooAsset.Editor System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); if (assetType == typeof(UnityEngine.Shader)) { - return RevisedBundleName(AssetBundleGrouperSettingData.Setting.ShadersBundleName); + string bundleName = AssetBundleGrouperSettingData.Setting.ShadersBundleName; + return RevisedBundleName(bundleName, false); } } // 根据规则设置获取资源包名称 - IPackRule packRuleInstance = AssetBundleGrouperSettingData.GetPackRuleInstance(PackRuleName); - string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, grouper.GrouperName)); - return RevisedBundleName(bundleName); + { + IPackRule packRuleInstance = AssetBundleGrouperSettingData.GetPackRuleInstance(PackRuleName); + string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, grouper.GrouperName)); + return RevisedBundleName(bundleName, isRawAsset); + } } private List GetAssetTags(AssetBundleGrouper grouper) { @@ -183,9 +186,18 @@ namespace YooAsset.Editor /// /// 修正资源包名 /// - public static string RevisedBundleName(string bundleName) + public static string RevisedBundleName(string bundleName, bool isRawBundle) { - return EditorTools.GetRegularPath(bundleName).ToLower(); + if (isRawBundle) + { + string fullName = $"{bundleName}.{YooAssetSettingsData.Setting.RawFileVariant}"; + return EditorTools.GetRegularPath(fullName).ToLower(); + } + else + { + string fullName = $"{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}"; + return EditorTools.GetRegularPath(fullName).ToLower(); ; + } } } } \ No newline at end of file