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
@@ -26,21 +26,22 @@ namespace YooAsset
}
/// <summary>
/// 加载资源包
/// 创建加载器
/// </summary>
public FSLoadBundleOperation LoadBundleFile()
public FSLoadBundleOperation CreateBundleLoader()
{
return _fileSystem.LoadBundleFile(Bundle);
var options = new LoadBundleOptions(Bundle);
return _fileSystem.LoadBundleAsync(options);
}
/// <summary>
/// 创建下载器
/// </summary>
public FSDownloadFileOperation CreateDownloader(int failedTryAgain)
public FSDownloadFileOperation CreateBundleDownloader(int failedTryAgain)
{
DownloadFileOptions options = new DownloadFileOptions(failedTryAgain);
DownloadFileOptions options = new DownloadFileOptions(Bundle, failedTryAgain);
options.ImportFilePath = _importFilePath;
return _fileSystem.DownloadFileAsync(Bundle, options);
return _fileSystem.DownloadFileAsync(options);
}
/// <summary>
@@ -1,7 +1,7 @@

namespace YooAsset
{
public enum EBuildBundleType
public enum EBundleType
{
/// <summary>
/// 未知类型
@@ -4,12 +4,18 @@ using System.Collections.Generic;
namespace YooAsset
{
internal class PlayModeImpl : IPlayMode, IBundleQuery
internal class FileSystemHost
{
public readonly string PackageName;
public readonly List<IFileSystem> FileSystems = new List<IFileSystem>(10);
public PlayModeImpl(string packageName)
/// <summary>
/// 当前激活的清单
/// </summary>
public PackageManifest ActiveManifest { set; get; }
public FileSystemHost(string packageName)
{
PackageName = packageName;
}
@@ -47,16 +53,10 @@ namespace YooAsset
return operation;
}
#region IPlayMode接口
/// <summary>
/// 当前激活的清单
/// </summary>
public PackageManifest ActiveManifest { set; get; }
/// <summary>
/// 销毁文件系统
/// </summary>
void IPlayMode.DestroyFileSystem()
public void Destroy()
{
foreach (var fileSystem in FileSystems)
{
@@ -65,92 +65,7 @@ namespace YooAsset
FileSystems.Clear();
}
/// <summary>
/// 向网络端请求最新的资源版本
/// </summary>
RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(RequestPackageVersionOptions options)
{
var operation = new RequestPackageVersionImplOperation(this, options);
return operation;
}
/// <summary>
/// 向网络端请求并更新清单
/// </summary>
LoadPackageManifestOperation IPlayMode.LoadPackageManifestAsync(LoadPackageManifestOptions options)
{
var operation = new LoadPackageManifestOperation(this, options);
return operation;
}
/// <summary>
/// 预下载指定版本的包裹内容
/// </summary>
PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(PreDownloadContentOptions options)
{
var operation = new PreDownloadContentOperation(this, options);
return operation;
}
/// <summary>
/// 清理缓存文件
/// </summary>
ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(ClearCacheFilesOptions options)
{
var operation = new ClearCacheFilesOperation(this, options);
return operation;
}
// 下载相关
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain)
{
List<BundleInfo> downloadList = GetDownloadListByAll(ActiveManifest);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain)
{
List<BundleInfo> downloadList = GetDownloadListByTags(ActiveManifest, tags);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{
List<BundleInfo> downloadList = GetDownloadListByPaths(ActiveManifest, assetInfos, recursiveDownload);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
return operation;
}
// 解压相关
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain)
{
List<BundleInfo> unpcakList = GetUnpackListByAll(ActiveManifest);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain);
return operation;
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain)
{
List<BundleInfo> unpcakList = GetUnpackListByTags(ActiveManifest, tags);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain);
return operation;
}
// 导入相关
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importingMaxNumber, int failedTryAgain)
{
List<BundleInfo> importerList = GetImporterListByFilePaths(ActiveManifest, filePaths);
var operation = new ResourceImporterOperation(PackageName, importerList, importingMaxNumber, failedTryAgain);
return operation;
}
ResourceImporterOperation IPlayMode.CreateResourceImporterByFileInfos(ImportFileInfo[] fileInfos, int importingMaxNumber, int failedTryAgain)
{
List<BundleInfo> importerList = GetImporterListByFileInfos(ActiveManifest, fileInfos);
var operation = new ResourceImporterOperation(PackageName, importerList, importingMaxNumber, failedTryAgain);
return operation;
}
#endregion
#region IBundleQuery接口
#region 资源包相关
private BundleInfo CreateBundleInfo(PackageBundle packageBundle)
{
if (packageBundle == null)
@@ -165,7 +80,11 @@ namespace YooAsset
throw new YooFileSystemException($"Can not found belong file system : {packageBundle.BundleName}");
}
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
/// <summary>
/// 获取主资源包信息
/// </summary>
public BundleInfo GetMainBundleInfo(AssetInfo assetInfo)
{
if (assetInfo == null || assetInfo.IsInvalid)
throw new YooInternalException();
@@ -174,7 +93,21 @@ namespace YooAsset
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.Asset);
return CreateBundleInfo(packageBundle);
}
List<BundleInfo> IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo)
/// <summary>
/// 获取主资源包名称
/// </summary>
public string GetMainBundleName(int bundleID)
{
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID);
return packageBundle.BundleName;
}
/// <summary>
/// 获取依赖的资源包信息集合
/// </summary>
public List<BundleInfo> GetDependBundleInfos(AssetInfo assetInfo)
{
if (assetInfo == null || assetInfo.IsInvalid)
throw new YooInternalException();
@@ -199,45 +132,50 @@ namespace YooAsset
}
return result;
}
string IBundleQuery.GetMainBundleName(int bundleID)
{
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID);
return packageBundle.BundleName;
}
#endregion
/// <summary>
/// 获取主文件系统
/// 说明:文件系统列表里,最后一个属于主文件系统
/// </summary>
public IFileSystem GetMainFileSystem()
#region 下载器相关
public ResourceDownloaderOperation CreateResourceDownloader(ResourceDownloaderOptions options)
{
int count = FileSystems.Count;
if (count == 0)
return null;
return FileSystems[count - 1];
List<BundleInfo> downloadList;
if (options.Tags == null)
downloadList = GetDownloadListByAll(ActiveManifest);
else
downloadList = GetDownloadListByTags(ActiveManifest, options.Tags);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain);
return operation;
}
public ResourceDownloaderOperation CreateResourceDownloader(BundleDownloaderOptions options)
{
List<BundleInfo> downloadList;
if (options.AssetInfos == null)
downloadList = GetDownloadListByAll(ActiveManifest);
else
downloadList = GetDownloadListByAssetInfos(ActiveManifest, options.AssetInfos, options.DownloadBundleDependencies);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain);
return operation;
}
public ResourceUnpackerOperation CreateResourceUnpacker(ResourceUnpackerOptions options)
{
List<BundleInfo> unpcakList;
if (options.Tags == null)
unpcakList = GetUnpackListByAll(ActiveManifest);
else
unpcakList = GetUnpackListByTags(ActiveManifest, options.Tags);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, options.MaximumConcurrency, options.FailedTryAgain);
return operation;
}
public ResourceImporterOperation CreateResourceImporter(BundleImporterOptions options)
{
List<BundleInfo> importerList = GetImporterListByBundleInfos(ActiveManifest, options.BundleInfos);
var operation = new ResourceImporterOperation(PackageName, importerList, options.MaximumConcurrency, options.FailedTryAgain);
return operation;
}
/// <summary>
/// 获取资源包所属文件系统
/// </summary>
public IFileSystem GetBelongFileSystem(PackageBundle packageBundle)
{
for (int i = 0; i < FileSystems.Count; i++)
{
IFileSystem fileSystem = FileSystems[i];
if (fileSystem.Belong(packageBundle))
{
return fileSystem;
}
}
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
return null;
}
public List<BundleInfo> GetDownloadListByAll(PackageManifest manifest)
internal List<BundleInfo> GetDownloadListByAll(PackageManifest manifest)
{
if (manifest == null)
return new List<BundleInfo>();
@@ -257,7 +195,7 @@ namespace YooAsset
}
return result;
}
public List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags)
internal List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags)
{
if (manifest == null)
return new List<BundleInfo>();
@@ -290,7 +228,7 @@ namespace YooAsset
}
return result;
}
public List<BundleInfo> GetDownloadListByPaths(PackageManifest manifest, AssetInfo[] assetInfos, bool recursiveDownload)
internal List<BundleInfo> GetDownloadListByAssetInfos(PackageManifest manifest, AssetInfo[] assetInfos, bool recursiveDownload)
{
if (manifest == null)
return new List<BundleInfo>();
@@ -365,7 +303,7 @@ namespace YooAsset
}
return result;
}
public List<BundleInfo> GetUnpackListByAll(PackageManifest manifest)
internal List<BundleInfo> GetUnpackListByAll(PackageManifest manifest)
{
if (manifest == null)
return new List<BundleInfo>();
@@ -385,7 +323,7 @@ namespace YooAsset
}
return result;
}
public List<BundleInfo> GetUnpackListByTags(PackageManifest manifest, string[] tags)
internal List<BundleInfo> GetUnpackListByTags(PackageManifest manifest, string[] tags)
{
if (manifest == null)
return new List<BundleInfo>();
@@ -408,22 +346,7 @@ namespace YooAsset
}
return result;
}
public List<BundleInfo> GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths)
{
if (manifest == null)
return new List<BundleInfo>();
ImportFileInfo[] fileInfos = new ImportFileInfo[filePaths.Length];
for (int i = 0; i < filePaths.Length; i++)
{
ImportFileInfo fileInfo = new ImportFileInfo();
fileInfo.FilePath = filePaths[i];
fileInfos[i] = fileInfo;
}
return GetImporterListByFileInfos(manifest, fileInfos);
}
public List<BundleInfo> GetImporterListByFileInfos(PackageManifest manifest, ImportFileInfo[] fileInfos)
internal List<BundleInfo> GetImporterListByBundleInfos(PackageManifest manifest, ImportBundleInfo[] fileInfos)
{
if (manifest == null)
return new List<BundleInfo>();
@@ -477,5 +400,36 @@ namespace YooAsset
}
return result;
}
#endregion
/// <summary>
/// 获取主文件系统
/// 说明:文件系统列表里,最后一个属于主文件系统
/// </summary>
public IFileSystem GetMainFileSystem()
{
int count = FileSystems.Count;
if (count == 0)
return null;
return FileSystems[count - 1];
}
/// <summary>
/// 获取资源包所属文件系统
/// </summary>
public IFileSystem GetBelongFileSystem(PackageBundle packageBundle)
{
for (int i = 0; i < FileSystems.Count; i++)
{
IFileSystem fileSystem = FileSystems[i];
if (fileSystem.Belong(packageBundle))
{
return fileSystem;
}
}
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
return null;
}
}
}
@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: e7f5776546411834d9ed949d54a6f241
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,23 +0,0 @@
using System.Collections;
using System.Collections.Generic;
namespace YooAsset
{
internal interface IBundleQuery
{
/// <summary>
/// 获取主资源包信息
/// </summary>
BundleInfo GetMainBundleInfo(AssetInfo assetInfo);
/// <summary>
/// 获取依赖的资源包信息集合
/// </summary>
List<BundleInfo> GetDependBundleInfos(AssetInfo assetPath);
/// <summary>
/// 获取主资源包名称
/// </summary>
string GetMainBundleName(int bundleID);
}
}
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 70420213c551a2b4b8cf014067699b07
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,49 +0,0 @@
namespace YooAsset
{
internal interface IPlayMode
{
/// <summary>
/// 当前激活的清单
/// </summary>
PackageManifest ActiveManifest { set; get; }
/// <summary>
/// 销毁文件系统
/// </summary>
void DestroyFileSystem();
/// <summary>
/// 请求最新的资源版本
/// </summary>
RequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options);
/// <summary>
/// 请求并加载资源清单
/// </summary>
LoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options);
/// <summary>
/// 预下载指定版本的包裹内容
/// </summary>
PreDownloadContentOperation PreDownloadContentAsync(PreDownloadContentOptions options);
/// <summary>
/// 清理缓存文件
/// </summary>
ClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options);
// 下载相关
ResourceDownloaderOperation CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain);
ResourceDownloaderOperation CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain);
ResourceDownloaderOperation CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain);
// 解压相关
ResourceUnpackerOperation CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain);
ResourceUnpackerOperation CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain);
// 导入相关
ResourceImporterOperation CreateResourceImporterByFilePaths(string[] filePaths, int importingMaxNumber, int failedTryAgain);
ResourceImporterOperation CreateResourceImporterByFileInfos(ImportFileInfo[] fileInfos, int importingMaxNumber, int failedTryAgain);
}
}
@@ -14,15 +14,15 @@ namespace YooAsset
Done,
}
private readonly PlayModeImpl _impl;
private readonly FileSystemHost _host;
private readonly ClearCacheFilesOptions _options;
private List<IFileSystem> _cloneList;
private FSClearCacheFilesOperation _clearCacheFilesOp;
private ESteps _steps = ESteps.None;
internal ClearCacheFilesOperation(PlayModeImpl impl, ClearCacheFilesOptions options)
internal ClearCacheFilesOperation(FileSystemHost host, ClearCacheFilesOptions options)
{
_impl = impl;
_host = host;
_options = options;
}
internal override void InternalStart()
@@ -36,7 +36,7 @@ namespace YooAsset
if (_steps == ESteps.Prepare)
{
var fileSytems = _impl.FileSystems;
var fileSytems = _host.FileSystems;
if (fileSytems == null || fileSytems.Count == 0)
{
_steps = ESteps.Done;
@@ -72,7 +72,7 @@ namespace YooAsset
var fileSystem = _cloneList[0];
_cloneList.RemoveAt(0);
_clearCacheFilesOp = fileSystem.ClearCacheFilesAsync(_impl.ActiveManifest, _options);
_clearCacheFilesOp = fileSystem.ClearCacheFilesAsync(_options);
_clearCacheFilesOp.StartOperation();
AddChildOperation(_clearCacheFilesOp);
_steps = ESteps.CheckClearResult;
@@ -13,20 +13,28 @@ namespace YooAsset
/// </summary>
public object ClearParam { private set; get; }
/// <summary>
/// 资源清单
/// </summary>
internal PackageManifest Manifest { set; get; }
public ClearCacheFilesOptions(EFileClearMode clearMode)
{
ClearMode = clearMode.ToString();
ClearParam = null;
Manifest = null;
}
public ClearCacheFilesOptions(EFileClearMode clearMode, object clearParam)
{
ClearMode = clearMode.ToString();
ClearParam = clearParam;
Manifest = null;
}
public ClearCacheFilesOptions(string clearMode, object clearParam)
{
ClearMode = clearMode;
ClearParam = clearParam;
Manifest = null;
}
}
}
@@ -0,0 +1,102 @@
namespace YooAsset
{
/// <summary>
/// 下载器结束
/// </summary>
public struct DownloaderFinishData
{
/// <summary>
/// 所属包裹名称
/// </summary>
public string PackageName;
/// <summary>
/// 是否成功
/// </summary>
public bool Succeed;
}
/// <summary>
/// 下载器相关的更新数据
/// </summary>
public struct DownloadUpdateData
{
/// <summary>
/// 所属包裹名称
/// </summary>
public string PackageName;
/// <summary>
/// 下载进度 (0-1f)
/// </summary>
public float Progress;
/// <summary>
/// 下载文件总数
/// </summary>
public int TotalDownloadCount;
/// <summary>
/// 当前完成的下载文件数量
/// </summary>
public int CurrentDownloadCount;
/// <summary>
/// 下载数据总大小(单位:字节)
/// </summary>
public long TotalDownloadBytes;
/// <summary>
/// 当前完成的下载数据大小(单位:字节)
/// </summary>
public long CurrentDownloadBytes;
}
/// <summary>
/// 下载器相关的错误数据
/// </summary>
public struct DownloadErrorData
{
/// <summary>
/// 所属包裹名称
/// </summary>
public string PackageName;
/// <summary>
/// 下载失败的文件名称
/// </summary>
public string FileName;
/// <summary>
/// 错误信息
/// </summary>
public string ErrorInfo;
}
/// <summary>
/// 下载器相关的文件数据
/// </summary>
public struct DownloadFileData
{
/// <summary>
/// 所属包裹名称
/// </summary>
public string PackageName;
/// <summary>
/// 资源包名称
/// </summary>
public string BundleName;
/// <summary>
/// 文件名称
/// </summary>
public string FileName;
/// <summary>
/// 文件大小
/// </summary>
public long FileSize;
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 4629f36c31a96214b9057827c6a283cf
guid: 0a798eb87a00a284189bb69a767d2c02
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -3,107 +3,6 @@ using System.Collections.Generic;
namespace YooAsset
{
#region 下载器相关类型定义
/// <summary>
/// 下载器结束
/// </summary>
public struct DownloaderFinishData
{
/// <summary>
/// 所属包裹名称
/// </summary>
public string PackageName;
/// <summary>
/// 是否成功
/// </summary>
public bool Succeed;
}
/// <summary>
/// 下载器相关的更新数据
/// </summary>
public struct DownloadUpdateData
{
/// <summary>
/// 所属包裹名称
/// </summary>
public string PackageName;
/// <summary>
/// 下载进度 (0-1f)
/// </summary>
public float Progress;
/// <summary>
/// 下载文件总数
/// </summary>
public int TotalDownloadCount;
/// <summary>
/// 当前完成的下载文件数量
/// </summary>
public int CurrentDownloadCount;
/// <summary>
/// 下载数据总大小(单位:字节)
/// </summary>
public long TotalDownloadBytes;
/// <summary>
/// 当前完成的下载数据大小(单位:字节)
/// </summary>
public long CurrentDownloadBytes;
}
/// <summary>
/// 下载器相关的错误数据
/// </summary>
public struct DownloadErrorData
{
/// <summary>
/// 所属包裹名称
/// </summary>
public string PackageName;
/// <summary>
/// 下载失败的文件名称
/// </summary>
public string FileName;
/// <summary>
/// 错误信息
/// </summary>
public string ErrorInfo;
}
/// <summary>
/// 下载器相关的文件数据
/// </summary>
public struct DownloadFileData
{
/// <summary>
/// 所属包裹名称
/// </summary>
public string PackageName;
/// <summary>
/// 资源包名称
/// </summary>
public string BundleName;
/// <summary>
/// 文件名称
/// </summary>
public string FileName;
/// <summary>
/// 文件大小
/// </summary>
public long FileSize;
}
#endregion
public abstract class DownloaderOperation : AsyncOperationBase
{
private enum ESteps
@@ -140,7 +39,7 @@ namespace YooAsset
#endregion
private readonly string _packageName;
private readonly int _downloadingMaxNumber;
private readonly int _maximumConcurrency;
private readonly int _failedTryAgain;
private readonly List<BundleInfo> _bundleInfoList;
private readonly List<FSDownloadFileOperation> _downloaders = new List<FSDownloadFileOperation>(MAX_LOADER_COUNT);
@@ -203,11 +102,11 @@ namespace YooAsset
public DownloadFileBegin DownloadFileBeginCallback { set; get; }
internal DownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
internal DownloaderOperation(string packageName, List<BundleInfo> downloadList, int maximumConcurrency, int failedTryAgain)
{
_packageName = packageName;
_bundleInfoList = downloadList;
_downloadingMaxNumber = UnityEngine.Mathf.Clamp(downloadingMaxNumber, 1, MAX_LOADER_COUNT); ;
_maximumConcurrency = UnityEngine.Mathf.Clamp(maximumConcurrency, 1, MAX_LOADER_COUNT); ;
_failedTryAgain = failedTryAgain;
// 统计下载信息
@@ -321,11 +220,11 @@ namespace YooAsset
if (_isPause)
return;
if (_downloaders.Count < _downloadingMaxNumber)
if (_downloaders.Count < _maximumConcurrency)
{
int index = _bundleInfoList.Count - 1;
var bundleInfo = _bundleInfoList[index];
var downloader = bundleInfo.CreateDownloader(_failedTryAgain);
var downloader = bundleInfo.CreateBundleDownloader(_failedTryAgain);
downloader.StartOperation();
this.AddChildOperation(downloader);
@@ -502,25 +401,25 @@ namespace YooAsset
public sealed class ResourceDownloaderOperation : DownloaderOperation
{
internal ResourceDownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain)
internal ResourceDownloaderOperation(string packageName, List<BundleInfo> downloadList, int maximumConcurrency, int failedTryAgain)
: base(packageName, downloadList, maximumConcurrency, failedTryAgain)
{
}
/// <summary>
/// 创建空的下载器
/// </summary>
internal static ResourceDownloaderOperation CreateEmptyDownloader(string packageName, int downloadingMaxNumber, int failedTryAgain)
internal static ResourceDownloaderOperation CreateEmptyDownloader(string packageName, int maximumConcurrency, int failedTryAgain)
{
List<BundleInfo> downloadList = new List<BundleInfo>();
var operation = new ResourceDownloaderOperation(packageName, downloadList, downloadingMaxNumber, failedTryAgain);
var operation = new ResourceDownloaderOperation(packageName, downloadList, maximumConcurrency, failedTryAgain);
return operation;
}
}
public sealed class ResourceUnpackerOperation : DownloaderOperation
{
internal ResourceUnpackerOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain)
internal ResourceUnpackerOperation(string packageName, List<BundleInfo> downloadList, int maximumConcurrency, int failedTryAgain)
: base(packageName, downloadList, maximumConcurrency, failedTryAgain)
{
}
@@ -536,8 +435,8 @@ namespace YooAsset
}
public sealed class ResourceImporterOperation : DownloaderOperation
{
internal ResourceImporterOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain)
internal ResourceImporterOperation(string packageName, List<BundleInfo> downloadList, int maximumConcurrency, int failedTryAgain)
: base(packageName, downloadList, maximumConcurrency, failedTryAgain)
{
}
@@ -0,0 +1,155 @@
namespace YooAsset
{
/// <summary>
/// 资源下载选项
/// </summary>
public struct BundleDownloaderOptions
{
/// <summary>
/// 最大并发数量
/// </summary>
public int MaximumConcurrency { private set; get; }
/// <summary>
/// 失败后的重试次数
/// </summary>
public int FailedTryAgain { private set; get; }
/// <summary>
/// 下载资源对象所属资源包内所有资源对象依赖的资源包
/// </summary>
public bool DownloadBundleDependencies { private set; get; }
/// <summary>
/// 资源信息列表
/// 说明:如果列表为NULL,则下载所有资产
/// </summary>
public AssetInfo[] AssetInfos { private set; get; }
public BundleDownloaderOptions(AssetInfo assetInfo, bool downloadDependencies, int maximumConcurrency, int failedTryAgain)
{
AssetInfos = new AssetInfo[] { assetInfo };
DownloadBundleDependencies = downloadDependencies;
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
public BundleDownloaderOptions(AssetInfo[] assetInfos, bool downloadDependencies, int maximumConcurrency, int failedTryAgain)
{
AssetInfos = assetInfos;
DownloadBundleDependencies = downloadDependencies;
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
}
/// <summary>
/// 资源下载选项
/// </summary>
public struct ResourceDownloaderOptions
{
/// <summary>
/// 最大并发数量
/// </summary>
public int MaximumConcurrency { private set; get; }
/// <summary>
/// 失败后的重试次数
/// </summary>
public int FailedTryAgain { private set; get; }
/// <summary>
/// 资源标签列表
/// 说明:如果列表为NULL,则下载所有资产
/// </summary>
public string[] Tags { private set; get; }
public ResourceDownloaderOptions(int maximumConcurrency, int failedTryAgain)
{
Tags = null;
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
public ResourceDownloaderOptions(string tag, int maximumConcurrency, int failedTryAgain)
{
Tags = new string[] { tag };
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
public ResourceDownloaderOptions(string[] tags, int maximumConcurrency, int failedTryAgain)
{
Tags = tags;
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
}
/// <summary>
/// 资源解压选项
/// </summary>
public struct ResourceUnpackerOptions
{
/// <summary>
/// 最大并发数量
/// </summary>
public int MaximumConcurrency { private set; get; }
/// <summary>
/// 失败后的重试次数
/// </summary>
public int FailedTryAgain { private set; get; }
/// <summary>
/// 资源标签列表
/// 说明:如果列表为NULL,则解压所有资产
/// </summary>
public string[] Tags { private set; get; }
public ResourceUnpackerOptions(int maximumConcurrency, int failedTryAgain)
{
Tags = null;
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
public ResourceUnpackerOptions(string tag, int maximumConcurrency, int failedTryAgain)
{
Tags = new string[] { tag };
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
public ResourceUnpackerOptions(string[] tags, int maximumConcurrency, int failedTryAgain)
{
Tags = tags;
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
}
/// <summary>
/// 资源导入选项
/// </summary>
public struct BundleImporterOptions
{
/// <summary>
/// 最大并发数量
/// </summary>
public int MaximumConcurrency { private set; get; }
/// <summary>
/// 失败后的重试次数
/// </summary>
public int FailedTryAgain { private set; get; }
/// <summary>
/// 资源包信息列表
/// </summary>
public ImportBundleInfo[] BundleInfos { private set; get; }
public BundleImporterOptions(ImportBundleInfo[] bundleInfos, int maximumConcurrency, int failedTryAgain)
{
BundleInfos = bundleInfos;
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: b0a23f529c8bf4943a371ee6b360e698
guid: 2567b73a071bdc14884214cb5e3b5cc0
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -17,7 +17,7 @@ namespace YooAsset
private readonly ResourcePackage _package;
private readonly InitializePackageOptions _options;
private PlayModeImpl _playModeImpl;
private FileSystemHost _fileSystemHost;
private InitializeFileSystemOperation _initializeFileSystemOp;
private EPlayMode _playMode;
private ESteps _steps = ESteps.None;
@@ -118,12 +118,11 @@ namespace YooAsset
{
string packageName = _package.PackageName;
var resourceManager = new ResourceManager(packageName);
var playModeImpl = new PlayModeImpl(packageName);
resourceManager.Initialize(_options, playModeImpl);
var fileSystemHost = new FileSystemHost(packageName);
resourceManager.Initialize(_options, fileSystemHost);
_playModeImpl = playModeImpl;
_package._bundleQuery = playModeImpl;
_package._playModeImpl = playModeImpl;
_fileSystemHost = fileSystemHost;
_package._fileSystemHost = fileSystemHost;
_package._resourceManager = resourceManager;
_steps = ESteps.InitFileSystem;
}
@@ -135,27 +134,27 @@ namespace YooAsset
if (_playMode == EPlayMode.EditorSimulateMode)
{
var initializeParameters = _options as EditorSimulateModeOptions;
_initializeFileSystemOp = _playModeImpl.InitializeAsync(initializeParameters.EditorFileSystemParameters);
_initializeFileSystemOp = _fileSystemHost.InitializeAsync(initializeParameters.EditorFileSystemParameters);
}
else if (_playMode == EPlayMode.OfflinePlayMode)
{
var initializeParameters = _options as OfflinePlayModeOptions;
_initializeFileSystemOp = _playModeImpl.InitializeAsync(initializeParameters.BuildinFileSystemParameters);
_initializeFileSystemOp = _fileSystemHost.InitializeAsync(initializeParameters.BuildinFileSystemParameters);
}
else if (_playMode == EPlayMode.HostPlayMode)
{
var initializeParameters = _options as HostPlayModeOptions;
_initializeFileSystemOp = _playModeImpl.InitializeAsync(initializeParameters.BuildinFileSystemParameters, initializeParameters.CacheFileSystemParameters);
_initializeFileSystemOp = _fileSystemHost.InitializeAsync(initializeParameters.BuildinFileSystemParameters, initializeParameters.CacheFileSystemParameters);
}
else if (_playMode == EPlayMode.WebPlayMode)
{
var initializeParameters = _options as WebPlayModeOptions;
_initializeFileSystemOp = _playModeImpl.InitializeAsync(initializeParameters.WebServerFileSystemParameters, initializeParameters.WebRemoteFileSystemParameters);
_initializeFileSystemOp = _fileSystemHost.InitializeAsync(initializeParameters.WebServerFileSystemParameters, initializeParameters.WebRemoteFileSystemParameters);
}
else if (_playMode == EPlayMode.CustomPlayMode)
{
var initializeParameters = _options as CustomPlayModeOptions;
_initializeFileSystemOp = _playModeImpl.InitializeAsync(initializeParameters.FileSystemParameterList);
_initializeFileSystemOp = _fileSystemHost.InitializeAsync(initializeParameters.FileSystemParameterList);
}
else
{
@@ -74,7 +74,7 @@ namespace YooAsset
// 读取文件标记
uint fileSign = _buffer.ReadUInt32();
if (fileSign != ManifestDefine.FileSign)
if (fileSign != PackageManifestDefine.FileSign)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
@@ -85,8 +85,8 @@ namespace YooAsset
// 读取文件版本
string fileVersion = _buffer.ReadUTF8();
Version fileVer = new Version(fileVersion);
Version ver2025_8_28 = new Version(ManifestDefine.VERSION_2025_8_28);
Version ver2025_9_30 = new Version(ManifestDefine.VERSION_2025_9_30);
Version ver2025_8_28 = new Version(PackageManifestDefine.VERSION_2025_8_28);
Version ver2025_9_30 = new Version(PackageManifestDefine.VERSION_2025_9_30);
if (fileVer < ver2025_8_28)
{
_steps = ESteps.Done;
@@ -14,15 +14,15 @@ namespace YooAsset
Done,
}
private readonly PlayModeImpl _impl;
private readonly FileSystemHost _host;
private readonly List<FileSystemParameters> _parametersList;
private List<FileSystemParameters> _cloneList;
private FSInitializeFileSystemOperation _initFileSystemOp;
private ESteps _steps = ESteps.None;
internal InitializeFileSystemOperation(PlayModeImpl impl, List<FileSystemParameters> parametersList)
internal InitializeFileSystemOperation(FileSystemHost host, List<FileSystemParameters> parametersList)
{
_impl = impl;
_host = host;
_parametersList = parametersList;
}
internal override void InternalStart()
@@ -71,7 +71,7 @@ namespace YooAsset
var fileSystemParams = _cloneList[0];
_cloneList.RemoveAt(0);
IFileSystem fileSystemInstance = fileSystemParams.CreateFileSystem(_impl.PackageName);
IFileSystem fileSystemInstance = fileSystemParams.CreateFileSystem(_host.PackageName);
if (fileSystemInstance == null)
{
_steps = ESteps.Done;
@@ -80,7 +80,7 @@ namespace YooAsset
return;
}
_impl.FileSystems.Add(fileSystemInstance);
_host.FileSystems.Add(fileSystemInstance);
_initFileSystemOp = fileSystemInstance.InitializeFileSystemAsync();
_initFileSystemOp.StartOperation();
AddChildOperation(_initFileSystemOp);
@@ -12,14 +12,14 @@ namespace YooAsset
Done,
}
private readonly PlayModeImpl _impl;
private readonly FileSystemHost _host;
private readonly LoadPackageManifestOptions _options;
private FSLoadPackageManifestOperation _loadPackageManifestOp;
private ESteps _steps = ESteps.None;
internal LoadPackageManifestOperation(PlayModeImpl impl, LoadPackageManifestOptions options)
internal LoadPackageManifestOperation(FileSystemHost host, LoadPackageManifestOptions options)
{
_impl = impl;
_host = host;
_options = options;
}
internal override void InternalStart()
@@ -48,7 +48,7 @@ namespace YooAsset
if (_steps == ESteps.CheckActiveManifest)
{
// 检测当前激活的清单对象
if (_impl.ActiveManifest != null && _impl.ActiveManifest.PackageVersion == _options.PackageVersion)
if (_host.ActiveManifest != null && _host.ActiveManifest.PackageVersion == _options.PackageVersion)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
@@ -63,7 +63,7 @@ namespace YooAsset
{
if (_loadPackageManifestOp == null)
{
var mainFileSystem = _impl.GetMainFileSystem();
var mainFileSystem = _host.GetMainFileSystem();
_loadPackageManifestOp = mainFileSystem.LoadPackageManifestAsync(_options);
_loadPackageManifestOp.StartOperation();
AddChildOperation(_loadPackageManifestOp);
@@ -76,7 +76,7 @@ namespace YooAsset
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
_impl.ActiveManifest = _loadPackageManifestOp.Manifest;
_host.ActiveManifest = _loadPackageManifestOp.Manifest;
Status = EOperationStatus.Succeed;
}
else
@@ -15,7 +15,7 @@ namespace YooAsset
Done,
}
private readonly PlayModeImpl _impl;
private readonly FileSystemHost _host;
private readonly PreDownloadContentOptions _options;
private readonly int _timeout;
private FSLoadPackageManifestOperation _loadPackageManifestOp;
@@ -23,9 +23,9 @@ namespace YooAsset
private ESteps _steps = ESteps.None;
internal PreDownloadContentOperation(PlayModeImpl impl, PreDownloadContentOptions options)
internal PreDownloadContentOperation(FileSystemHost host, PreDownloadContentOptions options)
{
_impl = impl;
_host = host;
_options = options;
}
internal override void InternalStart()
@@ -53,11 +53,11 @@ namespace YooAsset
if (_steps == ESteps.CheckActiveManifest)
{
// 检测当前激活的清单对象
if (_impl.ActiveManifest != null)
if (_host.ActiveManifest != null)
{
if (_impl.ActiveManifest.PackageVersion == _options.PackageVersion)
if (_host.ActiveManifest.PackageVersion == _options.PackageVersion)
{
_manifest = _impl.ActiveManifest;
_manifest = _host.ActiveManifest;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
return;
@@ -70,7 +70,7 @@ namespace YooAsset
{
if (_loadPackageManifestOp == null)
{
var mainFileSystem = _impl.GetMainFileSystem();
var mainFileSystem = _host.GetMainFileSystem();
var options = new LoadPackageManifestOptions(_options.PackageVersion, _options.Timeout);
_loadPackageManifestOp = mainFileSystem.LoadPackageManifestAsync(options);
_loadPackageManifestOp.StartOperation();
@@ -106,11 +106,11 @@ namespace YooAsset
if (Status != EOperationStatus.Succeed)
{
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain);
return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain);
}
List<BundleInfo> downloadList = _impl.GetDownloadListByAll(_manifest);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
List<BundleInfo> downloadList = _host.GetDownloadListByAll(_manifest);
var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
return operation;
}
@@ -125,11 +125,11 @@ namespace YooAsset
if (Status != EOperationStatus.Succeed)
{
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain);
return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain);
}
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, new string[] { tag });
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
List<BundleInfo> downloadList = _host.GetDownloadListByTags(_manifest, new string[] { tag });
var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
return operation;
}
@@ -144,11 +144,11 @@ namespace YooAsset
if (Status != EOperationStatus.Succeed)
{
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain);
return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain);
}
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, tags);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
List<BundleInfo> downloadList = _host.GetDownloadListByTags(_manifest, tags);
var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
return operation;
}
@@ -163,15 +163,15 @@ namespace YooAsset
if (Status != EOperationStatus.Succeed)
{
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain);
return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain);
}
List<AssetInfo> assetInfos = new List<AssetInfo>();
var assetInfo = _manifest.ConvertLocationToAssetInfo(location, null);
assetInfos.Add(assetInfo);
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
List<BundleInfo> downloadList = _host.GetDownloadListByAssetInfos(_manifest, assetInfos.ToArray(), recursiveDownload);
var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
return operation;
}
@@ -186,7 +186,7 @@ namespace YooAsset
if (Status != EOperationStatus.Succeed)
{
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain);
return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain);
}
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
@@ -196,8 +196,8 @@ namespace YooAsset
assetInfos.Add(assetInfo);
}
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
List<BundleInfo> downloadList = _host.GetDownloadListByAssetInfos(_manifest, assetInfos.ToArray(), recursiveDownload);
var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
return operation;
}
}
@@ -1,14 +1,7 @@
namespace YooAsset
{
public abstract class RequestPackageVersionOperation : AsyncOperationBase
{
/// <summary>
/// 当前最新的包裹版本
/// </summary>
public string PackageVersion { protected set; get; }
}
internal sealed class RequestPackageVersionImplOperation : RequestPackageVersionOperation
public sealed class RequestPackageVersionOperation : AsyncOperationBase
{
private enum ESteps
{
@@ -17,14 +10,20 @@ namespace YooAsset
Done,
}
private readonly PlayModeImpl _impl;
private readonly FileSystemHost _host;
private readonly RequestPackageVersionOptions _options;
private FSRequestPackageVersionOperation _requestPackageVersionOp;
private ESteps _steps = ESteps.None;
internal RequestPackageVersionImplOperation(PlayModeImpl impl, RequestPackageVersionOptions options)
/// <summary>
/// 当前最新的包裹版本
/// </summary>
public string PackageVersion { private set; get; }
internal RequestPackageVersionOperation(FileSystemHost host, RequestPackageVersionOptions options)
{
_impl = impl;
_host = host;
_options = options;
}
internal override void InternalStart()
@@ -40,7 +39,7 @@ namespace YooAsset
{
if (_requestPackageVersionOp == null)
{
var mainFileSystem = _impl.GetMainFileSystem();
var mainFileSystem = _host.GetMainFileSystem();
_requestPackageVersionOp = mainFileSystem.RequestPackageVersionAsync(_options);
_requestPackageVersionOp.StartOperation();
AddChildOperation(_requestPackageVersionOp);
@@ -122,8 +122,8 @@ namespace YooAsset
{
_mainfest = manifest;
_bundleType = manifest.BuildBundleType;
_fileExtension = ManifestTools.GetRemoteBundleFileExtension(BundleName);
_fileName = ManifestTools.GetRemoteBundleFileName(manifest.OutputNameStyle, BundleName, _fileExtension, FileHash);
_fileExtension = PackageManifestTools.GetRemoteBundleFileExtension(BundleName);
_fileName = PackageManifestTools.GetRemoteBundleFileName(manifest.OutputNameStyle, BundleName, _fileExtension, FileHash);
}
/// <summary>
@@ -1,7 +1,7 @@

namespace YooAsset
{
public class ManifestDefine
internal class PackageManifestDefine
{
/// <summary>
/// 文件极限大小(100MB)
@@ -6,7 +6,7 @@ using UnityEngine;
namespace YooAsset
{
internal static class ManifestTools
internal static class PackageManifestTools
{
/// <summary>
/// 验证清单文件的二进制数据
@@ -49,10 +49,10 @@ namespace YooAsset
using (FileStream fs = new FileStream(savePath, FileMode.Create))
{
// 创建缓存器
BufferWriter buffer = new BufferWriter(ManifestDefine.FileMaxSize);
BufferWriter buffer = new BufferWriter(PackageManifestDefine.FileMaxSize);
// 写入文件标记
buffer.WriteUInt32(ManifestDefine.FileSign);
buffer.WriteUInt32(PackageManifestDefine.FileSign);
// 写入文件版本
buffer.WriteUTF8(manifest.FileVersion);
@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: e9d6cb1ce5d510645866ad7c122abfab
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,16 +0,0 @@
namespace YooAsset
{
public class EditorSimulateModeHelper
{
public static PackageInvokeBuildResult SimulateBuild(string packageName)
{
var buildParam = new PackageInvokeBuildParam(packageName);
buildParam.BuildPipelineName = "EditorSimulateBuildPipeline";
buildParam.InvokeAssmeblyName = "YooAsset.Editor";
buildParam.InvokeClassFullName = "YooAsset.Editor.AssetBundleSimulateBuilder";
buildParam.InvokeMethodName = "SimulateBuild";
return PackageInvokeBuilder.InvokeBuilder(buildParam);
}
}
}
@@ -10,8 +10,7 @@ namespace YooAsset
{
private InitializePackageOperation _initializeOp;
internal ResourceManager _resourceManager;
internal IBundleQuery _bundleQuery;
internal IPlayMode _playModeImpl;
internal FileSystemHost _fileSystemHost;
internal EPlayMode _playMode;
/// <summary>
@@ -39,9 +38,9 @@ namespace YooAsset
{
get
{
if (_playModeImpl == null)
if (_fileSystemHost == null)
return false;
return _playModeImpl.ActiveManifest != null;
return _fileSystemHost.ActiveManifest != null;
}
}
@@ -66,7 +65,6 @@ namespace YooAsset
internal void InternalDestroy()
{
_initializeOp = null;
_bundleQuery = null;
// 销毁资源管理器
if (_resourceManager != null)
@@ -75,11 +73,11 @@ namespace YooAsset
_resourceManager = null;
}
// 销毁文件系统
if (_playModeImpl != null)
// 销毁文件系统中枢
if (_fileSystemHost != null)
{
_playModeImpl.DestroyFileSystem();
_playModeImpl = null;
_fileSystemHost.Destroy();
_fileSystemHost = null;
}
}
@@ -135,7 +133,7 @@ namespace YooAsset
public RequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options)
{
DebugCheckInitialize(false);
var operation = _playModeImpl.RequestPackageVersionAsync(options);
var operation = new RequestPackageVersionOperation(_fileSystemHost, options);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
@@ -153,7 +151,7 @@ namespace YooAsset
YooLogger.Warning($"Found loaded bundle before update manifest ! Recommended to call the {nameof(UnloadAllAssetsAsync)} method to release loaded bundle !");
}
var operation = _playModeImpl.LoadPackageManifestAsync(options);
var operation = new LoadPackageManifestOperation(_fileSystemHost, options);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
@@ -164,7 +162,7 @@ namespace YooAsset
public PreDownloadContentOperation PreDownloadContentAsync(PreDownloadContentOptions options)
{
DebugCheckInitialize(false);
var operation = _playModeImpl.PreDownloadContentAsync(options);
var operation = new PreDownloadContentOperation(_fileSystemHost, options);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
@@ -175,7 +173,8 @@ namespace YooAsset
public ClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options)
{
DebugCheckInitialize(false);
var operation = _playModeImpl.ClearCacheFilesAsync(options);
options.Manifest = _fileSystemHost.ActiveManifest;
var operation = new ClearCacheFilesOperation(_fileSystemHost, options);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
@@ -188,7 +187,7 @@ namespace YooAsset
public string GetPackageVersion()
{
DebugCheckInitialize();
return _playModeImpl.ActiveManifest.PackageVersion;
return _fileSystemHost.ActiveManifest.PackageVersion;
}
/// <summary>
@@ -197,7 +196,7 @@ namespace YooAsset
public string GetPackageNote()
{
DebugCheckInitialize();
return _playModeImpl.ActiveManifest.PackageNote;
return _fileSystemHost.ActiveManifest.PackageNote;
}
/// <summary>
@@ -206,7 +205,7 @@ namespace YooAsset
public PackageDetails GetPackageDetails()
{
DebugCheckInitialize();
return _playModeImpl.ActiveManifest.GetPackageDetails();
return _fileSystemHost.ActiveManifest.GetPackageDetails();
}
#endregion
@@ -216,7 +215,7 @@ namespace YooAsset
/// </summary>
public UnloadAllAssetsOperation UnloadAllAssetsAsync()
{
var options = new UnloadAllAssetsOptions();
var options = new UnloadAllAssetsOptions(true, true);
return UnloadAllAssetsAsync(options);
}
@@ -235,12 +234,22 @@ namespace YooAsset
/// <summary>
/// 回收不再使用的资源
/// 说明:卸载引用计数为零的资源
/// 说明:默认循环10次
/// </summary>
/// <param name="loopCount">循环迭代次数</param>
public UnloadUnusedAssetsOperation UnloadUnusedAssetsAsync(int loopCount = 10)
public UnloadUnusedAssetsOperation UnloadUnusedAssetsAsync()
{
var options = new UnloadUnusedAssetsOptions(10);
return UnloadUnusedAssetsAsync(options);
}
/// <summary>
/// 回收不再使用的资源
/// 说明:卸载引用计数为零的资源
/// </summary>
public UnloadUnusedAssetsOperation UnloadUnusedAssetsAsync(UnloadUnusedAssetsOptions options)
{
DebugCheckInitialize();
var operation = new UnloadUnusedAssetsOperation(_resourceManager, loopCount);
var operation = new UnloadUnusedAssetsOperation(_resourceManager, options);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
@@ -295,7 +304,7 @@ namespace YooAsset
public AssetInfo[] GetAllAssetInfos()
{
DebugCheckInitialize();
return _playModeImpl.ActiveManifest.GetAllAssetInfos();
return _fileSystemHost.ActiveManifest.GetAllAssetInfos();
}
/// <summary>
@@ -306,7 +315,7 @@ namespace YooAsset
{
DebugCheckInitialize();
string[] tags = new string[] { tag };
return _playModeImpl.ActiveManifest.GetAssetInfosByTags(tags);
return _fileSystemHost.ActiveManifest.GetAssetInfosByTags(tags);
}
/// <summary>
@@ -316,7 +325,7 @@ namespace YooAsset
public AssetInfo[] GetAssetInfos(string[] tags)
{
DebugCheckInitialize();
return _playModeImpl.ActiveManifest.GetAssetInfosByTags(tags);
return _fileSystemHost.ActiveManifest.GetAssetInfosByTags(tags);
}
/// <summary>
@@ -368,7 +377,7 @@ namespace YooAsset
public bool CheckLocationValid(string location)
{
DebugCheckInitialize();
string assetPath = _playModeImpl.ActiveManifest.TryMappingToAssetPath(location);
string assetPath = _fileSystemHost.ActiveManifest.TryMappingToAssetPath(location);
return string.IsNullOrEmpty(assetPath) == false;
}
@@ -380,11 +389,11 @@ namespace YooAsset
return false;
}
BundleInfo bundleInfo = _bundleQuery.GetMainBundleInfo(assetInfo);
BundleInfo bundleInfo = _fileSystemHost.GetMainBundleInfo(assetInfo);
if (bundleInfo.IsNeedDownloadFromRemote())
return true;
List<BundleInfo> depends = _bundleQuery.GetDependBundleInfos(assetInfo);
List<BundleInfo> depends = _fileSystemHost.GetDependBundleInfos(assetInfo);
foreach (var depend in depends)
{
if (depend.IsNeedDownloadFromRemote())
@@ -849,192 +858,55 @@ namespace YooAsset
#endregion
#region 资源下载
/// <summary>
/// 创建资源下载器,用于下载当前资源版本所有的资源包文件
/// </summary>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
return _playModeImpl.CreateResourceDownloaderByAll(downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源标签关联的资源包文件
/// </summary>
/// <param name="tag">资源标签</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
return _playModeImpl.CreateResourceDownloaderByTags(new string[] { tag }, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源标签列表关联的资源包文件
/// </summary>
/// <param name="tags">资源标签列表</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain)
public ResourceDownloaderOperation CreateResourceDownloader(ResourceDownloaderOptions options)
{
DebugCheckInitialize();
return _playModeImpl.CreateResourceDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain);
return _fileSystemHost.CreateResourceDownloader(options);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
/// 创建资源下载器,用于下载指定的资源信息列表依赖的资源包文件
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public ResourceDownloaderOperation CreateBundleDownloader(string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
public ResourceDownloaderOperation CreateBundleDownloader(BundleDownloaderOptions options)
{
DebugCheckInitialize();
var assetInfo = ConvertLocationToAssetInfo(location, null);
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
}
public ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain)
{
return CreateBundleDownloader(location, false, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
/// </summary>
/// <param name="locations">资源的定位地址列表</param>
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
foreach (var location in locations)
{
var assetInfo = ConvertLocationToAssetInfo(location, null);
assetInfos.Add(assetInfo);
}
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos.ToArray(), recursiveDownload, downloadingMaxNumber, failedTryAgain);
}
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain)
{
return CreateBundleDownloader(locations, false, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
/// </summary>
/// <param name="assetInfo">资源信息</param>
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
}
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain)
{
return CreateBundleDownloader(assetInfo, false, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
/// </summary>
/// <param name="assetInfos">资源信息列表</param>
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
}
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain)
{
return CreateBundleDownloader(assetInfos, false, downloadingMaxNumber, failedTryAgain);
return _fileSystemHost.CreateResourceDownloader(options);
}
#endregion
#region 资源解压
/// <summary>
/// 创建内置资源解压器,用于解压当前资源版本所有的资源包文件
/// </summary>
/// <param name="unpackingMaxNumber">同时解压的最大文件数</param>
/// <param name="failedTryAgain">解压失败的重试次数</param>
public ResourceUnpackerOperation CreateResourceUnpacker(int unpackingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
return _playModeImpl.CreateResourceUnpackerByAll(unpackingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建内置资源解压器,用于解压指定的资源标签关联的资源包文件
/// </summary>
/// <param name="tag">资源标签</param>
/// <param name="unpackingMaxNumber">同时解压的最大文件数</param>
/// <param name="failedTryAgain">解压失败的重试次数</param>
public ResourceUnpackerOperation CreateResourceUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
return _playModeImpl.CreateResourceUnpackerByTags(new string[] { tag }, unpackingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建内置资源解压器,用于解压指定的资源标签列表关联的资源包文件
/// </summary>
/// <param name="tags">资源标签列表</param>
/// <param name="unpackingMaxNumber">同时解压的最大文件数</param>
/// <param name="failedTryAgain">解压失败的重试次数</param>
public ResourceUnpackerOperation CreateResourceUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain)
public ResourceUnpackerOperation CreateResourceUnpacker(ResourceUnpackerOptions options)
{
DebugCheckInitialize();
return _playModeImpl.CreateResourceUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain);
return _fileSystemHost.CreateResourceUnpacker(options);
}
#endregion
#region 资源导入
/// <summary>
/// 创建资源导入器
/// 注意:资源文件名称必须和资源服务器部署的文件名称一致!
/// </summary>
/// <param name="filePaths">资源路径列表</param>
/// <param name="importerMaxNumber">同时导入的最大文件数</param>
/// <param name="failedTryAgain">导入失败的重试次数</param>
public ResourceImporterOperation CreateResourceImporter(string[] filePaths, int importerMaxNumber, int failedTryAgain)
public ResourceImporterOperation CreateResourceImporter(BundleImporterOptions options)
{
DebugCheckInitialize();
return _playModeImpl.CreateResourceImporterByFilePaths(filePaths, importerMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建资源导入器
/// 注意:资源信息里需要指定BundleName或BundleGUID!
/// </summary>
/// <param name="fileInfos">资源信息列表</param>
/// <param name="importerMaxNumber">同时导入的最大文件数</param>
/// <param name="failedTryAgain">导入失败的重试次数</param>
public ResourceImporterOperation CreateResourceImporter(ImportFileInfo[] fileInfos, int importerMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
return _playModeImpl.CreateResourceImporterByFileInfos(fileInfos, importerMaxNumber, failedTryAgain);
return _fileSystemHost.CreateResourceImporter(options);
}
#endregion
#region 内部方法
private AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType)
internal AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType)
{
return _playModeImpl.ActiveManifest.ConvertLocationToAssetInfo(location, assetType);
return _fileSystemHost.ActiveManifest.ConvertLocationToAssetInfo(location, assetType);
}
private AssetInfo ConvertAssetGUIDToAssetInfo(string assetGUID, System.Type assetType)
internal AssetInfo ConvertAssetGUIDToAssetInfo(string assetGUID, System.Type assetType)
{
return _playModeImpl.ActiveManifest.ConvertAssetGUIDToAssetInfo(assetGUID, assetType);
return _fileSystemHost.ActiveManifest.ConvertAssetGUIDToAssetInfo(assetGUID, assetType);
}
#endregion
@@ -1060,7 +932,7 @@ namespace YooAsset
if (checkActiveManifest)
{
if (_playModeImpl.ActiveManifest == null)
if (_fileSystemHost.ActiveManifest == null)
throw new YooPackageException(PackageName, "Can not found active package manifest !");
}
}