diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs index 8737488..ac3ec74 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) + { + // 注意:排除资源自身 + if (dependPath == assetPath) + continue; + //排除主资源 + if (dependPath == mainAssetPath) + continue; + + var stamp = new AssetStamp(mainAssetPath, dependPath); + + //主资源对于一个资源只有一个依赖 + if (m_AssetStamps.Contains(stamp)) + continue; + m_AssetStamps.Add(stamp); + + AssetInfo assetInfo = new AssetInfo(dependPath); + + //根据忽略规则排除 + 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; + } + } + } +}