From 3e3661ad95284d7acfba1ea9408d6b072ffd64c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Fri, 16 Jan 2026 14:37:04 +0800 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=E9=87=8D=E6=9E=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runtime/ResourceManager/DownloadStatus.cs | 8 +- .../Operation/UnloadAllAssetsOptions.cs | 4 +- .../Operation/UnloadUnusedAssetsOptions.cs | 2 +- .../Runtime/ResourcePackage/FileSystemHost.cs | 149 +++++++++++------- .../Operation/ClearCacheFilesOptions.cs | 4 +- .../Operation/DownloaderDefine.cs | 106 +++++++++---- .../Operation/DownloaderOperation.cs | 103 +++++------- .../Operation/DownloaderOptions.cs | 26 +-- .../Operation/LoadPackageManifestOperation.cs | 2 +- .../Operation/LoadPackageManifestOptions.cs | 4 +- .../Operation/PreDownloadContentOperation.cs | 96 ++--------- .../Operation/PreDownloadContentOptions.cs | 4 +- .../Operation/RequestPackageVersionOptions.cs | 4 +- .../ResourcePackage/ResourcePackage.cs | 30 +--- Assets/YooAsset/Runtime/YooAssets.cs | 9 -- .../Runtime/CompatibleOldVersion.cs | 8 +- .../Runtime/EventDefine/PatchEventDefine.cs | 4 +- .../FsmNode/FsmDownloadPackageFiles.cs | 4 +- 18 files changed, 258 insertions(+), 309 deletions(-) diff --git a/Assets/YooAsset/Runtime/ResourceManager/DownloadStatus.cs b/Assets/YooAsset/Runtime/ResourceManager/DownloadStatus.cs index 038503c1..4443c838 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/DownloadStatus.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/DownloadStatus.cs @@ -6,22 +6,22 @@ namespace YooAsset /// /// 下载是否已经完成 /// - public bool IsDone; + public bool IsDone { get; set; } /// /// 下载进度(0-1f) /// - public float Progress; + public float Progress { get; set; } /// /// 下载文件的总大小 /// - public long TotalBytes; + public long TotalBytes { get; set; } /// /// 已经下载的文件大小 /// - public long DownloadedBytes; + public long DownloadedBytes { get; set; } public static DownloadStatus CreateDefaultStatus() { diff --git a/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadAllAssetsOptions.cs b/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadAllAssetsOptions.cs index 883428f8..23272d1b 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadAllAssetsOptions.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadAllAssetsOptions.cs @@ -6,12 +6,12 @@ namespace YooAsset /// /// 释放所有资源句柄,防止卸载过程中触发完成回调! /// - public bool ReleaseAllHandles { private set; get; } + public bool ReleaseAllHandles { set; get; } /// /// 卸载过程中锁定加载操作,防止新的任务请求! /// - public bool LockLoadOperation { private set; get; } + public bool LockLoadOperation { set; get; } public UnloadAllAssetsOptions(bool releaseAllHandles, bool lockLoadOperation) { diff --git a/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadUnusedAssetsOptions.cs b/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadUnusedAssetsOptions.cs index 0dec79a5..4e2839c3 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadUnusedAssetsOptions.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadUnusedAssetsOptions.cs @@ -6,7 +6,7 @@ namespace YooAsset /// /// 循环迭代次数 /// - public int LoopCount { private set; get; } + public int LoopCount { set; get; } public UnloadUnusedAssetsOptions(int loopCount) { diff --git a/Assets/YooAsset/Runtime/ResourcePackage/FileSystemHost.cs b/Assets/YooAsset/Runtime/ResourcePackage/FileSystemHost.cs index 767f548b..092512a5 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/FileSystemHost.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/FileSystemHost.cs @@ -12,7 +12,7 @@ namespace YooAsset /// /// 当前激活的清单 /// - public PackageManifest ActiveManifest { set; get; } + public PackageManifest ActiveManifest { private set; get; } public FileSystemHost(string packageName) @@ -65,6 +65,44 @@ namespace YooAsset FileSystems.Clear(); } + /// + /// 设置当前激活的资源清单 + /// + public void SetActiveManifest(PackageManifest manifest) + { + ActiveManifest = manifest; + } + + /// + /// 获取主文件系统 + /// 说明:文件系统列表里,最后一个属于主文件系统 + /// + public IFileSystem GetMainFileSystem() + { + int count = FileSystems.Count; + if (count == 0) + return null; + return FileSystems[count - 1]; + } + + /// + /// 获取资源包所属文件系统 + /// + private 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; + } + #region 资源包相关 private BundleInfo CreateBundleInfo(PackageBundle packageBundle) { @@ -80,10 +118,6 @@ namespace YooAsset throw new YooFileSystemException($"Can not found belong file system : {packageBundle.BundleName}"); } - - /// - /// 获取主资源包信息 - /// public BundleInfo GetMainBundleInfo(AssetInfo assetInfo) { if (assetInfo == null || assetInfo.IsInvalid) @@ -93,20 +127,12 @@ namespace YooAsset var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.Asset); return CreateBundleInfo(packageBundle); } - - /// - /// 获取主资源包名称 - /// public string GetMainBundleName(int bundleID) { // 注意:如果清单里未找到资源包会抛出异常! var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID); return packageBundle.BundleName; } - - /// - /// 获取依赖的资源包信息集合 - /// public List GetDependBundleInfos(AssetInfo assetInfo) { if (assetInfo == null || assetInfo.IsInvalid) @@ -135,47 +161,88 @@ namespace YooAsset #endregion #region 下载器相关 + public bool IsNeedDownloadFromRemoteInternal(AssetInfo assetInfo) + { + if (assetInfo.IsInvalid) + { + YooLogger.Warning(assetInfo.Error); + return false; + } + + BundleInfo bundleInfo = GetMainBundleInfo(assetInfo); + if (bundleInfo.IsNeedDownloadFromRemote()) + return true; + + List depends = GetDependBundleInfos(assetInfo); + foreach (var depend in depends) + { + if (depend.IsNeedDownloadFromRemote()) + return true; + } + + return false; + } + public ResourceDownloaderOperation CreateResourceDownloader(ResourceDownloaderOptions options) + { + return CreateResourceDownloader(ActiveManifest, options); + } + public ResourceDownloaderOperation CreateResourceDownloader(PackageManifest manifest, ResourceDownloaderOptions options) { List downloadList; if (options.Tags == null) - downloadList = GetDownloadListByAll(ActiveManifest); + downloadList = GetDownloadListByAll(manifest); else - downloadList = GetDownloadListByTags(ActiveManifest, options.Tags); + downloadList = GetDownloadListByTags(manifest, options.Tags); var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain); return operation; } + public ResourceDownloaderOperation CreateResourceDownloader(BundleDownloaderOptions options) + { + return CreateResourceDownloader(ActiveManifest, options); + } + public ResourceDownloaderOperation CreateResourceDownloader(PackageManifest manifest, BundleDownloaderOptions options) { List downloadList; if (options.AssetInfos == null) - downloadList = GetDownloadListByAll(ActiveManifest); + downloadList = GetDownloadListByAll(manifest); else - downloadList = GetDownloadListByAssetInfos(ActiveManifest, options.AssetInfos, options.DownloadBundleDependencies); + downloadList = GetDownloadListByAssetInfos(manifest, options.AssetInfos, options.DownloadBundleDependencies); var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain); return operation; } + public ResourceUnpackerOperation CreateResourceUnpacker(ResourceUnpackerOptions options) + { + return CreateResourceUnpacker(ActiveManifest, options); + } + public ResourceUnpackerOperation CreateResourceUnpacker(PackageManifest manifest, ResourceUnpackerOptions options) { List unpcakList; if (options.Tags == null) - unpcakList = GetUnpackListByAll(ActiveManifest); + unpcakList = GetUnpackListByAll(manifest); else - unpcakList = GetUnpackListByTags(ActiveManifest, options.Tags); + unpcakList = GetUnpackListByTags(manifest, options.Tags); var operation = new ResourceUnpackerOperation(PackageName, unpcakList, options.MaximumConcurrency, options.FailedTryAgain); return operation; } + public ResourceImporterOperation CreateResourceImporter(BundleImporterOptions options) { - List importerList = GetImporterListByBundleInfos(ActiveManifest, options.BundleInfos); + return CreateResourceImporter(ActiveManifest, options); + } + public ResourceImporterOperation CreateResourceImporter(PackageManifest manifest, BundleImporterOptions options) + { + List importerList = GetImporterListByBundleInfos(manifest, options.BundleInfos); var operation = new ResourceImporterOperation(PackageName, importerList, options.MaximumConcurrency, options.FailedTryAgain); return operation; } - internal List GetDownloadListByAll(PackageManifest manifest) + private List GetDownloadListByAll(PackageManifest manifest) { if (manifest == null) return new List(); @@ -195,7 +262,7 @@ namespace YooAsset } return result; } - internal List GetDownloadListByTags(PackageManifest manifest, string[] tags) + private List GetDownloadListByTags(PackageManifest manifest, string[] tags) { if (manifest == null) return new List(); @@ -228,7 +295,7 @@ namespace YooAsset } return result; } - internal List GetDownloadListByAssetInfos(PackageManifest manifest, AssetInfo[] assetInfos, bool recursiveDownload) + private List GetDownloadListByAssetInfos(PackageManifest manifest, AssetInfo[] assetInfos, bool recursiveDownload) { if (manifest == null) return new List(); @@ -303,7 +370,7 @@ namespace YooAsset } return result; } - internal List GetUnpackListByAll(PackageManifest manifest) + private List GetUnpackListByAll(PackageManifest manifest) { if (manifest == null) return new List(); @@ -323,7 +390,7 @@ namespace YooAsset } return result; } - internal List GetUnpackListByTags(PackageManifest manifest, string[] tags) + private List GetUnpackListByTags(PackageManifest manifest, string[] tags) { if (manifest == null) return new List(); @@ -346,7 +413,7 @@ namespace YooAsset } return result; } - internal List GetImporterListByBundleInfos(PackageManifest manifest, ImportBundleInfo[] fileInfos) + private List GetImporterListByBundleInfos(PackageManifest manifest, ImportBundleInfo[] fileInfos) { if (manifest == null) return new List(); @@ -401,35 +468,5 @@ namespace YooAsset return result; } #endregion - - /// - /// 获取主文件系统 - /// 说明:文件系统列表里,最后一个属于主文件系统 - /// - public IFileSystem GetMainFileSystem() - { - int count = FileSystems.Count; - if (count == 0) - return null; - return FileSystems[count - 1]; - } - - /// - /// 获取资源包所属文件系统 - /// - 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; - } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/ClearCacheFilesOptions.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/ClearCacheFilesOptions.cs index 4b49ccad..6fae85f2 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/ClearCacheFilesOptions.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/ClearCacheFilesOptions.cs @@ -6,12 +6,12 @@ namespace YooAsset /// /// 清理模式 /// - public string ClearMode { private set; get; } + public string ClearMode { set; get; } /// /// 附加参数 /// - public object ClearParam { private set; get; } + public object ClearParam { set; get; } /// /// 资源清单 diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderDefine.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderDefine.cs index 017575ce..b040b785 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderDefine.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderDefine.cs @@ -2,101 +2,153 @@ namespace YooAsset { /// - /// 下载器结束 + /// 下载完成事件参数 /// - public struct DownloaderFinishData + public struct DownloadFinishedEventArgs { /// /// 所属包裹名称 /// - public string PackageName; + public string PackageName { get; set; } /// /// 是否成功 /// - public bool Succeed; + public bool IsSuccess { get; set; } + + /// + /// 如果下载失败,获取的错误信息。 + /// + public string ErrorInfo { get; set; } + + /// + /// 创建表示成功下载的事件参数 + /// + internal static DownloadFinishedEventArgs CreateSuccess(string packageName) + { + var args = new DownloadFinishedEventArgs(); + args.PackageName = packageName; + args.IsSuccess = true; + args.ErrorInfo = null; + return args; + } + + /// + /// 创建表示失败下载的事件参数 + /// + internal static DownloadFinishedEventArgs CreateFailure(string packageName, string errorInfo) + { + var args = new DownloadFinishedEventArgs(); + args.PackageName = packageName; + args.IsSuccess = false; + args.ErrorInfo = errorInfo; + return args; + } } /// - /// 下载器相关的更新数据 + /// 下载完成事件委托 /// - public struct DownloadUpdateData + public delegate void DownloadFinishedEventHandler(DownloadFinishedEventArgs args); + + + /// + /// 下载进度更新事件参数 + /// + public struct DownloadProgressChangedEventArgs { /// /// 所属包裹名称 /// - public string PackageName; + public string PackageName { get; set; } /// /// 下载进度 (0-1f) /// - public float Progress; + public float Progress { get; set; } /// /// 下载文件总数 /// - public int TotalDownloadCount; - - /// - /// 当前完成的下载文件数量 - /// - public int CurrentDownloadCount; + public int TotalDownloadCount { get; set; } /// /// 下载数据总大小(单位:字节) /// - public long TotalDownloadBytes; + public long TotalDownloadBytes { get; set; } + + /// + /// 当前完成的下载文件数量 + /// + public int CurrentDownloadCount { get; set; } /// /// 当前完成的下载数据大小(单位:字节) /// - public long CurrentDownloadBytes; + public long CurrentDownloadBytes { get; set; } } /// - /// 下载器相关的错误数据 + /// 下载进度更新事件委托 /// - public struct DownloadErrorData + public delegate void DownloadProgressChangedEventHandler(DownloadProgressChangedEventArgs args); + + + /// + /// 下载错误事件参数 + /// + public struct DownloadErrorEventArgs { /// /// 所属包裹名称 /// - public string PackageName; + public string PackageName { get; set; } /// /// 下载失败的文件名称 /// - public string FileName; + public string FileName { get; set; } /// /// 错误信息 /// - public string ErrorInfo; + public string ErrorInfo { get; set; } } /// - /// 下载器相关的文件数据 + /// 下载错误事件委托 /// - public struct DownloadFileData + public delegate void DownloadErrorEventHandler(DownloadErrorEventArgs args); + + + /// + /// 开始下载单个文件事件参数 + /// + public struct DownloadFileStartedEventArgs { /// /// 所属包裹名称 /// - public string PackageName; + public string PackageName { get; set; } /// /// 资源包名称 /// - public string BundleName; + public string BundleName { get; set; } /// /// 文件名称 /// - public string FileName; + public string FileName { get; set; } /// /// 文件大小 /// - public long FileSize; + public long FileSize { get; set; } } + + /// + /// 开始下载单个文件事件委托 + /// + public delegate void DownloadFileStartedEventHandler(DownloadFileStartedEventArgs args); } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs index 872a75cc..6ef7d454 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs @@ -15,29 +15,6 @@ namespace YooAsset } private const int MAX_LOADER_COUNT = 64; - - #region 委托定义 - /// - /// 下载器结束 - /// - public delegate void DownloaderFinish(DownloaderFinishData data); - - /// - /// 下载进度更新 - /// - public delegate void DownloadUpdate(DownloadUpdateData data); - - /// - /// 下载发生错误 - /// - public delegate void DownloadError(DownloadErrorData data); - - /// - /// 开始下载某个文件 - /// - public delegate void DownloadFileBegin(DownloadFileData data); - #endregion - private readonly string _packageName; private readonly int _maximumConcurrency; private readonly int _failedTryAgain; @@ -82,24 +59,24 @@ namespace YooAsset } /// - /// 当下载器结束(无论成功或失败) + /// 下载完成事件委托(无论成功或失败) /// - public DownloaderFinish DownloadFinishCallback { set; get; } + public DownloadFinishedEventHandler DownloadFinishedHandler { set; get; } /// - /// 当下载进度发生变化 + /// 下载进度更新事件委托 /// - public DownloadUpdate DownloadUpdateCallback { set; get; } + public DownloadProgressChangedEventHandler DownloadProgressChangedHandler { set; get; } /// - /// 当下载器发生错误 + /// 下载错误事件委托 /// - public DownloadError DownloadErrorCallback { set; get; } + public DownloadErrorEventHandler DownloadErrorHandler { set; get; } /// - /// 当开始下载某个文件 + /// 开始下载单个文件事件委托 /// - public DownloadFileBegin DownloadFileBeginCallback { set; get; } + public DownloadFileStartedEventHandler DownloadFileStartedHandler { set; get; } internal DownloaderOperation(string packageName, List downloadList, int maximumConcurrency, int failedTryAgain) @@ -130,12 +107,10 @@ namespace YooAsset Status = EOperationStatus.Failed; Error = "Download bundle list is null."; - if (DownloadFinishCallback != null) + if (DownloadFinishedHandler != null) { - var data = new DownloaderFinishData(); - data.PackageName = _packageName; - data.Succeed = false; - DownloadFinishCallback.Invoke(data); + var args = DownloadFinishedEventArgs.CreateFailure(_packageName, Error); + DownloadFinishedHandler.Invoke(args); } } else if (_bundleInfoList.Count == 0) @@ -144,12 +119,10 @@ namespace YooAsset Status = EOperationStatus.Succeed; Progress = 1f; - if (DownloadFinishCallback != null) + if (DownloadFinishedHandler != null) { - var data = new DownloaderFinishData(); - data.PackageName = _packageName; - data.Succeed = true; - DownloadFinishCallback.Invoke(data); + var args = DownloadFinishedEventArgs.CreateSuccess(_packageName); + DownloadFinishedHandler.Invoke(args); } } else @@ -200,16 +173,16 @@ namespace YooAsset else Progress = (float)_lastDownloadBytes / TotalDownloadBytes; - if (DownloadUpdateCallback != null) + if (DownloadProgressChangedHandler != null) { - var data = new DownloadUpdateData(); + var data = new DownloadProgressChangedEventArgs(); data.PackageName = _packageName; data.Progress = Progress; data.TotalDownloadCount = TotalDownloadCount; - data.CurrentDownloadCount = _lastDownloadCount; data.TotalDownloadBytes = TotalDownloadBytes; + data.CurrentDownloadCount = _lastDownloadCount; data.CurrentDownloadBytes = _lastDownloadBytes; - DownloadUpdateCallback.Invoke(data); + DownloadProgressChangedHandler.Invoke(data); } } @@ -231,14 +204,14 @@ namespace YooAsset _downloaders.Add(downloader); _bundleInfoList.RemoveAt(index); - if (DownloadFileBeginCallback != null) + if (DownloadFileStartedHandler != null) { - var data = new DownloadFileData(); + var data = new DownloadFileStartedEventArgs(); data.PackageName = _packageName; data.BundleName = bundleInfo.Bundle.BundleName; data.FileName = bundleInfo.Bundle.FileName; data.FileSize = bundleInfo.Bundle.FileSize; - DownloadFileBeginCallback.Invoke(data); + DownloadFileStartedHandler.Invoke(data); } } } @@ -260,21 +233,19 @@ namespace YooAsset Status = EOperationStatus.Failed; Error = $"Failed to download file : {bundleName}"; - if (DownloadErrorCallback != null) + if (DownloadErrorHandler != null) { - var data = new DownloadErrorData(); + var data = new DownloadErrorEventArgs(); data.PackageName = _packageName; data.FileName = bundleName; data.ErrorInfo = failedDownloader.Error; - DownloadErrorCallback.Invoke(data); + DownloadErrorHandler.Invoke(data); } - if (DownloadFinishCallback != null) + if (DownloadFinishedHandler != null) { - var data = new DownloaderFinishData(); - data.PackageName = _packageName; - data.Succeed = false; - DownloadFinishCallback.Invoke(data); + var args = DownloadFinishedEventArgs.CreateFailure(_packageName, failedDownloader.Error); + DownloadFinishedHandler.Invoke(args); } } else @@ -283,12 +254,10 @@ namespace YooAsset _steps = ESteps.Done; Status = EOperationStatus.Succeed; - if (DownloadFinishCallback != null) + if (DownloadFinishedHandler != null) { - var data = new DownloaderFinishData(); - data.PackageName = _packageName; - data.Succeed = true; - DownloadFinishCallback.Invoke(data); + var args = DownloadFinishedEventArgs.CreateSuccess(_packageName); + DownloadFinishedHandler.Invoke(args); } } } @@ -409,10 +378,10 @@ namespace YooAsset /// /// 创建空的下载器 /// - internal static ResourceDownloaderOperation CreateEmptyDownloader(string packageName, int maximumConcurrency, int failedTryAgain) + internal static ResourceDownloaderOperation CreateEmptyDownloader(string packageName) { List downloadList = new List(); - var operation = new ResourceDownloaderOperation(packageName, downloadList, maximumConcurrency, failedTryAgain); + var operation = new ResourceDownloaderOperation(packageName, downloadList, 1, 1); return operation; } } @@ -426,10 +395,10 @@ namespace YooAsset /// /// 创建空的解压器 /// - internal static ResourceUnpackerOperation CreateEmptyUnpacker(string packageName, int upackingMaxNumber, int failedTryAgain) + internal static ResourceUnpackerOperation CreateEmptyUnpacker(string packageName) { List downloadList = new List(); - var operation = new ResourceUnpackerOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain); + var operation = new ResourceUnpackerOperation(packageName, downloadList, 1, 1); return operation; } } @@ -443,10 +412,10 @@ namespace YooAsset /// /// 创建空的导入器 /// - internal static ResourceImporterOperation CreateEmptyImporter(string packageName, int upackingMaxNumber, int failedTryAgain) + internal static ResourceImporterOperation CreateEmptyImporter(string packageName) { List downloadList = new List(); - var operation = new ResourceImporterOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain); + var operation = new ResourceImporterOperation(packageName, downloadList, 1, 1); return operation; } } diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOptions.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOptions.cs index 52f56cf2..f479eab8 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOptions.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOptions.cs @@ -9,23 +9,23 @@ namespace YooAsset /// /// 最大并发数量 /// - public int MaximumConcurrency { private set; get; } + public int MaximumConcurrency { set; get; } /// /// 失败后的重试次数 /// - public int FailedTryAgain { private set; get; } + public int FailedTryAgain { set; get; } /// /// 下载资源对象所属资源包内所有资源对象依赖的资源包 /// - public bool DownloadBundleDependencies { private set; get; } + public bool DownloadBundleDependencies { set; get; } /// /// 资源信息列表 /// 说明:如果列表为NULL,则下载所有资产 /// - public AssetInfo[] AssetInfos { private set; get; } + public AssetInfo[] AssetInfos { set; get; } public BundleDownloaderOptions(AssetInfo assetInfo, bool downloadDependencies, int maximumConcurrency, int failedTryAgain) { @@ -51,18 +51,18 @@ namespace YooAsset /// /// 最大并发数量 /// - public int MaximumConcurrency { private set; get; } + public int MaximumConcurrency { set; get; } /// /// 失败后的重试次数 /// - public int FailedTryAgain { private set; get; } + public int FailedTryAgain { set; get; } /// /// 资源标签列表 /// 说明:如果列表为NULL,则下载所有资产 /// - public string[] Tags { private set; get; } + public string[] Tags { set; get; } public ResourceDownloaderOptions(int maximumConcurrency, int failedTryAgain) { @@ -92,18 +92,18 @@ namespace YooAsset /// /// 最大并发数量 /// - public int MaximumConcurrency { private set; get; } + public int MaximumConcurrency { set; get; } /// /// 失败后的重试次数 /// - public int FailedTryAgain { private set; get; } + public int FailedTryAgain { set; get; } /// /// 资源标签列表 /// 说明:如果列表为NULL,则解压所有资产 /// - public string[] Tags { private set; get; } + public string[] Tags { set; get; } public ResourceUnpackerOptions(int maximumConcurrency, int failedTryAgain) { @@ -133,17 +133,17 @@ namespace YooAsset /// /// 最大并发数量 /// - public int MaximumConcurrency { private set; get; } + public int MaximumConcurrency { set; get; } /// /// 失败后的重试次数 /// - public int FailedTryAgain { private set; get; } + public int FailedTryAgain { set; get; } /// /// 资源包信息列表 /// - public ImportBundleInfo[] BundleInfos { private set; get; } + public ImportBundleInfo[] BundleInfos { set; get; } public BundleImporterOptions(ImportBundleInfo[] bundleInfos, int maximumConcurrency, int failedTryAgain) { diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/LoadPackageManifestOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/LoadPackageManifestOperation.cs index 6394dfb5..833db07f 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/LoadPackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/LoadPackageManifestOperation.cs @@ -76,7 +76,7 @@ namespace YooAsset if (_loadPackageManifestOp.Status == EOperationStatus.Succeed) { _steps = ESteps.Done; - _host.ActiveManifest = _loadPackageManifestOp.Manifest; + _host.SetActiveManifest(_loadPackageManifestOp.Manifest); Status = EOperationStatus.Succeed; } else diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/LoadPackageManifestOptions.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/LoadPackageManifestOptions.cs index 358ce23f..619980b2 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/LoadPackageManifestOptions.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/LoadPackageManifestOptions.cs @@ -6,12 +6,12 @@ namespace YooAsset /// /// 包裹版本 /// - public string PackageVersion { private set; get; } + public string PackageVersion { set; get; } /// /// 超时时间 /// - public int Timeout { private set; get; } + public int Timeout { set; get; } public LoadPackageManifestOptions(string packageVersion, int timeout) { diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/PreDownloadContentOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/PreDownloadContentOperation.cs index ca661e77..02dc1f02 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/PreDownloadContentOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/PreDownloadContentOperation.cs @@ -17,7 +17,6 @@ namespace YooAsset private readonly FileSystemHost _host; private readonly PreDownloadContentOptions _options; - private readonly int _timeout; private FSLoadPackageManifestOperation _loadPackageManifestOp; private PackageManifest _manifest; private ESteps _steps = ESteps.None; @@ -96,109 +95,32 @@ namespace YooAsset } } - /// - /// 创建资源下载器,用于下载当前资源版本所有的资源包文件 - /// - /// 同时下载的最大文件数 - /// 下载失败的重试次数 - public ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain) - { - if (Status != EOperationStatus.Succeed) - { - YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); - return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain); - } - - List downloadList = _host.GetDownloadListByAll(_manifest); - var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain); - return operation; - } - - /// - /// 创建资源下载器,用于下载指定的资源标签关联的资源包文件 - /// - /// 资源标签 - /// 同时下载的最大文件数 - /// 下载失败的重试次数 - public ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain) - { - if (Status != EOperationStatus.Succeed) - { - YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); - return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain); - } - - List downloadList = _host.GetDownloadListByTags(_manifest, new string[] { tag }); - var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain); - return operation; - } - /// /// 创建资源下载器,用于下载指定的资源标签列表关联的资源包文件 /// - /// 资源标签列表 - /// 同时下载的最大文件数 - /// 下载失败的重试次数 - public ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain) + public ResourceDownloaderOperation CreateResourceDownloader(ResourceDownloaderOptions options) { if (Status != EOperationStatus.Succeed) { - YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); - return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain); + YooLogger.Error($"{nameof(PreDownloadContentOperation)} status is not succeed !"); + return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName); } - List downloadList = _host.GetDownloadListByTags(_manifest, tags); - var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain); - return operation; + return _host.CreateResourceDownloader(_manifest, options); } /// - /// 创建资源下载器,用于下载指定的资源依赖的资源包文件 + /// 创建资源下载器,用于下载指定的资源信息列表依赖的资源包文件 /// - /// 资源定位地址 - /// 同时下载的最大文件数 - /// 下载失败的重试次数 - public ResourceDownloaderOperation CreateBundleDownloader(string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain) + public ResourceDownloaderOperation CreateBundleDownloader(BundleDownloaderOptions options) { if (Status != EOperationStatus.Succeed) { - YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); - return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain); + YooLogger.Error($"{nameof(PreDownloadContentOperation)} status is not succeed !"); + return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName); } - List assetInfos = new List(); - var assetInfo = _manifest.ConvertLocationToAssetInfo(location, null); - assetInfos.Add(assetInfo); - - List downloadList = _host.GetDownloadListByAssetInfos(_manifest, assetInfos.ToArray(), recursiveDownload); - var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain); - return operation; - } - - /// - /// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件 - /// - /// 资源定位地址列表 - /// 同时下载的最大文件数 - /// 下载失败的重试次数 - public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain) - { - if (Status != EOperationStatus.Succeed) - { - YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); - return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain); - } - - List assetInfos = new List(locations.Length); - foreach (var location in locations) - { - var assetInfo = _manifest.ConvertLocationToAssetInfo(location, null); - assetInfos.Add(assetInfo); - } - - List downloadList = _host.GetDownloadListByAssetInfos(_manifest, assetInfos.ToArray(), recursiveDownload); - var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain); - return operation; + return _host.CreateResourceDownloader(_manifest, options); } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/PreDownloadContentOptions.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/PreDownloadContentOptions.cs index 62308d58..08531349 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/PreDownloadContentOptions.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/PreDownloadContentOptions.cs @@ -6,12 +6,12 @@ namespace YooAsset /// /// 预下载的包裹版本 /// - public string PackageVersion { private set; get; } + public string PackageVersion { set; get; } /// /// 资源清单请求超时时间 /// - public int Timeout { private set; get; } + public int Timeout { set; get; } public PreDownloadContentOptions(string packageVersion, int timeout) { diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/RequestPackageVersionOptions.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/RequestPackageVersionOptions.cs index 20a4b857..1c0b4281 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/RequestPackageVersionOptions.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/RequestPackageVersionOptions.cs @@ -6,12 +6,12 @@ namespace YooAsset /// /// 在URL末尾添加时间戳 /// - public bool AppendTimeTicks { private set; get; } + public bool AppendTimeTicks { set; get; } /// /// 超时时间 /// - public int Timeout { private set; get; } + public int Timeout { set; get; } public RequestPackageVersionOptions(bool appendTimeTicks, int timeout) { diff --git a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs index 245bcd29..b2a75907 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs @@ -285,7 +285,7 @@ namespace YooAsset { DebugCheckInitialize(); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); - return IsNeedDownloadFromRemoteInternal(assetInfo); + return _fileSystemHost.IsNeedDownloadFromRemoteInternal(assetInfo); } /// @@ -295,7 +295,7 @@ namespace YooAsset public bool IsNeedDownloadFromRemote(AssetInfo assetInfo) { DebugCheckInitialize(); - return IsNeedDownloadFromRemoteInternal(assetInfo); + return _fileSystemHost.IsNeedDownloadFromRemoteInternal(assetInfo); } /// @@ -380,28 +380,6 @@ namespace YooAsset string assetPath = _fileSystemHost.ActiveManifest.TryMappingToAssetPath(location); return string.IsNullOrEmpty(assetPath) == false; } - - private bool IsNeedDownloadFromRemoteInternal(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - { - YooLogger.Warning(assetInfo.Error); - return false; - } - - BundleInfo bundleInfo = _fileSystemHost.GetMainBundleInfo(assetInfo); - if (bundleInfo.IsNeedDownloadFromRemote()) - return true; - - List depends = _fileSystemHost.GetDependBundleInfos(assetInfo); - foreach (var depend in depends) - { - if (depend.IsNeedDownloadFromRemote()) - return true; - } - - return false; - } #endregion #region 原生文件 @@ -866,11 +844,11 @@ namespace YooAsset DebugCheckInitialize(); return _fileSystemHost.CreateResourceDownloader(options); } - + /// /// 创建资源下载器,用于下载指定的资源信息列表依赖的资源包文件 /// - public ResourceDownloaderOperation CreateBundleDownloader(BundleDownloaderOptions options) + public ResourceDownloaderOperation CreateResourceDownloader(BundleDownloaderOptions options) { DebugCheckInitialize(); return _fileSystemHost.CreateResourceDownloader(options); diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index 2d2754c5..490af73a 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -233,15 +233,6 @@ namespace YooAsset } #region 系统参数 - /// - /// 设置下载系统参数,自定义下载请求 - /// - [Obsolete("This method is deprecated. Please use FileSystemParametersDefine.UNITY_WEB_REQUEST_CREATOR instead.", true)] - public static void SetDownloadSystemUnityWebRequest(UnityWebRequestCreator createDelegate) - { - throw new NotImplementedException(); - } - /// /// 设置异步系统参数,每帧执行消耗的最大时间切片(单位:毫秒) /// diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/CompatibleOldVersion.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/CompatibleOldVersion.cs index de83e243..efbeefa1 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/CompatibleOldVersion.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/CompatibleOldVersion.cs @@ -337,7 +337,7 @@ public static class CompatibleResourcePackage { var assetInfo = package.ConvertLocationToAssetInfo(location, null); var options = new BundleDownloaderOptions(assetInfo, recursiveDownload, downloadingMaxNumber, failedTryAgain); - return package.CreateBundleDownloader(options); + return package.CreateResourceDownloader(options); } public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string location, int downloadingMaxNumber, int failedTryAgain) { @@ -357,7 +357,7 @@ public static class CompatibleResourcePackage } var options = new BundleDownloaderOptions(assetInfos.ToArray(), recursiveDownload, downloadingMaxNumber, failedTryAgain); - return package.CreateBundleDownloader(options); + return package.CreateResourceDownloader(options); } public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string[] locations, int downloadingMaxNumber, int failedTryAgain) { @@ -371,7 +371,7 @@ public static class CompatibleResourcePackage { AssetInfo[] assetInfos = new AssetInfo[] { assetInfo }; var options = new BundleDownloaderOptions(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain); - return package.CreateBundleDownloader(options); + return package.CreateResourceDownloader(options); } public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain) { @@ -384,7 +384,7 @@ public static class CompatibleResourcePackage public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain) { var options = new BundleDownloaderOptions(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain); - return package.CreateBundleDownloader(options); + return package.CreateResourceDownloader(options); } public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain) { diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/EventDefine/PatchEventDefine.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/EventDefine/PatchEventDefine.cs index e2c1cfb5..cdbb4dbd 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/EventDefine/PatchEventDefine.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/EventDefine/PatchEventDefine.cs @@ -57,7 +57,7 @@ public class PatchEventDefine public long TotalDownloadSizeBytes; public long CurrentDownloadSizeBytes; - public static void SendEventMessage(DownloadUpdateData updateData) + public static void SendEventMessage(DownloadProgressChangedEventArgs updateData) { var msg = new DownloadUpdate(); msg.TotalDownloadCount = updateData.TotalDownloadCount; @@ -100,7 +100,7 @@ public class PatchEventDefine public string FileName; public string Error; - public static void SendEventMessage(DownloadErrorData errorData) + public static void SendEventMessage(DownloadErrorEventArgs errorData) { var msg = new WebFileDownloadFailed(); msg.FileName = errorData.FileName; diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmDownloadPackageFiles.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmDownloadPackageFiles.cs index ea5d6bd8..efe21631 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmDownloadPackageFiles.cs +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/PatchLogic/FsmNode/FsmDownloadPackageFiles.cs @@ -26,8 +26,8 @@ public class FsmDownloadPackageFiles : IStateNode private IEnumerator BeginDownload() { var downloader = (ResourceDownloaderOperation)_machine.GetBlackboardValue("Downloader"); - downloader.DownloadErrorCallback = PatchEventDefine.WebFileDownloadFailed.SendEventMessage; - downloader.DownloadUpdateCallback = PatchEventDefine.DownloadUpdate.SendEventMessage; + downloader.DownloadErrorHandler = PatchEventDefine.WebFileDownloadFailed.SendEventMessage; + downloader.DownloadProgressChangedHandler = PatchEventDefine.DownloadUpdate.SendEventMessage; downloader.BeginDownload(); yield return downloader;