mirror of https://github.com/tuyoogame/YooAsset
refactor : editor code
parent
82b2a5cc20
commit
e8e7696a4d
|
@ -26,19 +26,9 @@ namespace YooAsset.Editor
|
|||
public string Address { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// 资源信息
|
||||
/// </summary>
|
||||
public string AssetPath { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源GUID
|
||||
/// </summary>
|
||||
public string AssetGUID { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源类型
|
||||
/// </summary>
|
||||
public System.Type AssetType { private set; get; }
|
||||
public AssetInfo AssetInfo { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源的分类标签
|
||||
|
@ -52,25 +42,19 @@ namespace YooAsset.Editor
|
|||
public List<BuildAssetInfo> AllDependAssetInfos { private set; get; }
|
||||
|
||||
|
||||
public BuildAssetInfo(ECollectorType collectorType, string bundleName, string address, string assetPath)
|
||||
public BuildAssetInfo(ECollectorType collectorType, string bundleName, string address, AssetInfo assetInfo)
|
||||
{
|
||||
CollectorType = collectorType;
|
||||
BundleName = bundleName;
|
||||
Address = address;
|
||||
AssetPath = assetPath;
|
||||
|
||||
AssetGUID = UnityEditor.AssetDatabase.AssetPathToGUID(assetPath);
|
||||
AssetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
AssetInfo = assetInfo;
|
||||
}
|
||||
public BuildAssetInfo(string assetPath)
|
||||
public BuildAssetInfo(AssetInfo assetInfo)
|
||||
{
|
||||
CollectorType = ECollectorType.None;
|
||||
BundleName = string.Empty;
|
||||
Address = string.Empty;
|
||||
AssetPath = assetPath;
|
||||
|
||||
AssetGUID = UnityEditor.AssetDatabase.AssetPathToGUID(assetPath);
|
||||
AssetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
AssetInfo = assetInfo;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -82,12 +82,12 @@ namespace YooAsset.Editor
|
|||
/// <summary>
|
||||
/// 添加一个打包资源
|
||||
/// </summary>
|
||||
public void PackAsset(BuildAssetInfo assetInfo)
|
||||
public void PackAsset(BuildAssetInfo buildAsset)
|
||||
{
|
||||
if (IsContainsAsset(assetInfo.AssetPath))
|
||||
throw new System.Exception($"Should never get here ! Asset is existed : {assetInfo.AssetPath}");
|
||||
if (IsContainsAsset(buildAsset.AssetInfo.AssetPath))
|
||||
throw new System.Exception($"Should never get here ! Asset is existed : {buildAsset.AssetInfo.AssetPath}");
|
||||
|
||||
MainAssets.Add(assetInfo);
|
||||
MainAssets.Add(buildAsset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -95,9 +95,9 @@ namespace YooAsset.Editor
|
|||
/// </summary>
|
||||
public bool IsContainsAsset(string assetPath)
|
||||
{
|
||||
foreach (var assetInfo in MainAssets)
|
||||
foreach (var buildAsset in MainAssets)
|
||||
{
|
||||
if (assetInfo.AssetPath == assetPath)
|
||||
if (buildAsset.AssetInfo.AssetPath == assetPath)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ namespace YooAsset.Editor
|
|||
/// </summary>
|
||||
public string[] GetAllMainAssetPaths()
|
||||
{
|
||||
return MainAssets.Select(t => t.AssetPath).ToArray();
|
||||
return MainAssets.Select(t => t.AssetInfo.AssetPath).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -120,17 +120,17 @@ namespace YooAsset.Editor
|
|||
{
|
||||
var packAssets = GetAllMainAssetPaths();
|
||||
List<string> result = new List<string>(packAssets);
|
||||
foreach (var assetInfo in MainAssets)
|
||||
foreach (var buildAsset in MainAssets)
|
||||
{
|
||||
if (assetInfo.AllDependAssetInfos == null)
|
||||
if (buildAsset.AllDependAssetInfos == null)
|
||||
continue;
|
||||
foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos)
|
||||
foreach (var dependAssetInfo in buildAsset.AllDependAssetInfos)
|
||||
{
|
||||
// 注意:依赖资源里只添加零依赖资源和冗余资源
|
||||
if (dependAssetInfo.HasBundleName() == false)
|
||||
{
|
||||
if (result.Contains(dependAssetInfo.AssetPath) == false)
|
||||
result.Add(dependAssetInfo.AssetPath);
|
||||
if (result.Contains(dependAssetInfo.AssetInfo.AssetPath) == false)
|
||||
result.Add(dependAssetInfo.AssetInfo.AssetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,13 @@ namespace YooAsset.Editor
|
|||
/// <summary>
|
||||
/// 冗余的资源列表
|
||||
/// </summary>
|
||||
public readonly List<ReportRedundancyInfo> RedundancyInfos = new List<ReportRedundancyInfo>(1000);
|
||||
|
||||
public readonly List<ReportRedundancyAsset> RedundancyInfos = new List<ReportRedundancyAsset>(1000);
|
||||
|
||||
/// <summary>
|
||||
/// 未被依赖的资源列表
|
||||
/// </summary>
|
||||
public readonly List<AssetInfo> UndependAssets = new List<AssetInfo>(1000);
|
||||
|
||||
/// <summary>
|
||||
/// 参与构建的资源总数
|
||||
/// 说明:包括主动收集的资源以及其依赖的所有资源
|
||||
|
|
|
@ -105,8 +105,8 @@ namespace YooAsset.Editor
|
|||
{
|
||||
PackageAsset packageAsset = new PackageAsset();
|
||||
packageAsset.Address = buildMapContext.Command.EnableAddressable ? assetInfo.Address : string.Empty;
|
||||
packageAsset.AssetPath = assetInfo.AssetPath;
|
||||
packageAsset.AssetGUID = buildMapContext.Command.IncludeAssetGUID ? assetInfo.AssetGUID : string.Empty;
|
||||
packageAsset.AssetPath = assetInfo.AssetInfo.AssetPath;
|
||||
packageAsset.AssetGUID = buildMapContext.Command.IncludeAssetGUID ? assetInfo.AssetInfo.AssetGUID : string.Empty;
|
||||
packageAsset.AssetTags = assetInfo.AssetTags.ToArray();
|
||||
packageAsset.BundleID = GetCachedBundleID(assetInfo.BundleName);
|
||||
result.Add(packageAsset);
|
||||
|
|
|
@ -108,7 +108,7 @@ namespace YooAsset.Editor
|
|||
}
|
||||
|
||||
// 冗余资源列表
|
||||
buildReport.RedundancyInfos = new List<ReportRedundancyInfo>(buildMapContext.RedundancyInfos);
|
||||
buildReport.RedundancyAssets = new List<ReportRedundancyAsset>(buildMapContext.RedundancyInfos);
|
||||
|
||||
// 序列化文件
|
||||
string fileName = YooAssetSettingsData.GetReportFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
|
@ -140,11 +140,11 @@ namespace YooAsset.Editor
|
|||
var bundleInfo = buildMapContext.GetBundleInfo(bundleName);
|
||||
{
|
||||
BuildAssetInfo findAssetInfo = null;
|
||||
foreach (var assetInfo in bundleInfo.MainAssets)
|
||||
foreach (var buildAsset in bundleInfo.MainAssets)
|
||||
{
|
||||
if (assetInfo.AssetPath == assetPath)
|
||||
if (buildAsset.AssetInfo.AssetPath == assetPath)
|
||||
{
|
||||
findAssetInfo = assetInfo;
|
||||
findAssetInfo = buildAsset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ namespace YooAsset.Editor
|
|||
}
|
||||
foreach (var dependAssetInfo in findAssetInfo.AllDependAssetInfos)
|
||||
{
|
||||
result.Add(dependAssetInfo.AssetPath);
|
||||
result.Add(dependAssetInfo.AssetInfo.AssetPath);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace YooAsset.Editor
|
|||
/// </summary>
|
||||
public BuildMapContext CreateBuildMap(BuildParameters buildParameters)
|
||||
{
|
||||
BuildMapContext context = new BuildMapContext();
|
||||
var buildMode = buildParameters.BuildMode;
|
||||
var packageName = buildParameters.PackageName;
|
||||
|
||||
|
@ -21,67 +22,65 @@ namespace YooAsset.Editor
|
|||
|
||||
// 1. 获取所有收集器收集的资源
|
||||
var collectResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName);
|
||||
List<CollectAssetInfo> allCollectAssetInfos = collectResult.CollectAssets;
|
||||
List<CollectAssetInfo> allCollectAssets = collectResult.CollectAssets;
|
||||
|
||||
// 2. 剔除未被引用的依赖项资源
|
||||
RemoveZeroReferenceAssets(allCollectAssetInfos);
|
||||
RemoveZeroReferenceAssets(context, allCollectAssets);
|
||||
|
||||
// 3. 录入所有收集器主动收集的资源
|
||||
foreach (var collectAssetInfo in allCollectAssetInfos)
|
||||
foreach (var collectAssetInfo in allCollectAssets)
|
||||
{
|
||||
if (allBuildAssetInfos.ContainsKey(collectAssetInfo.AssetPath) == false)
|
||||
{
|
||||
if (collectAssetInfo.CollectorType != ECollectorType.MainAssetCollector)
|
||||
{
|
||||
if (collectAssetInfo.AssetTags.Count > 0)
|
||||
{
|
||||
collectAssetInfo.AssetTags.Clear();
|
||||
string warning = BuildLogger.GetErrorMessage(ErrorCode.RemoveInvalidTags, $"Remove asset tags that don't work, see the asset collector type : {collectAssetInfo.AssetPath}");
|
||||
BuildLogger.Warning(warning);
|
||||
}
|
||||
}
|
||||
|
||||
var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName, collectAssetInfo.Address, collectAssetInfo.AssetPath);
|
||||
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
|
||||
allBuildAssetInfos.Add(collectAssetInfo.AssetPath, buildAssetInfo);
|
||||
}
|
||||
else
|
||||
if (allBuildAssetInfos.ContainsKey(collectAssetInfo.AssetInfo.AssetPath))
|
||||
{
|
||||
throw new Exception($"Should never get here !");
|
||||
}
|
||||
|
||||
if (collectAssetInfo.CollectorType != ECollectorType.MainAssetCollector)
|
||||
{
|
||||
if (collectAssetInfo.AssetTags.Count > 0)
|
||||
{
|
||||
collectAssetInfo.AssetTags.Clear();
|
||||
string warning = BuildLogger.GetErrorMessage(ErrorCode.RemoveInvalidTags, $"Remove asset tags that don't work, see the asset collector type : {collectAssetInfo.AssetInfo.AssetPath}");
|
||||
BuildLogger.Warning(warning);
|
||||
}
|
||||
}
|
||||
|
||||
var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName, collectAssetInfo.Address, collectAssetInfo.AssetInfo);
|
||||
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
|
||||
allBuildAssetInfos.Add(collectAssetInfo.AssetInfo.AssetPath, buildAssetInfo);
|
||||
}
|
||||
|
||||
// 4. 录入所有收集资源依赖的其它资源
|
||||
foreach (var collectAssetInfo in allCollectAssetInfos)
|
||||
foreach (var collectAssetInfo in allCollectAssets)
|
||||
{
|
||||
string bundleName = collectAssetInfo.BundleName;
|
||||
foreach (var dependAssetPath in collectAssetInfo.DependAssets)
|
||||
foreach (var dependAsset in collectAssetInfo.DependAssets)
|
||||
{
|
||||
if (allBuildAssetInfos.ContainsKey(dependAssetPath))
|
||||
if (allBuildAssetInfos.ContainsKey(dependAsset.AssetPath))
|
||||
{
|
||||
allBuildAssetInfos[dependAssetPath].AddReferenceBundleName(bundleName);
|
||||
allBuildAssetInfos[dependAsset.AssetPath].AddReferenceBundleName(bundleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
var buildAssetInfo = new BuildAssetInfo(dependAssetPath);
|
||||
var buildAssetInfo = new BuildAssetInfo(dependAsset);
|
||||
buildAssetInfo.AddReferenceBundleName(bundleName);
|
||||
allBuildAssetInfos.Add(dependAssetPath, buildAssetInfo);
|
||||
allBuildAssetInfos.Add(dependAsset.AssetPath, buildAssetInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 填充所有收集资源的依赖列表
|
||||
foreach (var collectAssetInfo in allCollectAssetInfos)
|
||||
foreach (var collectAssetInfo in allCollectAssets)
|
||||
{
|
||||
var dependAssetInfos = new List<BuildAssetInfo>(collectAssetInfo.DependAssets.Count);
|
||||
foreach (var dependAssetPath in collectAssetInfo.DependAssets)
|
||||
foreach (var dependAsset in collectAssetInfo.DependAssets)
|
||||
{
|
||||
if (allBuildAssetInfos.TryGetValue(dependAssetPath, out BuildAssetInfo value))
|
||||
if (allBuildAssetInfos.TryGetValue(dependAsset.AssetPath, out BuildAssetInfo value))
|
||||
dependAssetInfos.Add(value);
|
||||
else
|
||||
throw new Exception("Should never get here !");
|
||||
}
|
||||
allBuildAssetInfos[collectAssetInfo.AssetPath].SetDependAssetInfos(dependAssetInfos);
|
||||
allBuildAssetInfos[collectAssetInfo.AssetInfo.AssetPath].SetDependAssetInfos(dependAssetInfos);
|
||||
}
|
||||
|
||||
// 6. 自动收集所有依赖的着色器
|
||||
|
@ -91,7 +90,7 @@ namespace YooAsset.Editor
|
|||
{
|
||||
if (buildAssetInfo.CollectorType == ECollectorType.None)
|
||||
{
|
||||
if (buildAssetInfo.AssetType == typeof(UnityEngine.Shader) || buildAssetInfo.AssetType == typeof(UnityEngine.ShaderVariantCollection))
|
||||
if (buildAssetInfo.AssetInfo.IsShaderAsset())
|
||||
{
|
||||
buildAssetInfo.SetShaderBundleName(collectResult.Command.PackageName, collectResult.Command.UniqueBundleName);
|
||||
}
|
||||
|
@ -100,7 +99,6 @@ namespace YooAsset.Editor
|
|||
}
|
||||
|
||||
// 7. 记录关键信息
|
||||
BuildMapContext context = new BuildMapContext();
|
||||
context.AssetFileCount = allBuildAssetInfos.Count;
|
||||
context.Command = collectResult.Command;
|
||||
|
||||
|
@ -109,11 +107,9 @@ namespace YooAsset.Editor
|
|||
{
|
||||
if (buildAssetInfo.IsRedundancyAsset())
|
||||
{
|
||||
var redundancyInfo = new ReportRedundancyInfo();
|
||||
redundancyInfo.AssetPath = buildAssetInfo.AssetPath;
|
||||
redundancyInfo.AssetType = buildAssetInfo.AssetType.Name;
|
||||
redundancyInfo.AssetGUID = buildAssetInfo.AssetGUID;
|
||||
redundancyInfo.FileSize = FileUtility.GetFileSize(buildAssetInfo.AssetPath);
|
||||
var redundancyInfo = new ReportRedundancyAsset();
|
||||
redundancyInfo.AssetInfo = buildAssetInfo.AssetInfo;
|
||||
redundancyInfo.FileSize = FileUtility.GetFileSize(buildAssetInfo.AssetInfo.AssetPath);
|
||||
redundancyInfo.Number = buildAssetInfo.GetReferenceBundleCount();
|
||||
context.RedundancyInfos.Add(redundancyInfo);
|
||||
}
|
||||
|
@ -128,7 +124,7 @@ namespace YooAsset.Editor
|
|||
}
|
||||
foreach (var removeValue in removeBuildList)
|
||||
{
|
||||
allBuildAssetInfos.Remove(removeValue.AssetPath);
|
||||
allBuildAssetInfos.Remove(removeValue.AssetInfo.AssetPath);
|
||||
}
|
||||
|
||||
// 10. 构建资源列表
|
||||
|
@ -145,35 +141,35 @@ namespace YooAsset.Editor
|
|||
|
||||
return context;
|
||||
}
|
||||
private void RemoveZeroReferenceAssets(List<CollectAssetInfo> allCollectAssetInfos)
|
||||
private void RemoveZeroReferenceAssets(BuildMapContext context, List<CollectAssetInfo> allCollectAssets)
|
||||
{
|
||||
// 1. 检测是否任何存在依赖资源
|
||||
if (allCollectAssetInfos.Exists(x => x.CollectorType == ECollectorType.DependAssetCollector) == false)
|
||||
// 1. 检测依赖资源收集器是否存在
|
||||
if (allCollectAssets.Exists(x => x.CollectorType == ECollectorType.DependAssetCollector) == false)
|
||||
return;
|
||||
|
||||
// 2. 获取所有主资源的依赖资源集合
|
||||
HashSet<string> allDependAsset = new HashSet<string>();
|
||||
foreach (var collectAssetInfo in allCollectAssetInfos)
|
||||
foreach (var collectAsset in allCollectAssets)
|
||||
{
|
||||
var collectorType = collectAssetInfo.CollectorType;
|
||||
var collectorType = collectAsset.CollectorType;
|
||||
if (collectorType == ECollectorType.MainAssetCollector || collectorType == ECollectorType.StaticAssetCollector)
|
||||
{
|
||||
foreach (var dependAsset in collectAssetInfo.DependAssets)
|
||||
foreach (var dependAsset in collectAsset.DependAssets)
|
||||
{
|
||||
if (allDependAsset.Contains(dependAsset) == false)
|
||||
allDependAsset.Add(dependAsset);
|
||||
if (allDependAsset.Contains(dependAsset.AssetPath) == false)
|
||||
allDependAsset.Add(dependAsset.AssetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 找出所有零引用的依赖资源集合
|
||||
List<CollectAssetInfo> removeList = new List<CollectAssetInfo>();
|
||||
foreach (var collectAssetInfo in allCollectAssetInfos)
|
||||
foreach (var collectAssetInfo in allCollectAssets)
|
||||
{
|
||||
var collectorType = collectAssetInfo.CollectorType;
|
||||
if (collectorType == ECollectorType.DependAssetCollector)
|
||||
{
|
||||
if (allDependAsset.Contains(collectAssetInfo.AssetPath) == false)
|
||||
if (allDependAsset.Contains(collectAssetInfo.AssetInfo.AssetPath) == false)
|
||||
removeList.Add(collectAssetInfo);
|
||||
}
|
||||
}
|
||||
|
@ -181,9 +177,10 @@ namespace YooAsset.Editor
|
|||
// 4. 移除所有零引用的依赖资源
|
||||
foreach (var removeValue in removeList)
|
||||
{
|
||||
string warning = BuildLogger.GetErrorMessage(ErrorCode.FoundUndependedAsset, $"Found undepended asset and remove it : {removeValue.AssetPath}");
|
||||
string warning = BuildLogger.GetErrorMessage(ErrorCode.FoundUndependedAsset, $"Found undepended asset and remove it : {removeValue.AssetInfo.AssetPath}");
|
||||
BuildLogger.Warning(warning);
|
||||
allCollectAssetInfos.Remove(removeValue);
|
||||
context.UndependAssets.Add(removeValue.AssetInfo);
|
||||
allCollectAssets.Remove(removeValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,9 +29,9 @@ namespace YooAsset.Editor
|
|||
foreach (var bundleInfo in buildMapContext.Collection)
|
||||
{
|
||||
string dest = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||
foreach (var assetInfo in bundleInfo.MainAssets)
|
||||
foreach (var buildAsset in bundleInfo.MainAssets)
|
||||
{
|
||||
EditorTools.CopyFile(assetInfo.AssetPath, dest, true);
|
||||
EditorTools.CopyFile(buildAsset.AssetInfo.AssetPath, dest, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,38 +148,35 @@ namespace YooAsset.Editor
|
|||
|
||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000);
|
||||
|
||||
// 收集打包资源
|
||||
// 收集打包资源路径
|
||||
List<string> findAssets =new List<string>();
|
||||
if (AssetDatabase.IsValidFolder(CollectPath))
|
||||
{
|
||||
string collectDirectory = CollectPath;
|
||||
string[] findAssets = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory);
|
||||
foreach (string assetPath in findAssets)
|
||||
{
|
||||
if (IsValidateAsset(command, assetPath) && IsCollectAsset(group, assetPath))
|
||||
{
|
||||
if (result.ContainsKey(assetPath) == false)
|
||||
{
|
||||
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath);
|
||||
result.Add(assetPath, collectAssetInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"The collecting asset file is existed : {assetPath} in collector : {CollectPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
string[] findResult = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory);
|
||||
findAssets.AddRange(findResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
string assetPath = CollectPath;
|
||||
if (IsValidateAsset(command, assetPath) && IsCollectAsset(group, assetPath))
|
||||
findAssets.Add(assetPath);
|
||||
}
|
||||
|
||||
// 收集打包资源信息
|
||||
foreach (string assetPath in findAssets)
|
||||
{
|
||||
var assetInfo = new AssetInfo(assetPath);
|
||||
if (IsValidateAsset(command, assetInfo) && IsCollectAsset(group, assetInfo))
|
||||
{
|
||||
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath);
|
||||
result.Add(assetPath, collectAssetInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"The collecting single asset file is invalid : {assetPath} in collector : {CollectPath}");
|
||||
if (result.ContainsKey(assetPath) == false)
|
||||
{
|
||||
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetInfo);
|
||||
result.Add(assetPath, collectAssetInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"The collecting asset file is existed : {assetPath} in collector : {CollectPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,7 +189,7 @@ namespace YooAsset.Editor
|
|||
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
string assetPath = collectInfoPair.Value.AssetPath;
|
||||
string assetPath = collectInfoPair.Value.AssetInfo.AssetPath;
|
||||
if (string.IsNullOrEmpty(address))
|
||||
continue;
|
||||
|
||||
|
@ -211,61 +208,64 @@ namespace YooAsset.Editor
|
|||
return result.Values.ToList();
|
||||
}
|
||||
|
||||
private CollectAssetInfo CreateCollectAssetInfo(CollectCommand command, AssetBundleCollectorGroup group, string assetPath)
|
||||
|
||||
/// <summary>
|
||||
/// 创建资源收集类
|
||||
/// </summary>
|
||||
private CollectAssetInfo CreateCollectAssetInfo(CollectCommand command, AssetBundleCollectorGroup group, AssetInfo assetInfo)
|
||||
{
|
||||
string address = GetAddress(command, group, assetPath);
|
||||
string bundleName = GetBundleName(command, group, assetPath);
|
||||
string address = GetAddress(command, group, assetInfo);
|
||||
string bundleName = GetBundleName(command, group, assetInfo);
|
||||
List<string> assetTags = GetAssetTags(group);
|
||||
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, assetTags);
|
||||
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetInfo, assetTags);
|
||||
|
||||
// 注意:模拟构建模式下不需要收集依赖资源
|
||||
if (command.BuildMode == EBuildMode.SimulateBuild)
|
||||
collectAssetInfo.DependAssets = new List<string>();
|
||||
collectAssetInfo.DependAssets = new List<AssetInfo>();
|
||||
else
|
||||
collectAssetInfo.DependAssets = GetAllDependencies(command, assetPath);
|
||||
collectAssetInfo.DependAssets = GetAllDependencies(command, assetInfo.AssetPath);
|
||||
|
||||
return collectAssetInfo;
|
||||
}
|
||||
private bool IsValidateAsset(CollectCommand command, string assetPath)
|
||||
|
||||
private bool IsValidateAsset(CollectCommand command, AssetInfo assetInfo)
|
||||
{
|
||||
if (assetPath.StartsWith("Assets/") == false && assetPath.StartsWith("Packages/") == false)
|
||||
if (assetInfo.AssetPath.StartsWith("Assets/") == false && assetInfo.AssetPath.StartsWith("Packages/") == false)
|
||||
{
|
||||
UnityEngine.Debug.LogError($"Invalid asset path : {assetPath}");
|
||||
UnityEngine.Debug.LogError($"Invalid asset path : {assetInfo.AssetPath}");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 忽略文件夹
|
||||
if (AssetDatabase.IsValidFolder(assetPath))
|
||||
if (AssetDatabase.IsValidFolder(assetInfo.AssetPath))
|
||||
return false;
|
||||
|
||||
// 忽略编辑器下的类型资源
|
||||
Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(LightingDataAsset))
|
||||
if (assetInfo.AssetType == typeof(LightingDataAsset))
|
||||
return false;
|
||||
|
||||
// 忽略Unity引擎无法识别的文件
|
||||
if (command.IgnoreDefaultType)
|
||||
{
|
||||
if (assetType == typeof(UnityEditor.DefaultAsset))
|
||||
if (assetInfo.AssetType == typeof(UnityEditor.DefaultAsset))
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetPath}");
|
||||
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetInfo.AssetPath}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
string fileExtension = System.IO.Path.GetExtension(assetPath);
|
||||
if (DefaultFilterRule.IsIgnoreFile(fileExtension))
|
||||
if (DefaultFilterRule.IsIgnoreFile(assetInfo.FileExtension))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
private bool IsCollectAsset(AssetBundleCollectorGroup group, string assetPath)
|
||||
private bool IsCollectAsset(AssetBundleCollectorGroup group, AssetInfo assetInfo)
|
||||
{
|
||||
// 根据规则设置过滤资源文件
|
||||
IFilterRule filterRuleInstance = AssetBundleCollectorSettingData.GetFilterRuleInstance(FilterRuleName);
|
||||
return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetPath, CollectPath, group.GroupName, UserData));
|
||||
return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetInfo.AssetPath, CollectPath, group.GroupName, UserData));
|
||||
}
|
||||
private string GetAddress(CollectCommand command, AssetBundleCollectorGroup group, string assetPath)
|
||||
private string GetAddress(CollectCommand command, AssetBundleCollectorGroup group, AssetInfo assetInfo)
|
||||
{
|
||||
if (command.EnableAddressable == false)
|
||||
return string.Empty;
|
||||
|
@ -274,15 +274,14 @@ namespace YooAsset.Editor
|
|||
return string.Empty;
|
||||
|
||||
IAddressRule addressRuleInstance = AssetBundleCollectorSettingData.GetAddressRuleInstance(AddressRuleName);
|
||||
string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetPath, CollectPath, group.GroupName, UserData));
|
||||
string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetInfo.AssetPath, CollectPath, group.GroupName, UserData));
|
||||
return adressValue;
|
||||
}
|
||||
private string GetBundleName(CollectCommand command, AssetBundleCollectorGroup group, string assetPath)
|
||||
private string GetBundleName(CollectCommand command, AssetBundleCollectorGroup group, AssetInfo assetInfo)
|
||||
{
|
||||
if (command.AutoCollectShaders)
|
||||
{
|
||||
System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(UnityEngine.Shader) || assetType == typeof(UnityEngine.ShaderVariantCollection))
|
||||
if (assetInfo.IsShaderAsset())
|
||||
{
|
||||
// 获取着色器打包规则结果
|
||||
PackRuleResult shaderPackRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
|
||||
|
@ -292,7 +291,7 @@ namespace YooAsset.Editor
|
|||
|
||||
// 获取其它资源打包规则结果
|
||||
IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
|
||||
PackRuleResult defaultPackRuleResult = packRuleInstance.GetPackRuleResult(new PackRuleData(assetPath, CollectPath, group.GroupName, UserData));
|
||||
PackRuleResult defaultPackRuleResult = packRuleInstance.GetPackRuleResult(new PackRuleData(assetInfo.AssetPath, CollectPath, group.GroupName, UserData));
|
||||
return defaultPackRuleResult.GetBundleName(command.PackageName, command.UniqueBundleName);
|
||||
}
|
||||
private List<string> GetAssetTags(AssetBundleCollectorGroup group)
|
||||
|
@ -302,18 +301,19 @@ namespace YooAsset.Editor
|
|||
tags.AddRange(temper);
|
||||
return tags;
|
||||
}
|
||||
private List<string> GetAllDependencies(CollectCommand command, string mainAssetPath)
|
||||
private List<AssetInfo> GetAllDependencies(CollectCommand command, string mainAssetPath)
|
||||
{
|
||||
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true);
|
||||
List<string> result = new List<string>(depends.Length);
|
||||
List<AssetInfo> result = new List<AssetInfo>(depends.Length);
|
||||
foreach (string assetPath in depends)
|
||||
{
|
||||
// 注意:排除主资源对象
|
||||
if (assetPath == mainAssetPath)
|
||||
continue;
|
||||
|
||||
if (IsValidateAsset(command, assetPath))
|
||||
result.Add(assetPath);
|
||||
AssetInfo assetInfo = new AssetInfo(assetPath);
|
||||
if (IsValidateAsset(command, assetInfo))
|
||||
result.Add(assetInfo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -89,12 +89,12 @@ namespace YooAsset.Editor
|
|||
foreach (var collector in Collectors)
|
||||
{
|
||||
var temper = collector.GetAllCollectAssets(command, this);
|
||||
foreach (var assetInfo in temper)
|
||||
foreach (var collectAsset in temper)
|
||||
{
|
||||
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
||||
result.Add(assetInfo.AssetPath, assetInfo);
|
||||
if (result.ContainsKey(collectAsset.AssetInfo.AssetPath) == false)
|
||||
result.Add(collectAsset.AssetInfo.AssetPath, collectAsset);
|
||||
else
|
||||
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath} in group : {GroupName}");
|
||||
throw new Exception($"The collecting asset file is existed : {collectAsset.AssetInfo.AssetPath} in group : {GroupName}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,12 +102,12 @@ namespace YooAsset.Editor
|
|||
if (command.EnableAddressable)
|
||||
{
|
||||
var addressTemper = new Dictionary<string, string>();
|
||||
foreach (var collectInfoPair in result)
|
||||
foreach (var collectAssetPair in result)
|
||||
{
|
||||
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
if (collectAssetPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
string assetPath = collectInfoPair.Value.AssetPath;
|
||||
string address = collectAssetPair.Value.Address;
|
||||
string assetPath = collectAssetPair.Value.AssetInfo.AssetPath;
|
||||
if (string.IsNullOrEmpty(address))
|
||||
continue;
|
||||
|
||||
|
|
|
@ -89,12 +89,12 @@ namespace YooAsset.Editor
|
|||
foreach (var group in Groups)
|
||||
{
|
||||
var temper = group.GetAllCollectAssets(command);
|
||||
foreach (var assetInfo in temper)
|
||||
foreach (var collectAsset in temper)
|
||||
{
|
||||
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
||||
result.Add(assetInfo.AssetPath, assetInfo);
|
||||
if (result.ContainsKey(collectAsset.AssetInfo.AssetPath) == false)
|
||||
result.Add(collectAsset.AssetInfo.AssetPath, collectAsset);
|
||||
else
|
||||
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath}");
|
||||
throw new Exception($"The collecting asset file is existed : {collectAsset.AssetInfo.AssetPath}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ namespace YooAsset.Editor
|
|||
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||
{
|
||||
string address = collectInfoPair.Value.Address;
|
||||
string assetPath = collectInfoPair.Value.AssetPath;
|
||||
string assetPath = collectInfoPair.Value.AssetInfo.AssetPath;
|
||||
if (string.IsNullOrEmpty(address))
|
||||
continue;
|
||||
|
||||
|
|
|
@ -991,15 +991,15 @@ namespace YooAsset.Editor
|
|||
|
||||
if (collectAssetInfos != null)
|
||||
{
|
||||
foreach (var collectAssetInfo in collectAssetInfos)
|
||||
foreach (var collectAsset in collectAssetInfos)
|
||||
{
|
||||
VisualElement elementRow = new VisualElement();
|
||||
elementRow.style.flexDirection = FlexDirection.Row;
|
||||
foldout.Add(elementRow);
|
||||
|
||||
string showInfo = collectAssetInfo.AssetPath;
|
||||
string showInfo = collectAsset.AssetInfo.AssetPath;
|
||||
if (_enableAddressableToogle.value)
|
||||
showInfo = $"[{collectAssetInfo.Address}] {collectAssetInfo.AssetPath}";
|
||||
showInfo = $"[{collectAsset.Address}] {collectAsset.AssetInfo.AssetPath}";
|
||||
|
||||
var label = new Label();
|
||||
label.text = showInfo;
|
||||
|
|
|
@ -21,9 +21,9 @@ namespace YooAsset.Editor
|
|||
public string Address { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// 资源信息
|
||||
/// </summary>
|
||||
public string AssetPath { private set; get; }
|
||||
public AssetInfo AssetInfo { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源分类标签
|
||||
|
@ -33,15 +33,15 @@ namespace YooAsset.Editor
|
|||
/// <summary>
|
||||
/// 依赖的资源列表
|
||||
/// </summary>
|
||||
public List<string> DependAssets = new List<string>();
|
||||
public List<AssetInfo> DependAssets = new List<AssetInfo>();
|
||||
|
||||
|
||||
public CollectAssetInfo(ECollectorType collectorType, string bundleName, string address, string assetPath, List<string> assetTags)
|
||||
public CollectAssetInfo(ECollectorType collectorType, string bundleName, string address, AssetInfo assetInfo, List<string> assetTags)
|
||||
{
|
||||
CollectorType = collectorType;
|
||||
BundleName = bundleName;
|
||||
Address = address;
|
||||
AssetPath = assetPath;
|
||||
AssetInfo = assetInfo;
|
||||
AssetTags = assetTags;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,12 @@ namespace YooAsset.Editor
|
|||
/// <summary>
|
||||
/// 冗余的资源列表
|
||||
/// </summary>
|
||||
public List<ReportRedundancyInfo> RedundancyInfos = new List<ReportRedundancyInfo>();
|
||||
public List<ReportRedundancyAsset> RedundancyAssets = new List<ReportRedundancyAsset>();
|
||||
|
||||
/// <summary>
|
||||
/// 未被依赖的资源列表
|
||||
/// </summary>
|
||||
public List<AssetInfo> UndependAssets = new List<AssetInfo>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源包信息类
|
||||
|
|
|
@ -5,23 +5,12 @@ using System.Collections.Generic;
|
|||
namespace YooAsset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class ReportRedundancyInfo
|
||||
public class ReportRedundancyAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// 资源信息
|
||||
/// </summary>
|
||||
public string AssetPath;
|
||||
|
||||
/// <summary>
|
||||
/// 资源类型
|
||||
/// </summary>
|
||||
public string AssetType;
|
||||
|
||||
/// <summary>
|
||||
/// 资源GUID
|
||||
/// 说明:Meta文件记录的GUID
|
||||
/// </summary>
|
||||
public string AssetGUID;
|
||||
public AssetInfo AssetInfo;
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件大小
|
|
@ -80,16 +80,16 @@ namespace YooAsset.Editor
|
|||
_assetListView.Rebuild();
|
||||
RefreshSortingSymbol();
|
||||
}
|
||||
private List<ReportRedundancyInfo> FilterAndSortViewItems()
|
||||
private List<ReportRedundancyAsset> FilterAndSortViewItems()
|
||||
{
|
||||
List<ReportRedundancyInfo> result = new List<ReportRedundancyInfo>(_buildReport.RedundancyInfos.Count);
|
||||
List<ReportRedundancyAsset> result = new List<ReportRedundancyAsset>(_buildReport.RedundancyAssets.Count);
|
||||
|
||||
// 过滤列表
|
||||
foreach (var redundancyInfo in _buildReport.RedundancyInfos)
|
||||
foreach (var redundancyInfo in _buildReport.RedundancyAssets)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_searchKeyWord) == false)
|
||||
{
|
||||
if (redundancyInfo.AssetPath.Contains(_searchKeyWord) == false)
|
||||
if (redundancyInfo.AssetInfo.AssetPath.Contains(_searchKeyWord) == false)
|
||||
continue;
|
||||
}
|
||||
result.Add(redundancyInfo);
|
||||
|
@ -99,16 +99,16 @@ namespace YooAsset.Editor
|
|||
if (_sortMode == ESortMode.AssetPath)
|
||||
{
|
||||
if (_descendingSort)
|
||||
return result.OrderByDescending(a => a.AssetPath).ToList();
|
||||
return result.OrderByDescending(a => a.AssetInfo.AssetPath).ToList();
|
||||
else
|
||||
return result.OrderBy(a => a.AssetPath).ToList();
|
||||
return result.OrderBy(a => a.AssetInfo.AssetPath).ToList();
|
||||
}
|
||||
else if (_sortMode == ESortMode.AssetType)
|
||||
{
|
||||
if (_descendingSort)
|
||||
return result.OrderByDescending(a => a.AssetType).ToList();
|
||||
return result.OrderByDescending(a => a.AssetInfo.AssetType).ToList();
|
||||
else
|
||||
return result.OrderBy(a => a.AssetType).ToList();
|
||||
return result.OrderBy(a => a.AssetInfo.AssetType).ToList();
|
||||
}
|
||||
else if (_sortMode == ESortMode.FileSize)
|
||||
{
|
||||
|
@ -237,16 +237,16 @@ namespace YooAsset.Editor
|
|||
}
|
||||
private void BindAssetListViewItem(VisualElement element, int index)
|
||||
{
|
||||
var sourceData = _assetListView.itemsSource as List<ReportRedundancyInfo>;
|
||||
var sourceData = _assetListView.itemsSource as List<ReportRedundancyAsset>;
|
||||
var redundancyInfo = sourceData[index];
|
||||
|
||||
// Asset Path
|
||||
var label1 = element.Q<Label>("Label1");
|
||||
label1.text = redundancyInfo.AssetPath;
|
||||
label1.text = redundancyInfo.AssetInfo.AssetPath;
|
||||
|
||||
// Asset Type
|
||||
var label2 = element.Q<Label>("Label2");
|
||||
label2.text = redundancyInfo.AssetType;
|
||||
label2.text = redundancyInfo.AssetInfo.AssetType.ToString();
|
||||
|
||||
// File Size
|
||||
var label3 = element.Q<Label>("Label3");
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4cb0b75b2f649c64bb1d8203f2fbfeea
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,58 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class AssetInfo
|
||||
{
|
||||
private string _fileExtension = null;
|
||||
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// </summary>
|
||||
public string AssetPath;
|
||||
|
||||
/// <summary>
|
||||
/// 资源GUID
|
||||
/// </summary>
|
||||
public string AssetGUID;
|
||||
|
||||
/// <summary>
|
||||
/// 资源类型
|
||||
/// </summary>
|
||||
public System.Type AssetType;
|
||||
|
||||
/// <summary>
|
||||
/// 文件格式
|
||||
/// </summary>
|
||||
public string FileExtension
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_fileExtension))
|
||||
_fileExtension = System.IO.Path.GetExtension(AssetPath);
|
||||
return _fileExtension;
|
||||
}
|
||||
}
|
||||
|
||||
public AssetInfo(string assetPath)
|
||||
{
|
||||
AssetPath = assetPath;
|
||||
AssetGUID = UnityEditor.AssetDatabase.AssetPathToGUID(AssetPath);
|
||||
AssetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(AssetPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为着色器资源
|
||||
/// </summary>
|
||||
public bool IsShaderAsset()
|
||||
{
|
||||
if (AssetType == typeof(UnityEngine.Shader) || AssetType == typeof(UnityEngine.ShaderVariantCollection))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4a2e0565919d49348b8deeb14258a985
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue