Update patch manifest

更新资源清单:资源对象增加分类标签。
pull/11/head
hevinci 2022-05-11 16:23:31 +08:00
parent ae465a47a9
commit 67eeae31c7
9 changed files with 77 additions and 17 deletions

View File

@ -10,6 +10,7 @@ namespace YooAsset.Editor
private string _mainBundleName; private string _mainBundleName;
private string _shareBundleName; private string _shareBundleName;
private readonly HashSet<string> _referenceBundleNames = new HashSet<string>(); private readonly HashSet<string> _referenceBundleNames = new HashSet<string>();
private bool _isAddAssetTags = false;
/// <summary> /// <summary>
/// 收集器类型 /// 收集器类型
@ -37,10 +38,15 @@ namespace YooAsset.Editor
public bool IsShaderAsset { private set; get; } public bool IsShaderAsset { private set; get; }
/// <summary> /// <summary>
/// 资源分类标签列表 /// 资源分类标签
/// </summary> /// </summary>
public readonly List<string> AssetTags = new List<string>(); public readonly List<string> AssetTags = new List<string>();
/// <summary>
/// 资源包的分类标签
/// </summary>
public readonly List<string> BundleTags = new List<string>();
/// <summary> /// <summary>
/// 依赖的所有资源 /// 依赖的所有资源
/// 注意:包括零依赖资源和冗余资源(资源包名无效) /// 注意:包括零依赖资源和冗余资源(资源包名无效)
@ -89,10 +95,15 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 添加资源分类标签 /// 添加资源的分类标签
/// 说明:原始定义的资源分类标签
/// </summary> /// </summary>
public void AddAssetTags(List<string> tags) public void AddAssetTags(List<string> tags)
{ {
if (_isAddAssetTags)
throw new Exception("Should never get here !");
_isAddAssetTags = true;
foreach (var tag in tags) foreach (var tag in tags)
{ {
if (AssetTags.Contains(tag) == false) if (AssetTags.Contains(tag) == false)
@ -102,6 +113,21 @@ namespace YooAsset.Editor
} }
} }
/// <summary>
/// 添加资源包的分类标签
/// 说明:传染算法统计到的分类标签
/// </summary>
public void AddBundleTags(List<string> tags)
{
foreach (var tag in tags)
{
if (BundleTags.Contains(tag) == false)
{
BundleTags.Add(tag);
}
}
}
/// <summary> /// <summary>
/// 资源包名是否存在 /// 资源包名是否存在
/// </summary> /// </summary>

View File

