From 48356a4f9e2163cfa392d7b9ff7631f477987afb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Tue, 17 Jun 2025 18:20:28 +0800 Subject: [PATCH] fix #573 --- .../AssetDependencyDatabase.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetDependencyDatabase.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetDependencyDatabase.cs index 9a8d4618..b54f42ab 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetDependencyDatabase.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetDependencyDatabase.cs @@ -187,16 +187,30 @@ namespace YooAsset.Editor } var result = new HashSet { assetPath }; - CollectDependencies(assetPath, result, recursive); + CollectDependencies(assetPath, assetPath, result, recursive); // 注意:AssetDatabase.GetDependencies保持一致,将主资源添加到依赖列表最前面 return result.ToArray(); } - private void CollectDependencies(string assetPath, HashSet result, bool recursive) + private void CollectDependencies(string parent, string assetPath, HashSet result, bool recursive) { if (_database.TryGetValue(assetPath, out var cacheInfo) == false) { - throw new Exception($"Fatal : can not found cache info : {assetPath}"); + // 说明:检测是否为丢失引用的资产 +#if UNITY_2021_3_OR_NEWER + var assetGUID = AssetDatabase.AssetPathToGUID(assetPath, AssetPathToGUIDOptions.OnlyExistingAssets); +#else + var assetGUID = AssetDatabase.AssetPathToGUID(assetPath); +#endif + if (string.IsNullOrEmpty(assetGUID)) + { + Debug.LogWarning($"{parent} found missing asset : {assetPath}"); + return; + } + else + { + throw new Exception($"Fatal : can not found cache info : {assetPath}"); + } } foreach (var dependGUID in cacheInfo.DependGUIDs) @@ -217,7 +231,7 @@ namespace YooAsset.Editor // 递归收集依赖 if (recursive) - CollectDependencies(dependAssetPath, result, recursive); + CollectDependencies(assetPath, dependAssetPath, result, recursive); } }