From fa572e6ae1c4f7f64b58ddabbc46a55a19485bb1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 18 Nov 2024 14:59:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=80=92=E5=BD=92=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E4=BE=9D=E8=B5=96=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AssetBundleCollector.cs | 46 ++++++++++++++----- .../Editor/AssetBundleCollector/AssetStamp.cs | 33 +++++++++++++ 2 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 Assets/YooAsset/Editor/AssetBundleCollector/AssetStamp.cs diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs index 8737488..6566989 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs @@ -149,7 +149,7 @@ namespace YooAsset.Editor Dictionary result = new Dictionary(1000); // 收集打包资源路径 - List findAssets =new List(); + List findAssets = new List(); if (AssetDatabase.IsValidFolder(CollectPath)) { string collectDirectory = CollectPath; @@ -272,19 +272,43 @@ namespace YooAsset.Editor } private List GetAllDependencies(CollectCommand command, string mainAssetPath) { - string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true); - List result = new List(depends.Length); - foreach (string assetPath in depends) + List dependencies = new List(); + HashSet m_AssetStamps = new HashSet(); + void GetDependRecursive(string assetPath) { - // 注意:排除主资源对象 - if (assetPath == mainAssetPath) - continue; + string[] depends = AssetDatabase.GetDependencies(assetPath, false); - AssetInfo assetInfo = new AssetInfo(assetPath); - if (command.IgnoreRule.IsIgnore(assetInfo) == false) - result.Add(assetInfo); + foreach (string dependPath in depends) + { + AssetInfo assetInfo = new AssetInfo(dependPath); + + // 注意:排除资源自身 + if (dependPath == assetPath) + continue; + //排除主资源 + if (dependPath == mainAssetPath) + continue; + + var stamp = new AssetStamp(mainAssetPath, dependPath); + + //主资源对于一个资源只有一个依赖 + if (m_AssetStamps.Contains(stamp)) + continue; + m_AssetStamps.Add(stamp); + + //根据忽略规则排除 + if (command.IgnoreRule.IsIgnore(assetInfo)) + continue; + + dependencies.Add(assetInfo); + + GetDependRecursive(dependPath); + } } - return result; + + GetDependRecursive(mainAssetPath); + + return dependencies; } } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetStamp.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetStamp.cs new file mode 100644 index 0000000..476c9a2 --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetStamp.cs @@ -0,0 +1,33 @@ +using System.Runtime.InteropServices; + +namespace YooAsset.Editor +{ + [StructLayout(LayoutKind.Auto)] + internal struct AssetStamp + { + private readonly string m_AssetName; + private readonly string m_DependAssetPath; + + public AssetStamp(string assetName, string dependencyAssetName) + { + m_AssetName = assetName; + m_DependAssetPath = dependencyAssetName; + } + + public string AssetName + { + get + { + return m_AssetName; + } + } + + public string DependAssetPath + { + get + { + return m_DependAssetPath; + } + } + } +} From 008a3e1893dae45be1e4a3398c4a45aa074ee1de Mon Sep 17 00:00:00 2001 From: absences <49706424+absences@users.noreply.github.com> Date: Thu, 21 Nov 2024 18:49:17 +0800 Subject: [PATCH 2/2] Update AssetBundleCollector.cs --- .../Editor/AssetBundleCollector/AssetBundleCollector.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs index 6566989..ac3ec74 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs @@ -280,8 +280,6 @@ namespace YooAsset.Editor foreach (string dependPath in depends) { - AssetInfo assetInfo = new AssetInfo(dependPath); - // 注意:排除资源自身 if (dependPath == assetPath) continue; @@ -295,7 +293,9 @@ namespace YooAsset.Editor if (m_AssetStamps.Contains(stamp)) continue; m_AssetStamps.Add(stamp); - + + AssetInfo assetInfo = new AssetInfo(dependPath); + //根据忽略规则排除 if (command.IgnoreRule.IsIgnore(assetInfo)) continue; @@ -311,4 +311,4 @@ namespace YooAsset.Editor return dependencies; } } -} \ No newline at end of file +}