@ -68,14 +68,14 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 获取资源标签列表 /// 获取资源包的分类标签列表
/// </summary> /// </summary>
public string[] GetAssetTags() public string[] GetBundleTags()
{ {
List<string> result = new List<string>(BuildinAssets.Count); List<string> result = new List<string>(BuildinAssets.Count);
foreach (var assetInfo in BuildinAssets) foreach (var assetInfo in BuildinAssets)
{ {
foreach (var assetTag in assetInfo.AssetTags) foreach (var assetTag in assetInfo.BundleTags)
{ {
if (result.Contains(assetTag) == false) if (result.Contains(assetTag) == false)
result.Add(assetTag); result.Add(assetTag);

View File

@ -55,13 +55,13 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 获取AssetBundle内包含的标记列表 /// 获取资源包的分类标签列表
/// </summary> /// </summary>
public string[] GetAssetTags(string bundleName) public string[] GetBundleTags(string bundleName)
{ {
if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo)) if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
{ {
return bundleInfo.GetAssetTags(); return bundleInfo.GetBundleTags();
} }
throw new Exception($"Not found {nameof(BuildBundleInfo)} : {bundleName}"); throw new Exception($"Not found {nameof(BuildBundleInfo)} : {bundleName}");
} }

View File

@ -18,7 +18,7 @@ namespace YooAsset.Editor
// 1. 检测配置合法性 // 1. 检测配置合法性
AssetBundleCollectorSettingData.Setting.CheckConfigError(); AssetBundleCollectorSettingData.Setting.CheckConfigError();
// 2. 获取所有主动收集的资源 // 2. 获取所有收集器收集的资源
List<CollectAssetInfo> allCollectAssets = AssetBundleCollectorSettingData.Setting.GetAllCollectAssets(buildMode); List<CollectAssetInfo> allCollectAssets = AssetBundleCollectorSettingData.Setting.GetAllCollectAssets(buildMode);
// 3. 剔除未被引用的依赖资源 // 3. 剔除未被引用的依赖资源
@ -36,13 +36,15 @@ namespace YooAsset.Editor
allCollectAssets.Remove(removeValue); allCollectAssets.Remove(removeValue);
} }
// 4. 录入主动收集的资源 // 4. 录入所有收集器收集的资源
foreach (var collectAssetInfo in allCollectAssets) foreach (var collectAssetInfo in allCollectAssets)
{ {
if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false) if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false)
{ {
var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName, collectAssetInfo.Address, collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset); var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName,
collectAssetInfo.Address, collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset);
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags); buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
buildAssetDic.Add(collectAssetInfo.AssetPath, buildAssetInfo); buildAssetDic.Add(collectAssetInfo.AssetPath, buildAssetInfo);
} }
else else
@ -58,13 +60,13 @@ namespace YooAsset.Editor
{ {
if (buildAssetDic.ContainsKey(dependAssetPath)) if (buildAssetDic.ContainsKey(dependAssetPath))
{ {
buildAssetDic[dependAssetPath].AddAssetTags(collectAssetInfo.AssetTags); buildAssetDic[dependAssetPath].AddBundleTags(collectAssetInfo.AssetTags);
buildAssetDic[dependAssetPath].AddReferenceBundleName(collectAssetInfo.BundleName); buildAssetDic[dependAssetPath].AddReferenceBundleName(collectAssetInfo.BundleName);
} }
else else
{ {
var buildAssetInfo = new BuildAssetInfo(ECollectorType.None, dependAssetPath); var buildAssetInfo = new BuildAssetInfo(ECollectorType.None, dependAssetPath);
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags); buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
buildAssetInfo.AddReferenceBundleName(collectAssetInfo.BundleName); buildAssetInfo.AddReferenceBundleName(collectAssetInfo.BundleName);
buildAssetDic.Add(dependAssetPath, buildAssetInfo); buildAssetDic.Add(dependAssetPath, buildAssetInfo);
} }
@ -92,7 +94,7 @@ namespace YooAsset.Editor
pair.Value.CalculateFullBundleName(); pair.Value.CalculateFullBundleName();
} }
// 8. 移除参与构建的资源 // 8. 移除参与构建的资源
List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>(); List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>();
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic) foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
{ {

View File

@ -23,6 +23,11 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public string AssetGUID; public string AssetGUID;
/// <summary>
/// 资源的分类标签
/// </summary>
public string[] AssetTags;
/// <summary> /// <summary>
/// 所属资源包名称 /// 所属资源包名称
/// </summary> /// </summary>

View File

@ -70,7 +70,7 @@ namespace YooAsset.Editor
string hash = GetFileHash(filePath, standardBuild); string hash = GetFileHash(filePath, standardBuild);
string crc32 = GetFileCRC(filePath, standardBuild); string crc32 = GetFileCRC(filePath, standardBuild);
long size = GetFileSize(filePath, standardBuild); long size = GetFileSize(filePath, standardBuild);
string[] tags = buildMapContext.GetAssetTags(bundleName); string[] tags = buildMapContext.GetBundleTags(bundleName);
bool isEncrypted = encryptionContext.IsEncryptFile(bundleName); bool isEncrypted = encryptionContext.IsEncryptFile(bundleName);
bool isBuildin = IsBuildinBundle(tags, buildinTags); bool isBuildin = IsBuildinBundle(tags, buildinTags);
bool isRawFile = bundleInfo.IsRawFile; bool isRawFile = bundleInfo.IsRawFile;
@ -141,6 +141,7 @@ namespace YooAsset.Editor
else else
patchAsset.Address = string.Empty; patchAsset.Address = string.Empty;
patchAsset.AssetPath = assetInfo.AssetPath; patchAsset.AssetPath = assetInfo.AssetPath;
patchAsset.AssetTags = assetInfo.AssetTags.ToArray();
patchAsset.BundleID = GetAssetBundleID(assetInfo.GetBundleName(), patchManifest); patchAsset.BundleID = GetAssetBundleID(assetInfo.GetBundleName(), patchManifest);
patchAsset.DependIDs = GetAssetBundleDependIDs(patchAsset.BundleID, assetInfo, patchManifest); patchAsset.DependIDs = GetAssetBundleDependIDs(patchAsset.BundleID, assetInfo, patchManifest);
result.Add(patchAsset); result.Add(patchAsset);

View File

@ -75,6 +75,7 @@ namespace YooAsset.Editor
ReportAssetInfo reportAssetInfo = new ReportAssetInfo(); ReportAssetInfo reportAssetInfo = new ReportAssetInfo();
reportAssetInfo.Address = patchAsset.Address; reportAssetInfo.Address = patchAsset.Address;
reportAssetInfo.AssetPath = patchAsset.AssetPath; reportAssetInfo.AssetPath = patchAsset.AssetPath;
reportAssetInfo.AssetTags = patchAsset.AssetTags;
reportAssetInfo.AssetGUID = AssetDatabase.AssetPathToGUID(patchAsset.AssetPath); reportAssetInfo.AssetGUID = AssetDatabase.AssetPathToGUID(patchAsset.AssetPath);
reportAssetInfo.MainBundleName = mainBundle.BundleName; reportAssetInfo.MainBundleName = mainBundle.BundleName;
reportAssetInfo.MainBundleSize = mainBundle.SizeBytes; reportAssetInfo.MainBundleSize = mainBundle.SizeBytes;

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
namespace YooAsset namespace YooAsset
{ {
@ -15,6 +16,11 @@ namespace YooAsset
/// </summary> /// </summary>
public string AssetPath; public string AssetPath;
/// <summary>
/// 资源的分类标签
/// </summary>
public string[] AssetTags;
/// <summary> /// <summary>
/// 所属资源包ID /// 所属资源包ID
/// </summary> /// </summary>
@ -24,5 +30,24 @@ namespace YooAsset
/// 依赖的资源包ID列表 /// 依赖的资源包ID列表
/// </summary> /// </summary>
public int[] DependIDs; public int[] DependIDs;
/// <summary>
/// 是否包含Tag
/// </summary>
public bool HasTag(string[] tags)
{
if (tags == null || tags.Length == 0)
return false;
if (AssetTags == null || AssetTags.Length == 0)
return false;
foreach (var tag in tags)
{
if (AssetTags.Contains(tag))
return true;
}
return false;
}
} }
} }

View File

@ -27,7 +27,7 @@ namespace YooAsset
public long SizeBytes; public long SizeBytes;
/// <summary> /// <summary>
/// Tags /// 资源包的分类标签
/// </summary> /// </summary>
public string[] Tags; public string[] Tags;