refactor : 重构代码

This commit is contained in:
何冠峰
2026-01-17 18:44:48 +08:00
parent e10888de93
commit 0a1c81faf1
75 changed files with 219 additions and 197 deletions
@@ -114,7 +114,7 @@ namespace YooAsset
var fileSystem = GetBelongFileSystem(packageBundle);
if (fileSystem != null)
{
BundleInfo bundleInfo = new BundleInfo(fileSystem, packageBundle);
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
return bundleInfo;
}
@@ -209,9 +209,9 @@ namespace YooAsset
{
List<BundleInfo> downloadList;
if (options.Tags == null)
downloadList = GetBundleListByAll(manifest, NeedDownload);
downloadList = GetBundleInfoListByAll(manifest, NeedDownload);
else
downloadList = GetBundleListByTags(manifest, options.Tags, NeedDownload);
downloadList = GetBundleInfoListByTags(manifest, options.Tags, NeedDownload);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain);
return operation;
@@ -225,9 +225,9 @@ namespace YooAsset
{
List<BundleInfo> downloadList;
if (options.AssetInfos == null)
downloadList = GetBundleListByAll(manifest, NeedDownload);
downloadList = GetBundleInfoListByAll(manifest, NeedDownload);
else
downloadList = GetBundleListByAssetInfos(manifest, options.AssetInfos, options.DownloadBundleDependencies, NeedDownload);
downloadList = GetBundleInfoListByAssetInfos(manifest, options.AssetInfos, options.DownloadBundleDependencies, NeedDownload);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain);
return operation;
@@ -241,9 +241,9 @@ namespace YooAsset
{
List<BundleInfo> unpackList;
if (options.Tags == null)
unpackList = GetBundleListByAll(manifest, NeedUnpack);
unpackList = GetBundleInfoListByAll(manifest, NeedUnpack);
else
unpackList = GetBundleListByTags(manifest, options.Tags, NeedUnpack);
unpackList = GetBundleInfoListByTags(manifest, options.Tags, NeedUnpack);
var operation = new ResourceUnpackerOperation(PackageName, unpackList, options.MaximumConcurrency, options.FailedTryAgain);
return operation;
@@ -255,12 +255,12 @@ namespace YooAsset
}
public ResourceImporterOperation CreateResourceImporter(PackageManifest manifest, BundleImporterOptions options)
{
List<BundleInfo> importerList = GetBundleListByBundleInfos(manifest, options.BundleInfos, NeedImport);
List<BundleInfo> importerList = GetBundleInfoListByBundleInfos(manifest, options.BundleInfos, NeedImport);
var operation = new ResourceImporterOperation(PackageName, importerList, options.MaximumConcurrency, options.FailedTryAgain);
return operation;
}
private List<BundleInfo> GetBundleListByAll(PackageManifest manifest, Func<IFileSystem, PackageBundle, bool> predicate)
private List<BundleInfo> GetBundleInfoListByAll(PackageManifest manifest, Func<IFileSystem, PackageBundle, bool> predicate)
{
if (manifest == null)
return new List<BundleInfo>();
@@ -280,7 +280,7 @@ namespace YooAsset
}
return result;
}
private List<BundleInfo> GetBundleListByTags(PackageManifest manifest, string[] tags, Func<IFileSystem, PackageBundle, bool> predicate)
private List<BundleInfo> GetBundleInfoListByTags(PackageManifest manifest, string[] tags, Func<IFileSystem, PackageBundle, bool> predicate)
{
if (manifest == null)
return new List<BundleInfo>();
@@ -312,7 +312,7 @@ namespace YooAsset
}
return result;
}
private List<BundleInfo> GetBundleListByAssetInfos(PackageManifest manifest, AssetInfo[] assetInfos, bool recursiveDepend, Func<IFileSystem, PackageBundle, bool> predicate)
private List<BundleInfo> GetBundleInfoListByAssetInfos(PackageManifest manifest, AssetInfo[] assetInfos, bool recursiveDepend, Func<IFileSystem, PackageBundle, bool> predicate)
{
if (manifest == null)
return new List<BundleInfo>();
@@ -387,7 +387,7 @@ namespace YooAsset
}
return result;
}
private List<BundleInfo> GetBundleListByBundleInfos(PackageManifest manifest, ImportBundleInfo[] fileInfos, Func<IFileSystem, PackageBundle, bool> predicate)
private List<BundleInfo> GetBundleInfoListByBundleInfos(PackageManifest manifest, ImportBundleInfo[] fileInfos, Func<IFileSystem, PackageBundle, bool> predicate)
{
if (manifest == null)
return new List<BundleInfo>();
@@ -36,27 +36,27 @@ namespace YooAsset
if (_steps == ESteps.Prepare)
{
var fileSytems = _host.FileSystems;
if (fileSytems == null || fileSytems.Count == 0)
var fileSystems = _host.FileSystems;
if (fileSystems == null || fileSystems.Count == 0)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "The file system is empty !";
Error = "The file system is empty.";
return;
}
foreach (var fileSystem in fileSytems)
foreach (var fileSystem in fileSystems)
{
if (fileSystem == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "An empty object exists in the list!";
Error = "An empty object exists in the list.";
return;
}
}
_cloneList = fileSytems.ToList();
_cloneList = fileSystems.ToList();
_steps = ESteps.ClearCacheFiles;
}
@@ -43,7 +43,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "The Package is initializing ! Please try to destroy the package again later.";
Error = "The Package is initializing. Please try to destroy the package again later.";
}
else if (_resourcePackage.InitializeStatus == EOperationStatus.Failed)
{
@@ -87,7 +87,7 @@ namespace YooAsset
_failedTryAgain = failedTryAgain;
// 统计下载信息
CalculatDownloaderInfo();
CalculateDownloaderInfo();
}
internal override void InternalStart()
{
@@ -262,7 +262,7 @@ namespace YooAsset
}
}
}
private void CalculatDownloaderInfo()
private void CalculateDownloaderInfo()
{
if (_bundleInfoList != null)
{
@@ -288,23 +288,23 @@ namespace YooAsset
{
if (_packageName != downloader._packageName)
{
YooLogger.Error("The downloaders have different resource packages !");
YooLogger.Error("The downloaders have different resource packages.");
return;
}
if (Status != EOperationStatus.None)
{
YooLogger.Error("The downloader is running, can not combine with other downloader !");
YooLogger.Error("The downloader is running, can not combine with other downloader.");
return;
}
HashSet<string> temper = new HashSet<string>();
HashSet<string> combineGuidSet = new HashSet<string>();
foreach (var bundleInfo in _bundleInfoList)
{
string combineGUID = bundleInfo.GetDownloadCombineGUID();
if (temper.Contains(combineGUID) == false)
if (combineGuidSet.Contains(combineGUID) == false)
{
temper.Add(combineGUID);
combineGuidSet.Add(combineGUID);
}
}
@@ -312,14 +312,14 @@ namespace YooAsset
foreach (var bundleInfo in downloader._bundleInfoList)
{
string combineGUID = bundleInfo.GetDownloadCombineGUID();
if (temper.Contains(combineGUID) == false)
if (combineGuidSet.Contains(combineGUID) == false)
{
_bundleInfoList.Add(bundleInfo);
}
}
// 重新统计下载信息
CalculatDownloaderInfo();
CalculateDownloaderInfo();
}
/// <summary>
@@ -89,7 +89,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"{_playMode} can not support WebGL plateform !";
Error = $"{_playMode} can not support WebGL plateform.";
YooLogger.Error(Error);
return;
}
@@ -103,7 +103,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"{nameof(EPlayMode.WebPlayMode)} only support WebGL plateform !";
Error = $"{nameof(EPlayMode.WebPlayMode)} only support WebGL plateform.";
YooLogger.Error(Error);
return;
}
@@ -31,7 +31,7 @@ namespace YooAsset
/// <summary>
/// 解析的清单实例
/// </summary>
public PackageManifest Manifest { private set; get; }
public PackageManifest Manifest { get; private set; }
public DeserializeManifestOperation(IManifestRestoreServices services, byte[] binaryData)
{
@@ -68,7 +68,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Buffer is invalid !";
Error = "Buffer is invalid.";
return;
}
@@ -78,7 +78,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "The manifest file format is invalid !";
Error = "The manifest file format is invalid.";
return;
}
@@ -115,9 +115,9 @@ namespace YooAsset
// 检测配置
if (Manifest.EnableAddressable && Manifest.LocationToLower)
throw new YooManifestException("Addressable not support location to lower !");
throw new YooManifestException("Addressable not support location to lower.");
if (Manifest.EnableAddressable == false && Manifest.ReplaceAssetPathWithAddress)
throw new YooManifestException("Replace asset path with address need enable Addressable !");
throw new YooManifestException("Replace asset path with address need enable Addressable.");
_steps = ESteps.PrepareAssetList;
}
@@ -40,7 +40,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "The file system parameters is empty !";
Error = "The file system parameters is empty.";
return;
}
@@ -50,7 +50,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "An empty object exists in the list!";
Error = "An empty object exists in the list.";
return;
}
}
@@ -76,7 +76,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to create file system instance !";
Error = "Failed to create file system instance.";
return;
}
@@ -102,7 +102,7 @@ namespace YooAsset
{
if (Status != EOperationStatus.Succeed)
{
YooLogger.Error($"{nameof(PreDownloadContentOperation)} status is not succeed !");
YooLogger.Error($"{nameof(PreDownloadContentOperation)} status is not succeed.");
return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName);
}
@@ -116,7 +116,7 @@ namespace YooAsset
{
if (Status != EOperationStatus.Succeed)
{
YooLogger.Error($"{nameof(PreDownloadContentOperation)} status is not succeed !");
YooLogger.Error($"{nameof(PreDownloadContentOperation)} status is not succeed.");
return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName);
}
@@ -335,7 +335,7 @@ namespace YooAsset
{
string error;
if (string.IsNullOrEmpty(location))
error = $"The location is null or empty !";
error = $"The location is null or empty.";
else
error = $"The location is invalid : {location}";
AssetInfo assetInfo = new AssetInfo(PackageName, error);
@@ -369,8 +369,8 @@ namespace YooAsset
{
if (IncludeAssetGUID == false)
{
YooLogger.Warning("Package manifest not include asset guid ! Please check asset bundle collector settings.");
AssetInfo assetInfo = new AssetInfo(PackageName, "AssetGUID data is empty !");
YooLogger.Warning("Package manifest not include asset guid. Please check asset bundle collector settings.");
AssetInfo assetInfo = new AssetInfo(PackageName, "AssetGUID data is empty.");
return assetInfo;
}
@@ -384,7 +384,7 @@ namespace YooAsset
{
string error;
if (string.IsNullOrEmpty(assetGUID))
error = $"The assetGUID is null or empty !";
error = $"The assetGUID is null or empty.";
else
error = $"The assetGUID is invalid : {assetGUID}";
AssetInfo assetInfo = new AssetInfo(PackageName, error);
@@ -19,10 +19,5 @@ namespace YooAsset
public const string FileVersion = "2025.9.30";
public const string VERSION_2025_8_28 = "2025.8.28";
public const string VERSION_2025_9_30 = "2025.9.30";
/// <summary>
/// 版本兼容
/// </summary>
public const bool BackwardCompatible = true;
}
}
@@ -8,6 +8,8 @@ namespace YooAsset
{
internal static class PackageManifestTools
{
private const int MD5HashLength = 32; //MD5的哈希值通常为32个字符
/// <summary>
/// 验证清单文件的二进制数据
/// </summary>
@@ -19,9 +21,8 @@ namespace YooAsset
return false;
// 注意:兼容俩种验证方式
// 注意:计算MD5的哈希值通常为32个字符
string fileHash;
if (hashValue.Length == 32)
if (hashValue.Length == MD5HashLength)
fileHash = HashUtility.BytesMD5(fileData);
else
fileHash = HashUtility.BytesCRC32(fileData);
@@ -91,7 +91,7 @@ namespace YooAsset
// 检测重复初始化
if (_initializeOp != null)
throw new YooPackageException(PackageName, $"Resource package '{PackageName}' is already initialized!");
throw new YooPackageException(PackageName, $"Resource package '{PackageName}' is already initialized.");
// 开始初始化操作
_initializeOp = new InitializePackageOperation(this, options);
@@ -149,7 +149,7 @@ namespace YooAsset
// 注意:强烈建议在更新之前保持加载器为空!
if (_resourceManager.HasAnyLoader())
{
YooLogger.Warning($"Found loaded bundle before update manifest ! Recommended to call the {nameof(UnloadAllAssetsAsync)} method to release loaded bundle !");
YooLogger.Warning($"Found loaded bundle before update manifest. Recommended to call the {nameof(UnloadAllAssetsAsync)} method to release loaded bundle.");
}
var operation = new LoadPackageManifestOperation(_fileSystemHost, options);
@@ -891,23 +891,23 @@ namespace YooAsset
{
if (InitializeStatus == EOperationStatus.None)
{
throw new YooPackageException(PackageName, "Resource package not initialized!");
throw new YooPackageException(PackageName, "Resource package not initialized.");
}
else if (InitializeStatus == EOperationStatus.Processing)
{
throw new YooPackageException(PackageName, "Resource package initialization not completed!");
throw new YooPackageException(PackageName, "Resource package initialization not completed.");
}
else if (InitializeStatus == EOperationStatus.Failed)
{
string error = _initializeOp == null ? string.Empty : _initializeOp.Error;
throw new YooPackageException(PackageName, $"Resource package initialization failed! Error: {error}");
throw new YooPackageException(PackageName, $"Resource package initialization failed. Error: {error}");
}
}
if (checkActiveManifest)
{
if (_fileSystemHost.ActiveManifest == null)
throw new YooPackageException(PackageName, "Cannot found active package manifest!");
throw new YooPackageException(PackageName, "Cannot found active package manifest.");
}
}