Compare commits

...

3 Commits

Author SHA1 Message Date
absences 0dd97e9004
Merge 008a3e1893 into d890ccd5e6 2024-12-11 10:43:24 +08:00
absences 008a3e1893
Update AssetBundleCollector.cs 2024-11-21 18:49:17 +08:00
unknown fa572e6ae1 递归获取资源依赖列表 2024-11-18 14:59:30 +08:00
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;
}
}
}
}