absences 2024-12-12 21:37:10 +08:00 committed by GitHub
commit a9f8449d86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 69 additions and 12 deletions

View File

@ -149,7 +149,7 @@ namespace YooAsset.Editor
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000); Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000);
// 收集打包资源路径 // 收集打包资源路径
List<string> findAssets =new List<string>(); List<string> findAssets = new List<string>();
if (AssetDatabase.IsValidFolder(CollectPath)) if (AssetDatabase.IsValidFolder(CollectPath))
{ {
string collectDirectory = CollectPath; string collectDirectory = CollectPath;
@ -272,19 +272,43 @@ namespace YooAsset.Editor
} }
private List<AssetInfo> GetAllDependencies(CollectCommand command, string mainAssetPath) private List<AssetInfo> GetAllDependencies(CollectCommand command, string mainAssetPath)
{ {
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true); List<AssetInfo> dependencies = new List<AssetInfo>();
List<AssetInfo> result = new List<AssetInfo>(depends.Length); HashSet<AssetStamp> m_AssetStamps = new HashSet<AssetStamp>();
foreach (string assetPath in depends) void GetDependRecursive(string assetPath)
{ {
// 注意:排除主资源对象 string[] depends = AssetDatabase.GetDependencies(assetPath, false);
if (assetPath == mainAssetPath)
continue;
AssetInfo assetInfo = new AssetInfo(assetPath); foreach (string dependPath in depends)
if (command.IgnoreRule.IsIgnore(assetInfo) == false) {
result.Add(assetInfo); // 注意:排除资源自身
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;
} }
} }
} }

View File

@ -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;
}
}
}
}