refactor : 重构代码

This commit is contained in:
何冠峰
2026-01-16 10:28:01 +08:00
parent 2b6e7856e7
commit b0e85017d2
100 changed files with 1042 additions and 1582 deletions
@@ -129,12 +129,12 @@ namespace YooAsset
/// <summary>
/// 自定义参数:解密服务接口的实例类
/// </summary>
public IDecryptionServices DecryptionServices { private set; get; }
public IBundleDecryptionServices BundleDecryptionServices { private set; get; }
/// <summary>
/// 自定义参数:资源清单服务类
/// </summary>
public IManifestRestoreServices ManifestServices { private set; get; }
public IManifestRestoreServices ManifestRestoreServices { private set; get; }
/// <summary>
/// 自定义参数:拷贝内置文件接口的实例类
@@ -161,7 +161,7 @@ namespace YooAsset
var operation = new DCFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout);
return operation;
}
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options)
{
if (options.ClearMode == EFileClearMode.ClearAllBundleFiles.ToString())
{
@@ -170,17 +170,17 @@ namespace YooAsset
}
else if (options.ClearMode == EFileClearMode.ClearUnusedBundleFiles.ToString())
{
var operation = new ClearUnusedCacheBundleFilesOperation(this, manifest);
var operation = new ClearUnusedCacheBundleFilesOperation(this, options.Manifest);
return operation;
}
else if (options.ClearMode == EFileClearMode.ClearBundleFilesByLocations.ToString())
{
var operation = new ClearCacheBundleFilesByLocationsOperaiton(this, manifest, options.ClearParam);
var operation = new ClearCacheBundleFilesByLocationsOperaiton(this, options.Manifest, options.ClearParam);
return operation;
}
else if (options.ClearMode == EFileClearMode.ClearBundleFilesByTags.ToString())
{
var operation = new ClearCacheBundleFilesByTagsOperaiton(this, manifest, options.ClearParam);
var operation = new ClearCacheBundleFilesByTagsOperaiton(this, options.Manifest, options.ClearParam);
return operation;
}
else if (options.ClearMode == EFileClearMode.ClearAllManifestFiles.ToString())
@@ -190,7 +190,7 @@ namespace YooAsset
}
else if (options.ClearMode == EFileClearMode.ClearUnusedManifestFiles.ToString())
{
var operation = new ClearUnusedCacheManifestFilesOperation(this, manifest);
var operation = new ClearUnusedCacheManifestFilesOperation(this, options.Manifest);
return operation;
}
else
@@ -200,9 +200,10 @@ namespace YooAsset
return operation;
}
}
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
{
// 获取下载地址
PackageBundle bundle = options.Bundle;
if (string.IsNullOrEmpty(options.ImportFilePath))
{
// 注意:如果是解压文件系统类,这里会返回本地内置文件的下载路径
@@ -217,17 +218,18 @@ namespace YooAsset
options.SetURL(mainURL, mainURL);
}
var downloader = new DownloadPackageBundleOperation(this, bundle, options);
var downloader = new DownloadPackageBundleOperation(this, options);
return downloader;
}
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
{
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
PackageBundle bundle = options.Bundle;
if (bundle.BundleType == (int)EBundleType.AssetBundle)
{
var operation = new DCFSLoadAssetBundleOperation(this, bundle);
return operation;
}
else if (bundle.BundleType == (int)EBuildBundleType.RawBundle)
else if (bundle.BundleType == (int)EBundleType.RawBundle)
{
var operation = new DCFSLoadRawBundleOperation(this, bundle);
return operation;
@@ -315,13 +317,13 @@ namespace YooAsset
{
ResumeDownloadResponseCodes = (List<long>)value;
}
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
else if (name == FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES)
{
DecryptionServices = (IDecryptionServices)value;
BundleDecryptionServices = (IBundleDecryptionServices)value;
}
else if (name == FileSystemParametersDefine.MANIFEST_SERVICES)
else if (name == FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES)
{
ManifestServices = (IManifestRestoreServices)value;
ManifestRestoreServices = (IManifestRestoreServices)value;
}
else if (name == FileSystemParametersDefine.COPY_LOCAL_FILE_SERVICES)
{
@@ -403,20 +405,20 @@ namespace YooAsset
if (bundle.Encrypted)
{
if (DecryptionServices == null)
if (BundleDecryptionServices == null)
{
YooLogger.Error($"The {nameof(IDecryptionServices)} is null !");
YooLogger.Error($"The {nameof(IBundleDecryptionServices)} is null !");
return null;
}
string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo()
var bundleInfo = new DecryptBundleInfo()
{
BundleName = bundle.BundleName,
FileLoadCRC = bundle.UnityCRC,
FileLoadPath = filePath,
};
return DecryptionServices.ReadFileData(fileInfo);
return BundleDecryptionServices.ReadFileData(bundleInfo);
}
else
{
@@ -431,20 +433,20 @@ namespace YooAsset
if (bundle.Encrypted)
{
if (DecryptionServices == null)
if (BundleDecryptionServices == null)
{
YooLogger.Error($"The {nameof(IDecryptionServices)} is null !");
YooLogger.Error($"The {nameof(IBundleDecryptionServices)} is null !");
return null;
}
string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo()
var bundleInfo = new DecryptBundleInfo()
{
BundleName = bundle.BundleName,
FileLoadCRC = bundle.UnityCRC,
FileLoadPath = filePath,
};
return DecryptionServices.ReadFileText(fileInfo);
return BundleDecryptionServices.ReadFileText(bundleInfo);
}
else
{
@@ -649,46 +651,46 @@ namespace YooAsset
/// <summary>
/// 加载加密资源文件
/// </summary>
public DecryptResult LoadEncryptedAssetBundle(PackageBundle bundle)
public DecryptSyncResult LoadEncryptedBundleSync(PackageBundle bundle)
{
string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo()
var bundleInfo = new DecryptBundleInfo()
{
BundleName = bundle.BundleName,
FileLoadCRC = bundle.UnityCRC,
FileLoadPath = filePath,
};
return DecryptionServices.LoadAssetBundle(fileInfo);
return BundleDecryptionServices.LoadAssetBundleSync(bundleInfo);
}
/// <summary>
/// 加载加密资源文件
/// </summary>
public DecryptResult LoadEncryptedAssetBundleAsync(PackageBundle bundle)
public DecryptAsyncResult LoadEncryptedBundleAsync(PackageBundle bundle)
{
string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo()
var bundleInfo = new DecryptBundleInfo()
{
BundleName = bundle.BundleName,
FileLoadCRC = bundle.UnityCRC,
FileLoadPath = filePath,
};
return DecryptionServices.LoadAssetBundleAsync(fileInfo);
return BundleDecryptionServices.LoadAssetBundleAsync(bundleInfo);
}
/// <summary>
/// 加载加密资源文件
/// </summary>
public DecryptResult LoadEncryptedAssetBundleFallback(PackageBundle bundle)
public DecryptSyncResult LoadEncryptedBundleFallback(PackageBundle bundle)
{
string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo()
var bundleInfo = new DecryptBundleInfo()
{
BundleName = bundle.BundleName,
FileLoadCRC = bundle.UnityCRC,
FileLoadPath = filePath,
};
return DecryptionServices.LoadAssetBundleFallback(fileInfo);
return BundleDecryptionServices.LoadAssetBundleFallback(bundleInfo);
}
#endregion
}