update resource package

This commit is contained in:
何冠峰
2025-02-21 15:29:42 +08:00
parent d9c911d89b
commit 7eacb46555
15 changed files with 98 additions and 188 deletions
@@ -35,7 +35,6 @@ namespace YooAsset
buffer.WriteUTF8(manifest.FileVersion);
// 写入文件头信息
buffer.WriteBool(manifest.LegacyDependency);
buffer.WriteBool(manifest.EnableAddressable);
buffer.WriteBool(manifest.LocationToLower);
buffer.WriteBool(manifest.IncludeAssetGUID);
@@ -71,8 +70,7 @@ namespace YooAsset
buffer.WriteInt64(packageBundle.FileSize);
buffer.WriteBool(packageBundle.Encrypted);
buffer.WriteUTF8Array(packageBundle.Tags);
buffer.WriteInt32Array(packageBundle.DependIDs);
buffer.WriteInt32Array(packageBundle.ReferenceBundleIDs);
buffer.WriteInt32Array(packageBundle.DependBundleIDs);
}
// 写入文件流
@@ -111,7 +109,6 @@ namespace YooAsset
{
// 读取文件头信息
manifest.FileVersion = fileVersion;
manifest.LegacyDependency = buffer.ReadBool();
manifest.EnableAddressable = buffer.ReadBool();
manifest.LocationToLower = buffer.ReadBool();
manifest.IncludeAssetGUID = buffer.ReadBool();
@@ -154,8 +151,7 @@ namespace YooAsset
packageBundle.FileSize = buffer.ReadInt64();
packageBundle.Encrypted = buffer.ReadBool();
packageBundle.Tags = buffer.ReadUTF8Array();
packageBundle.DependIDs = buffer.ReadInt32Array();
packageBundle.ReferenceBundleIDs = buffer.ReadInt32Array();
packageBundle.DependBundleIDs = buffer.ReadInt32Array();
FillBundleCollection(manifest, packageBundle);
}
}
@@ -183,6 +179,17 @@ namespace YooAsset
throw new Exception($"Invalid bundle id : {bundleID} Asset path : {packageAsset.AssetPath}");
}
}
// 填充资源包引用关系
for (int index = 0; index < manifest.BundleList.Count; index++)
{
var sourceBundle = manifest.BundleList[index];
foreach (int dependIndex in sourceBundle.DependBundleIDs)
{
var dependBundle = manifest.BundleList[dependIndex];
dependBundle.AddReferenceBundleID(index);
}
}
}
public static void CreateAssetCollection(PackageManifest manifest, int assetCount)
@@ -78,7 +78,6 @@ namespace YooAsset
// 读取文件头信息
Manifest = new PackageManifest();
Manifest.FileVersion = fileVersion;
Manifest.LegacyDependency = _buffer.ReadBool();
Manifest.EnableAddressable = _buffer.ReadBool();
Manifest.LocationToLower = _buffer.ReadBool();
Manifest.IncludeAssetGUID = _buffer.ReadBool();
@@ -147,8 +146,7 @@ namespace YooAsset
packageBundle.FileSize = _buffer.ReadInt64();
packageBundle.Encrypted = _buffer.ReadBool();
packageBundle.Tags = _buffer.ReadUTF8Array();
packageBundle.DependIDs = _buffer.ReadInt32Array();
packageBundle.ReferenceBundleIDs = _buffer.ReadInt32Array();
packageBundle.DependBundleIDs = _buffer.ReadInt32Array();
ManifestTools.FillBundleCollection(Manifest, packageBundle);
_packageBundleCount--;
@@ -31,12 +31,11 @@ namespace YooAsset
/// </summary>
public int BundleID;
#region YOOASSET_LEGACY_DEPENDENCY
/// <summary>
/// 依赖的资源包列表
/// 依赖的资源包ID集合
/// 说明:框架层收集查询结果
/// </summary>
public int[] DependBundleIDs;
#endregion
/// <summary>
/// 临时数据对象(仅编辑器有效)
@@ -44,16 +44,9 @@ namespace YooAsset
/// <summary>
/// 依赖的资源包ID集合
/// 注意:引擎层构建查询结果
/// </summary>
public int[] DependIDs;
#region YOOASSET_LEGACY_DEPENDENCY
/// <summary>
/// 引用该资源包的资源包列表
/// 说明:谁引用了该资源包
/// </summary>
public int[] ReferenceBundleIDs;
#endregion
public int[] DependBundleIDs;
/// <summary>
/// 资源包GUID
@@ -66,7 +59,6 @@ namespace YooAsset
/// <summary>
/// 资源包类型
/// </summary>
private int _bundleType;
public int BundleType
{
get
@@ -74,11 +66,11 @@ namespace YooAsset
return _bundleType;
}
}
private int _bundleType;
/// <summary>
/// 文件名称
/// </summary>
private string _fileName;
/// </summary>
public string FileName
{
get
@@ -88,11 +80,11 @@ namespace YooAsset
return _fileName;
}
}
private string _fileName;
/// <summary>
/// 文件后缀名
/// </summary>
private string _fileExtension;
public string FileExtension
{
get
@@ -102,6 +94,7 @@ namespace YooAsset
return _fileExtension;
}
}
private string _fileExtension;
/// <summary>
/// 包含的主资源集合
@@ -110,10 +103,12 @@ namespace YooAsset
public readonly List<PackageAsset> IncludeMainAssets = new List<PackageAsset>(10);
/// <summary>
/// 临时数据对象(仅编辑器有效)
/// 引用该资源包的资源包列表
/// 说明:谁引用了该资源包
/// </summary>
[NonSerialized]
public object TempDataInEditor;
public readonly List<int> ReferenceBundleIDs = new List<int>(10);
private readonly HashSet<int> _referenceBundleIDs = new HashSet<int>();
public PackageBundle()
@@ -130,6 +125,19 @@ namespace YooAsset
_fileName = ManifestTools.GetRemoteBundleFileName(manifest.OutputNameStyle, BundleName, _fileExtension, FileHash);
}
/// <summary>
/// 添加引用该资源包的资源包ID
/// 说明:谁引用了该资源包
/// </summary>
public void AddReferenceBundleID(int bundleID)
{
if (_referenceBundleIDs.Contains(bundleID) == false)
{
_referenceBundleIDs.Add(bundleID);
ReferenceBundleIDs.Add(bundleID);
}
}
/// <summary>
/// 是否包含Tag
/// </summary>
@@ -17,11 +17,6 @@ namespace YooAsset
/// </summary>
public string FileVersion;
/// <summary>
/// 怀旧版依赖模式
/// </summary>
public bool LegacyDependency;
/// <summary>
/// 启用可寻址资源定位
/// </summary>
@@ -191,35 +186,20 @@ namespace YooAsset
/// </summary>
public PackageBundle[] GetAllDependencies(string assetPath)
{
// YOOASSET_LEGACY_DEPENDENCY
if (LegacyDependency)
if (TryGetPackageAsset(assetPath, out PackageAsset packageAsset))
{
if (TryGetPackageAsset(assetPath, out PackageAsset packageAsset))
{
List<PackageBundle> result = new List<PackageBundle>(packageAsset.DependBundleIDs.Length);
foreach (var dependID in packageAsset.DependBundleIDs)
{
var dependBundle = GetMainPackageBundle(dependID);
result.Add(dependBundle);
}
return result.ToArray();
}
else
{
throw new Exception("Should never get here !");
}
}
else
{
var packageBundle = GetMainPackageBundle(assetPath);
List<PackageBundle> result = new List<PackageBundle>(packageBundle.DependIDs.Length);
foreach (var dependID in packageBundle.DependIDs)
List<PackageBundle> result = new List<PackageBundle>(packageAsset.DependBundleIDs.Length);
foreach (var dependID in packageAsset.DependBundleIDs)
{
var dependBundle = GetMainPackageBundle(dependID);
result.Add(dependBundle);
}
return result.ToArray();
}
else
{
throw new Exception("Should never get here !");
}
}
/// <summary>