From 522ddb5115ede9d97fb3bfc7f2e6e69dcf4fc7a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Thu, 27 Feb 2025 16:31:56 +0800 Subject: [PATCH] update resource package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加CustomPlayMode运行模式 --- .../YooAsset/Runtime/InitializeParameters.cs | 20 +- .../ResourceManager/ResourceManager.cs | 2 +- .../ResourcePackage/Interface/IBundleQuery.cs | 5 - .../Operation/ClearCacheFilesOperation.cs | 156 +++--- .../Operation/InitializationOperation.cs | 455 +++--------------- .../Operation/PreDownloadContentOperation.cs | 229 ++------- .../RequestPackageVersionOperation.cs | 12 +- .../UpdatePackageManifestOperation.cs | 20 +- .../PlayMode/EditorSimulateModeImpl.cs | 173 ------- .../PlayMode/EditorSimulateModeImpl.cs.meta | 11 - .../PlayMode/HostPlayModeImpl.cs | 181 ------- .../PlayMode/HostPlayModeImpl.cs.meta | 11 - .../PlayMode/OfflinePlayModeImpl.cs | 173 ------- .../PlayMode/PlayModeHelper.cs | 276 ----------- .../PlayMode/PlayModeHelper.cs.meta | 11 - .../ResourcePackage/PlayMode/PlayModeImpl.cs | 440 +++++++++++++++++ ...yModeImpl.cs.meta => PlayModeImpl.cs.meta} | 2 +- .../PlayMode/WebPlayModeImpl.cs | 201 -------- .../PlayMode/WebPlayModeImpl.cs.meta | 11 - .../ResourcePackage/ResourcePackage.cs | 45 +- 20 files changed, 666 insertions(+), 1768 deletions(-) delete mode 100644 Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs delete mode 100644 Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs.meta delete mode 100644 Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs delete mode 100644 Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs.meta delete mode 100644 Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs delete mode 100644 Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeHelper.cs delete mode 100644 Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeHelper.cs.meta create mode 100644 Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeImpl.cs rename Assets/YooAsset/Runtime/ResourcePackage/PlayMode/{OfflinePlayModeImpl.cs.meta => PlayModeImpl.cs.meta} (83%) delete mode 100644 Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs delete mode 100644 Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs.meta diff --git a/Assets/YooAsset/Runtime/InitializeParameters.cs b/Assets/YooAsset/Runtime/InitializeParameters.cs index 152e2523..bc36c30e 100644 --- a/Assets/YooAsset/Runtime/InitializeParameters.cs +++ b/Assets/YooAsset/Runtime/InitializeParameters.cs @@ -1,4 +1,5 @@ - +using System.Collections.Generic; + namespace YooAsset { /// @@ -25,6 +26,11 @@ namespace YooAsset /// WebGL运行模式 /// WebPlayMode, + + /// + /// 自定义运行模式 + /// + CustomPlayMode, } /// @@ -67,4 +73,16 @@ namespace YooAsset public FileSystemParameters WebServerFileSystemParameters; public FileSystemParameters WebRemoteFileSystemParameters; } + + /// + /// 自定义运行模式的初始化参数 + /// + public class CustomPlayModeParameters : InitializeParameters + { + /// + /// 文件系统初始化参数列表 + /// 注意:列表最后一个元素作为主文件系统! + /// + public List FileSystemParameterList; + } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs b/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs index 8958ec75..129b2e59 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs @@ -34,7 +34,7 @@ namespace YooAsset /// /// 初始化 /// - public void Initialize(InitializeParameters initializeParameters, IBundleQuery bundleServices) + public void Initialize(IBundleQuery bundleServices) { _bundleQuery = bundleServices; SceneManager.sceneUnloaded += OnSceneUnloaded; diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Interface/IBundleQuery.cs b/Assets/YooAsset/Runtime/ResourcePackage/Interface/IBundleQuery.cs index d0cb7013..1261d7ae 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Interface/IBundleQuery.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Interface/IBundleQuery.cs @@ -27,10 +27,5 @@ namespace YooAsset /// 获取依赖的资源包名称集合 /// string[] GetDependBundleNames(AssetInfo assetInfo); - - /// - /// 清单是否有效 - /// - bool ManifestValid(); } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/ClearCacheFilesOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/ClearCacheFilesOperation.cs index 4b38c24b..c3de967b 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/ClearCacheFilesOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/ClearCacheFilesOperation.cs @@ -1,144 +1,102 @@ - +using System.Collections.Generic; +using System.Linq; + namespace YooAsset { - public abstract class ClearCacheFilesOperation : AsyncOperationBase - { - } - internal sealed class ClearCacheFilesImplOperation : ClearCacheFilesOperation + public sealed class ClearCacheFilesOperation : AsyncOperationBase { private enum ESteps { None, - ClearFileSystemA, - ClearFileSystemB, - ClearFileSystemC, + Prepare, + ClearCacheFiles, + CheckClearResult, Done, } - private readonly IPlayMode _impl; - private readonly IFileSystem _fileSystemA; - private readonly IFileSystem _fileSystemB; - private readonly IFileSystem _fileSystemC; + private readonly PlayModeImpl _impl; private readonly string _clearMode; private readonly object _clearParam; - private FSClearCacheFilesOperation _clearCacheFilesOpA; - private FSClearCacheFilesOperation _clearCacheFilesOpB; - private FSClearCacheFilesOperation _clearCacheFilesOpC; + private List _cloneList; + private FSClearCacheFilesOperation _clearCacheFilesOp; private ESteps _steps = ESteps.None; - internal ClearCacheFilesImplOperation(IPlayMode impl, IFileSystem fileSystemA, IFileSystem fileSystemB, IFileSystem fileSystemC, string clearMode, object clearParam) + internal ClearCacheFilesOperation(PlayModeImpl impl, string clearMode, object clearParam) { _impl = impl; - _fileSystemA = fileSystemA; - _fileSystemB = fileSystemB; - _fileSystemC = fileSystemC; _clearMode = clearMode; _clearParam = clearParam; } internal override void InternalStart() { - _steps = ESteps.ClearFileSystemA; + _steps = ESteps.Prepare; } internal override void InternalUpdate() { if (_steps == ESteps.None || _steps == ESteps.Done) return; - if (_steps == ESteps.ClearFileSystemA) + if (_steps == ESteps.Prepare) { - if (_fileSystemA == null) - { - _steps = ESteps.ClearFileSystemB; - return; - } - - if (_clearCacheFilesOpA == null) - { - _clearCacheFilesOpA = _fileSystemA.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam); - _clearCacheFilesOpA.StartOperation(); - AddChildOperation(_clearCacheFilesOpA); - } - - _clearCacheFilesOpA.UpdateOperation(); - Progress = _clearCacheFilesOpA.Progress; - if (_clearCacheFilesOpA.IsDone == false) - return; - - if (_clearCacheFilesOpA.Status == EOperationStatus.Succeed) - { - _steps = ESteps.ClearFileSystemB; - } - else + var fileSytems = _impl.FileSystems; + if (fileSytems == null || fileSytems.Count == 0) { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = _clearCacheFilesOpA.Error; + Error = "The file system is empty !"; + return; } + + foreach (var fileSystem in fileSytems) + { + if (fileSystem == null) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = "An empty object exists in the list!"; + return; + } + } + + _cloneList = fileSytems.ToList(); + _steps = ESteps.ClearCacheFiles; } - if (_steps == ESteps.ClearFileSystemB) + if (_steps == ESteps.ClearCacheFiles) { - if (_fileSystemB == null) - { - _steps = ESteps.ClearFileSystemC; - return; - } - - if (_clearCacheFilesOpB == null) - { - _clearCacheFilesOpB = _fileSystemB.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam); - _clearCacheFilesOpB.StartOperation(); - AddChildOperation(_clearCacheFilesOpB); - } - - _clearCacheFilesOpB.UpdateOperation(); - Progress = _clearCacheFilesOpB.Progress; - if (_clearCacheFilesOpB.IsDone == false) - return; - - if (_clearCacheFilesOpB.Status == EOperationStatus.Succeed) - { - _steps = ESteps.ClearFileSystemC; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = _clearCacheFilesOpB.Error; - } - } - - if (_steps == ESteps.ClearFileSystemC) - { - if (_fileSystemC == null) - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeed; - return; - } - - if (_clearCacheFilesOpC == null) - { - _clearCacheFilesOpC = _fileSystemC.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam); - _clearCacheFilesOpC.StartOperation(); - AddChildOperation(_clearCacheFilesOpC); - } - - _clearCacheFilesOpC.UpdateOperation(); - Progress = _clearCacheFilesOpC.Progress; - if (_clearCacheFilesOpC.IsDone == false) - return; - - if (_clearCacheFilesOpC.Status == EOperationStatus.Succeed) + if (_cloneList.Count == 0) { _steps = ESteps.Done; Status = EOperationStatus.Succeed; } else + { + var fileSystem = _cloneList[0]; + _cloneList.RemoveAt(0); + + _clearCacheFilesOp = fileSystem.ClearCacheFilesAsync(_impl.ActiveManifest, _clearMode, _clearParam); + _clearCacheFilesOp.StartOperation(); + AddChildOperation(_clearCacheFilesOp); + _steps = ESteps.CheckClearResult; + } + } + + if (_steps == ESteps.CheckClearResult) + { + _clearCacheFilesOp.UpdateOperation(); + Progress = _clearCacheFilesOp.Progress; + if (_clearCacheFilesOp.IsDone == false) + return; + + if (_clearCacheFilesOp.Status == EOperationStatus.Succeed) + { + _steps = ESteps.ClearCacheFiles; + } + else { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = _clearCacheFilesOpC.Error; + Error = _clearCacheFilesOp.Error; } } } diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/InitializationOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/InitializationOperation.cs index 3803716a..29437bd8 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/InitializationOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/InitializationOperation.cs @@ -1,73 +1,108 @@ - +using System.Collections.Generic; +using System.Linq; + namespace YooAsset { - /// - /// 初始化操作 - /// - public abstract class InitializationOperation : AsyncOperationBase - { - } - - /// - /// 编辑器下模拟模式 - /// - internal sealed class EditorSimulateModeInitializationOperation : InitializationOperation + public class InitializationOperation : AsyncOperationBase { private enum ESteps { None, - CreateFileSystem, + Prepare, + ClearOldFileSystem, InitFileSystem, + CheckInitResult, Done, } - private readonly EditorSimulateModeImpl _impl; - private readonly EditorSimulateModeParameters _parameters; + private readonly PlayModeImpl _impl; + private readonly List _parametersList; + private List _cloneList; private FSInitializeFileSystemOperation _initFileSystemOp; private ESteps _steps = ESteps.None; - internal EditorSimulateModeInitializationOperation(EditorSimulateModeImpl impl, EditorSimulateModeParameters parameters) + internal InitializationOperation(PlayModeImpl impl, List parametersList) { _impl = impl; - _parameters = parameters; + _parametersList = parametersList; } internal override void InternalStart() { - _steps = ESteps.CreateFileSystem; + _steps = ESteps.Prepare; } internal override void InternalUpdate() { - if (_steps == ESteps.CreateFileSystem) + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.Prepare) { - if (_parameters.EditorFileSystemParameters == null) + if (_parametersList == null || _parametersList.Count == 0) { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = "Editor file system parameters is null"; + Error = "The file system parameters is empty !"; return; } - _impl.EditorFileSystem = _parameters.EditorFileSystemParameters.CreateFileSystem(_impl.PackageName); - if (_impl.EditorFileSystem == null) + foreach (var fileSystemParam in _parametersList) { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = "Failed to create editor file system"; - return; + if (fileSystemParam == null) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = "An empty object exists in the list!"; + return; + } } + _cloneList = _parametersList.ToList(); + _steps = ESteps.ClearOldFileSystem; + } + + if (_steps == ESteps.ClearOldFileSystem) + { + // 注意:初始化失败后可能会残存一些旧的文件系统! + foreach (var fileSystem in _impl.FileSystems) + { + fileSystem.OnDestroy(); + } + + _impl.FileSystems.Clear(); _steps = ESteps.InitFileSystem; } if (_steps == ESteps.InitFileSystem) { - if (_initFileSystemOp == null) + if (_cloneList.Count == 0) { - _initFileSystemOp = _impl.EditorFileSystem.InitializeFileSystemAsync(); + _steps = ESteps.Done; + Status = EOperationStatus.Succeed; + } + else + { + var fileSystemParams = _cloneList[0]; + _cloneList.RemoveAt(0); + + IFileSystem fileSystemInstance = fileSystemParams.CreateFileSystem(_impl.PackageName); + if (fileSystemInstance == null) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = "Failed to create file system instance !"; + return; + } + + _impl.FileSystems.Add(fileSystemInstance); + _initFileSystemOp = fileSystemInstance.InitializeFileSystemAsync(); _initFileSystemOp.StartOperation(); AddChildOperation(_initFileSystemOp); + _steps = ESteps.CheckInitResult; } + } + if (_steps == ESteps.CheckInitResult) + { _initFileSystemOp.UpdateOperation(); Progress = _initFileSystemOp.Progress; if (_initFileSystemOp.IsDone == false) @@ -75,375 +110,15 @@ namespace YooAsset if (_initFileSystemOp.Status == EOperationStatus.Succeed) { - _steps = ESteps.Done; - Status = EOperationStatus.Succeed; + _steps = ESteps.InitFileSystem; } else { _steps = ESteps.Done; Status = EOperationStatus.Failed; Error = _initFileSystemOp.Error; - } - } - } - } - - /// - /// 离线运行模式 - /// - internal sealed class OfflinePlayModeInitializationOperation : InitializationOperation - { - private enum ESteps - { - None, - CreateFileSystem, - InitFileSystem, - Done, - } - - private readonly OfflinePlayModeImpl _impl; - private readonly OfflinePlayModeParameters _parameters; - private FSInitializeFileSystemOperation _initFileSystemOp; - private ESteps _steps = ESteps.None; - - internal OfflinePlayModeInitializationOperation(OfflinePlayModeImpl impl, OfflinePlayModeParameters parameters) - { - _impl = impl; - _parameters = parameters; - } - internal override void InternalStart() - { - _steps = ESteps.CreateFileSystem; - } - internal override void InternalUpdate() - { - if (_steps == ESteps.None || _steps == ESteps.Done) - return; - - if (_steps == ESteps.CreateFileSystem) - { - if (_parameters.BuildinFileSystemParameters == null) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = "Buildin file system parameters is null"; return; } - - _impl.BuildinFileSystem = _parameters.BuildinFileSystemParameters.CreateFileSystem(_impl.PackageName); - if (_impl.BuildinFileSystem == null) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = "Failed to create buildin file system"; - return; - } - - _steps = ESteps.InitFileSystem; - } - - if (_steps == ESteps.InitFileSystem) - { - if (_initFileSystemOp == null) - { - _initFileSystemOp = _impl.BuildinFileSystem.InitializeFileSystemAsync(); - _initFileSystemOp.StartOperation(); - AddChildOperation(_initFileSystemOp); - } - - _initFileSystemOp.UpdateOperation(); - Progress = _initFileSystemOp.Progress; - if (_initFileSystemOp.IsDone == false) - return; - - if (_initFileSystemOp.Status == EOperationStatus.Succeed) - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeed; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = _initFileSystemOp.Error; - } - } - } - } - - /// - /// 联机运行模式 - /// - internal sealed class HostPlayModeInitializationOperation : InitializationOperation - { - private enum ESteps - { - None, - CreateBuildinFileSystem, - InitBuildinFileSystem, - CreateCacheFileSystem, - InitCacheFileSystem, - Done, - } - - private readonly HostPlayModeImpl _impl; - private readonly HostPlayModeParameters _parameters; - private FSInitializeFileSystemOperation _initBuildinFileSystemOp; - private FSInitializeFileSystemOperation _initCacheFileSystemOp; - private ESteps _steps = ESteps.None; - - internal HostPlayModeInitializationOperation(HostPlayModeImpl impl, HostPlayModeParameters parameters) - { - _impl = impl; - _parameters = parameters; - } - internal override void InternalStart() - { - _steps = ESteps.CreateBuildinFileSystem; - } - internal override void InternalUpdate() - { - if (_steps == ESteps.None || _steps == ESteps.Done) - return; - - if (_steps == ESteps.CreateBuildinFileSystem) - { - if (_parameters.BuildinFileSystemParameters == null) - { - _steps = ESteps.CreateCacheFileSystem; - return; - } - - _impl.BuildinFileSystem = _parameters.BuildinFileSystemParameters.CreateFileSystem(_impl.PackageName); - if (_impl.BuildinFileSystem == null) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = "Failed to create buildin file system"; - return; - } - - _steps = ESteps.InitBuildinFileSystem; - } - - if (_steps == ESteps.InitBuildinFileSystem) - { - if (_initBuildinFileSystemOp == null) - { - _initBuildinFileSystemOp = _impl.BuildinFileSystem.InitializeFileSystemAsync(); - _initBuildinFileSystemOp.StartOperation(); - AddChildOperation(_initBuildinFileSystemOp); - } - - _initBuildinFileSystemOp.UpdateOperation(); - Progress = _initBuildinFileSystemOp.Progress; - if (_initBuildinFileSystemOp.IsDone == false) - return; - - if (_initBuildinFileSystemOp.Status == EOperationStatus.Succeed) - { - _steps = ESteps.CreateCacheFileSystem; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = _initBuildinFileSystemOp.Error; - } - } - - if (_steps == ESteps.CreateCacheFileSystem) - { - if (_parameters.CacheFileSystemParameters == null) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = "Cache file system parameters is null"; - return; - } - - _impl.CacheFileSystem = _parameters.CacheFileSystemParameters.CreateFileSystem(_impl.PackageName); - if (_impl.CacheFileSystem == null) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = "Failed to create cache file system"; - return; - } - - _steps = ESteps.InitCacheFileSystem; - } - - if (_steps == ESteps.InitCacheFileSystem) - { - if (_initCacheFileSystemOp == null) - { - _initCacheFileSystemOp = _impl.CacheFileSystem.InitializeFileSystemAsync(); - _initCacheFileSystemOp.StartOperation(); - AddChildOperation(_initCacheFileSystemOp); - } - - _initCacheFileSystemOp.UpdateOperation(); - Progress = _initCacheFileSystemOp.Progress; - if (_initCacheFileSystemOp.IsDone == false) - return; - - if (_initCacheFileSystemOp.Status == EOperationStatus.Succeed) - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeed; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = _initCacheFileSystemOp.Error; - } - } - } - } - - /// - /// WebGL运行模式 - /// - internal sealed class WebPlayModeInitializationOperation : InitializationOperation - { - private enum ESteps - { - None, - CreateWebServerFileSystem, - InitWebServerFileSystem, - CreateWebRemoteFileSystem, - InitWebRemoteFileSystem, - CheckResult, - Done, - } - - private readonly WebPlayModeImpl _impl; - private readonly WebPlayModeParameters _parameters; - private FSInitializeFileSystemOperation _initWebServerFileSystemOp; - private FSInitializeFileSystemOperation _initWebRemoteFileSystemOp; - private ESteps _steps = ESteps.None; - - internal WebPlayModeInitializationOperation(WebPlayModeImpl impl, WebPlayModeParameters parameters) - { - _impl = impl; - _parameters = parameters; - } - internal override void InternalStart() - { - _steps = ESteps.CreateWebServerFileSystem; - } - internal override void InternalUpdate() - { - if (_steps == ESteps.None || _steps == ESteps.Done) - return; - - if (_steps == ESteps.CreateWebServerFileSystem) - { - if (_parameters.WebServerFileSystemParameters == null) - { - _steps = ESteps.CreateWebRemoteFileSystem; - return; - } - - _impl.WebServerFileSystem = _parameters.WebServerFileSystemParameters.CreateFileSystem(_impl.PackageName); - if (_impl.WebServerFileSystem == null) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = "Failed to create web server file system"; - return; - } - - _steps = ESteps.InitWebServerFileSystem; - } - - if (_steps == ESteps.InitWebServerFileSystem) - { - if (_initWebServerFileSystemOp == null) - { - _initWebServerFileSystemOp = _impl.WebServerFileSystem.InitializeFileSystemAsync(); - _initWebServerFileSystemOp.StartOperation(); - AddChildOperation(_initWebServerFileSystemOp); - } - - _initWebServerFileSystemOp.UpdateOperation(); - Progress = _initWebServerFileSystemOp.Progress; - if (_initWebServerFileSystemOp.IsDone == false) - return; - - if (_initWebServerFileSystemOp.Status == EOperationStatus.Succeed) - { - _steps = ESteps.CreateWebRemoteFileSystem; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = _initWebServerFileSystemOp.Error; - } - } - - if (_steps == ESteps.CreateWebRemoteFileSystem) - { - if (_parameters.WebRemoteFileSystemParameters == null) - { - _steps = ESteps.CheckResult; - return; - } - - _impl.WebRemoteFileSystem = _parameters.WebRemoteFileSystemParameters.CreateFileSystem(_impl.PackageName); - if (_impl.WebRemoteFileSystem == null) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = "Failed to create web remote file system"; - return; - } - - _steps = ESteps.InitWebRemoteFileSystem; - } - - if (_steps == ESteps.InitWebRemoteFileSystem) - { - if (_initWebRemoteFileSystemOp == null) - { - _initWebRemoteFileSystemOp = _impl.WebRemoteFileSystem.InitializeFileSystemAsync(); - _initWebRemoteFileSystemOp.StartOperation(); - AddChildOperation(_initWebRemoteFileSystemOp); - } - - _initWebRemoteFileSystemOp.UpdateOperation(); - Progress = _initWebRemoteFileSystemOp.Progress; - if (_initWebRemoteFileSystemOp.IsDone == false) - return; - - if (_initWebRemoteFileSystemOp.Status == EOperationStatus.Succeed) - { - _steps = ESteps.CheckResult; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = _initWebRemoteFileSystemOp.Error; - } - } - - if (_steps == ESteps.CheckResult) - { - if (_impl.WebServerFileSystem == null && _impl.WebRemoteFileSystem == null) - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = "Not found any file system !"; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Succeed; - } } } } diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/PreDownloadContentOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/PreDownloadContentOperation.cs index e7825220..16a8b8ef 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/PreDownloadContentOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/PreDownloadContentOperation.cs @@ -4,132 +4,7 @@ using System.Collections.Generic; namespace YooAsset { - /// - /// 预下载内容 - /// 说明:目前只支持联机模式 - /// - public abstract class PreDownloadContentOperation : AsyncOperationBase - { - /// - /// 创建资源下载器,用于下载当前资源版本所有的资源包文件 - /// - /// 同时下载的最大文件数 - /// 下载失败的重试次数 - /// 超时时间 - public abstract ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60); - - /// - /// 创建资源下载器,用于下载指定的资源标签关联的资源包文件 - /// - /// 资源标签 - /// 同时下载的最大文件数 - /// 下载失败的重试次数 - /// 超时时间 - public abstract ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60); - - /// - /// 创建资源下载器,用于下载指定的资源标签列表关联的资源包文件 - /// - /// 资源标签列表 - /// 同时下载的最大文件数 - /// 下载失败的重试次数 - /// 超时时间 - public abstract ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60); - - /// - /// 创建资源下载器,用于下载指定的资源依赖的资源包文件 - /// - /// 资源定位地址 - /// 同时下载的最大文件数 - /// 下载失败的重试次数 - /// 超时时间 - public abstract ResourceDownloaderOperation CreateBundleDownloader(string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60); - - /// - /// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件 - /// - /// 资源定位地址列表 - /// 同时下载的最大文件数 - /// 下载失败的重试次数 - /// 超时时间 - public abstract ResourceDownloaderOperation CreateBundleDownloader(string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60); - } - - internal class EditorSimulateModePreDownloadContentOperation : PreDownloadContentOperation - { - private readonly EditorSimulateModeImpl _impl; - - public EditorSimulateModePreDownloadContentOperation(EditorSimulateModeImpl impl) - { - _impl = impl; - } - internal override void InternalStart() - { - Status = EOperationStatus.Succeed; - } - internal override void InternalUpdate() - { - } - - public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); - } - public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); - } - public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); - } - public override ResourceDownloaderOperation CreateBundleDownloader(string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); - } - public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); - } - } - internal class OfflinePlayModePreDownloadContentOperation : PreDownloadContentOperation - { - private readonly OfflinePlayModeImpl _impl; - - public OfflinePlayModePreDownloadContentOperation(OfflinePlayModeImpl impl) - { - _impl = impl; - } - internal override void InternalStart() - { - Status = EOperationStatus.Succeed; - } - internal override void InternalUpdate() - { - } - - public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); - } - public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); - } - public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); - } - public override ResourceDownloaderOperation CreateBundleDownloader(string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); - } - public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); - } - } - internal class HostPlayModePreDownloadContentOperation : PreDownloadContentOperation + public sealed class PreDownloadContentOperation : AsyncOperationBase { private enum ESteps { @@ -140,7 +15,7 @@ namespace YooAsset Done, } - private readonly HostPlayModeImpl _impl; + private readonly PlayModeImpl _impl; private readonly string _packageVersion; private readonly int _timeout; private FSLoadPackageManifestOperation _loadPackageManifestOp; @@ -148,7 +23,7 @@ namespace YooAsset private ESteps _steps = ESteps.None; - internal HostPlayModePreDownloadContentOperation(HostPlayModeImpl impl, string packageVersion, int timeout) + internal PreDownloadContentOperation(PlayModeImpl impl, string packageVersion, int timeout) { _impl = impl; _packageVersion = packageVersion; @@ -196,7 +71,8 @@ namespace YooAsset { if (_loadPackageManifestOp == null) { - _loadPackageManifestOp = _impl.CacheFileSystem.LoadPackageManifestAsync(_packageVersion, _timeout); + var mainFileSystem = _impl.GetMainFileSystem(); + _loadPackageManifestOp = mainFileSystem.LoadPackageManifestAsync(_packageVersion, _timeout); _loadPackageManifestOp.StartOperation(); AddChildOperation(_loadPackageManifestOp); } @@ -220,7 +96,13 @@ namespace YooAsset } } - public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + /// + /// 创建资源下载器,用于下载当前资源版本所有的资源包文件 + /// + /// 同时下载的最大文件数 + /// 下载失败的重试次数 + /// 超时时间 + public ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { if (Status != EOperationStatus.Succeed) { @@ -228,11 +110,19 @@ namespace YooAsset return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } - List downloadList = PlayModeHelper.GetDownloadListByAll(_manifest, _impl.BuildinFileSystem, _impl.CacheFileSystem); + List downloadList = _impl.GetDownloadListByAll(_manifest); var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } - public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + + /// + /// 创建资源下载器,用于下载指定的资源标签关联的资源包文件 + /// + /// 资源标签 + /// 同时下载的最大文件数 + /// 下载失败的重试次数 + /// 超时时间 + public ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { if (Status != EOperationStatus.Succeed) { @@ -240,11 +130,19 @@ namespace YooAsset return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } - List downloadList = PlayModeHelper.GetDownloadListByTags(_manifest, new string[] { tag }, _impl.BuildinFileSystem, _impl.CacheFileSystem); + List downloadList = _impl.GetDownloadListByTags(_manifest, new string[] { tag }); var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } - public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + + /// + /// 创建资源下载器,用于下载指定的资源标签列表关联的资源包文件 + /// + /// 资源标签列表 + /// 同时下载的最大文件数 + /// 下载失败的重试次数 + /// 超时时间 + public ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { if (Status != EOperationStatus.Succeed) { @@ -252,11 +150,19 @@ namespace YooAsset return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); } - List downloadList = PlayModeHelper.GetDownloadListByTags(_manifest, tags, _impl.BuildinFileSystem, _impl.CacheFileSystem); + List downloadList = _impl.GetDownloadListByTags(_manifest, tags); var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } - public override ResourceDownloaderOperation CreateBundleDownloader(string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + + /// + /// 创建资源下载器,用于下载指定的资源依赖的资源包文件 + /// + /// 资源定位地址 + /// 同时下载的最大文件数 + /// 下载失败的重试次数 + /// 超时时间 + public ResourceDownloaderOperation CreateBundleDownloader(string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { if (Status != EOperationStatus.Succeed) { @@ -268,11 +174,19 @@ namespace YooAsset var assetInfo = _manifest.ConvertLocationToAssetInfo(location, null); assetInfos.Add(assetInfo); - List downloadList = PlayModeHelper.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload, _impl.BuildinFileSystem, _impl.CacheFileSystem); + List downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload); var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } - public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) + + /// + /// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件 + /// + /// 资源定位地址列表 + /// 同时下载的最大文件数 + /// 下载失败的重试次数 + /// 超时时间 + public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) { if (Status != EOperationStatus.Succeed) { @@ -287,46 +201,9 @@ namespace YooAsset assetInfos.Add(assetInfo); } - List downloadList = PlayModeHelper.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload, _impl.BuildinFileSystem, _impl.CacheFileSystem); + List downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload); var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } } - internal class WebPlayModePreDownloadContentOperation : PreDownloadContentOperation - { - private readonly WebPlayModeImpl _impl; - - public WebPlayModePreDownloadContentOperation(WebPlayModeImpl impl) - { - _impl = impl; - } - internal override void InternalStart() - { - Status = EOperationStatus.Succeed; - } - internal override void InternalUpdate() - { - } - - public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); - } - public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); - } - public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); - } - public override ResourceDownloaderOperation CreateBundleDownloader(string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); - } - public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60) - { - return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout); - } - } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/RequestPackageVersionOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/RequestPackageVersionOperation.cs index 38dc778f..adc3cfd3 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/RequestPackageVersionOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/RequestPackageVersionOperation.cs @@ -1,9 +1,6 @@  namespace YooAsset { - /// - /// 查询远端包裹的最新版本 - /// public abstract class RequestPackageVersionOperation : AsyncOperationBase { /// @@ -20,15 +17,15 @@ namespace YooAsset Done, } - private readonly IFileSystem _fileSystem; + private readonly PlayModeImpl _impl; private readonly bool _appendTimeTicks; private readonly int _timeout; private FSRequestPackageVersionOperation _requestPackageVersionOp; private ESteps _steps = ESteps.None; - internal RequestPackageVersionImplOperation(IFileSystem fileSystem, bool appendTimeTicks, int timeout) + internal RequestPackageVersionImplOperation(PlayModeImpl impl, bool appendTimeTicks, int timeout) { - _fileSystem = fileSystem; + _impl = impl; _appendTimeTicks = appendTimeTicks; _timeout = timeout; } @@ -45,7 +42,8 @@ namespace YooAsset { if (_requestPackageVersionOp == null) { - _requestPackageVersionOp = _fileSystem.RequestPackageVersionAsync(_appendTimeTicks, _timeout); + var mainFileSystem = _impl.GetMainFileSystem(); + _requestPackageVersionOp = mainFileSystem.RequestPackageVersionAsync(_appendTimeTicks, _timeout); _requestPackageVersionOp.StartOperation(); AddChildOperation(_requestPackageVersionOp); } diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/UpdatePackageManifestOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/UpdatePackageManifestOperation.cs index 0b27eabb..e8c97121 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/UpdatePackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/UpdatePackageManifestOperation.cs @@ -1,13 +1,7 @@  namespace YooAsset { - /// - /// 向远端请求并更新清单 - /// - public abstract class UpdatePackageManifestOperation : AsyncOperationBase - { - } - internal sealed class UpdatePackageManifestImplOperation : UpdatePackageManifestOperation + public sealed class UpdatePackageManifestOperation : AsyncOperationBase { private enum ESteps { @@ -17,19 +11,16 @@ namespace YooAsset LoadPackageManifest, Done, } - - private readonly IPlayMode _impl; - private readonly IFileSystem _fileSystem; + + private readonly PlayModeImpl _impl; private readonly string _packageVersion; private readonly int _timeout; private FSLoadPackageManifestOperation _loadPackageManifestOp; private ESteps _steps = ESteps.None; - - internal UpdatePackageManifestImplOperation(IPlayMode impl, IFileSystem fileSystem, string packageVersion, int timeout) + internal UpdatePackageManifestOperation(PlayModeImpl impl, string packageVersion, int timeout) { _impl = impl; - _fileSystem = fileSystem; _packageVersion = packageVersion; _timeout = timeout; } @@ -74,7 +65,8 @@ namespace YooAsset { if (_loadPackageManifestOp == null) { - _loadPackageManifestOp = _fileSystem.LoadPackageManifestAsync(_packageVersion, _timeout); + var mainFileSystem = _impl.GetMainFileSystem(); + _loadPackageManifestOp = mainFileSystem.LoadPackageManifestAsync(_packageVersion, _timeout); _loadPackageManifestOp.StartOperation(); AddChildOperation(_loadPackageManifestOp); } diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs deleted file mode 100644 index 3a70c0cf..00000000 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs +++ /dev/null @@ -1,173 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace YooAsset -{ - internal class EditorSimulateModeImpl : IPlayMode, IBundleQuery - { - public readonly string PackageName; - public IFileSystem EditorFileSystem { set; get; } - - - public EditorSimulateModeImpl(string packageName) - { - PackageName = packageName; - } - - /// - /// 异步初始化 - /// - public InitializationOperation InitializeAsync(EditorSimulateModeParameters initParameters) - { - var operation = new EditorSimulateModeInitializationOperation(this, initParameters); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - - #region IPlayMode接口 - public PackageManifest ActiveManifest { set; get; } - - void IPlayMode.DestroyFileSystem() - { - if (EditorFileSystem != null) - EditorFileSystem.OnDestroy(); - } - - RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout) - { - var operation = new RequestPackageVersionImplOperation(EditorFileSystem, appendTimeTicks, timeout); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, int timeout) - { - var operation = new UpdatePackageManifestImplOperation(this, EditorFileSystem, packageVersion, timeout); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout) - { - var operation = new EditorSimulateModePreDownloadContentOperation(this); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam) - { - var operation = new ClearCacheFilesImplOperation(this, EditorFileSystem, null, null, clearMode, clearParam); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - - ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) - { - List downloadList = PlayModeHelper.GetDownloadListByAll(ActiveManifest, EditorFileSystem); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - List downloadList = PlayModeHelper.GetDownloadListByTags(ActiveManifest, tags, EditorFileSystem); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - List downloadList = PlayModeHelper.GetDownloadListByPaths(ActiveManifest, assetInfos, recursiveDownload, EditorFileSystem); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) - { - List unpcakList = PlayModeHelper.GetUnpackListByAll(ActiveManifest, EditorFileSystem); - var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) - { - List unpcakList = PlayModeHelper.GetUnpackListByTags(ActiveManifest, tags, EditorFileSystem); - var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout) - { - List importerList = PlayModeHelper.GetImporterListByFilePaths(ActiveManifest, filePaths, EditorFileSystem); - var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout); - return operation; - } - #endregion - - #region IBundleQuery接口 - private BundleInfo CreateBundleInfo(PackageBundle packageBundle, AssetInfo assetInfo) - { - if (packageBundle == null) - throw new Exception("Should never get here !"); - - if (EditorFileSystem.Belong(packageBundle)) - { - BundleInfo bundleInfo = new BundleInfo(EditorFileSystem, packageBundle); - return bundleInfo; - } - - throw new Exception($"Can not found belong file system : {packageBundle.BundleName}"); - } - BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - throw new Exception("Should never get here !"); - - // 注意:如果清单里未找到资源包会抛出异常! - var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath); - return CreateBundleInfo(packageBundle, assetInfo); - } - BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - throw new Exception("Should never get here !"); - - // 注意:如果清单里未找到资源包会抛出异常! - var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath); - List result = new List(depends.Length); - foreach (var packageBundle in depends) - { - BundleInfo bundleInfo = CreateBundleInfo(packageBundle, assetInfo); - result.Add(bundleInfo); - } - return result.ToArray(); - } - string IBundleQuery.GetMainBundleName(int bundleID) - { - // 注意:如果清单里未找到资源包会抛出异常! - var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID); - return packageBundle.BundleName; - } - string IBundleQuery.GetMainBundleName(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - throw new Exception("Should never get here !"); - - // 注意:如果清单里未找到资源包会抛出异常! - var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath); - return packageBundle.BundleName; - } - string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - throw new Exception("Should never get here !"); - - // 注意:如果清单里未找到资源包会抛出异常! - var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath); - List result = new List(depends.Length); - foreach (var packageBundle in depends) - { - result.Add(packageBundle.BundleName); - } - return result.ToArray(); - } - bool IBundleQuery.ManifestValid() - { - return ActiveManifest != null; - } - #endregion - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs.meta b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs.meta deleted file mode 100644 index 305eea0d..00000000 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 2fb1b9a2a91f1af4a86acfcfac424e0b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs deleted file mode 100644 index c8ae44e8..00000000 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs +++ /dev/null @@ -1,181 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace YooAsset -{ - internal class HostPlayModeImpl : IPlayMode, IBundleQuery - { - public readonly string PackageName; - public IFileSystem BuildinFileSystem { set; get; } //可以为空! - public IFileSystem CacheFileSystem { set; get; } - - - public HostPlayModeImpl(string packageName) - { - PackageName = packageName; - } - - /// - /// 异步初始化 - /// - public InitializationOperation InitializeAsync(HostPlayModeParameters initParameters) - { - var operation = new HostPlayModeInitializationOperation(this, initParameters); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - - #region IPlayMode接口 - public PackageManifest ActiveManifest { set; get; } - - void IPlayMode.DestroyFileSystem() - { - if (BuildinFileSystem != null) - BuildinFileSystem.OnDestroy(); - if (CacheFileSystem != null) - CacheFileSystem.OnDestroy(); - } - - RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout) - { - var operation = new RequestPackageVersionImplOperation(CacheFileSystem, appendTimeTicks, timeout); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, int timeout) - { - var operation = new UpdatePackageManifestImplOperation(this, CacheFileSystem, packageVersion, timeout); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout) - { - var operation = new HostPlayModePreDownloadContentOperation(this, packageVersion, timeout); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam) - { - var operation = new ClearCacheFilesImplOperation(this, BuildinFileSystem, CacheFileSystem, null, clearMode, clearParam); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - - ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) - { - List downloadList = PlayModeHelper.GetDownloadListByAll(ActiveManifest, BuildinFileSystem, CacheFileSystem); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - List downloadList = PlayModeHelper.GetDownloadListByTags(ActiveManifest, tags, BuildinFileSystem, CacheFileSystem); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - List downloadList = PlayModeHelper.GetDownloadListByPaths(ActiveManifest, assetInfos, recursiveDownload, BuildinFileSystem, CacheFileSystem); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) - { - List unpcakList = PlayModeHelper.GetUnpackListByAll(ActiveManifest, BuildinFileSystem, CacheFileSystem); - var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) - { - List unpcakList = PlayModeHelper.GetUnpackListByTags(ActiveManifest, tags, BuildinFileSystem, CacheFileSystem); - var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout) - { - List importerList = PlayModeHelper.GetImporterListByFilePaths(ActiveManifest, filePaths, BuildinFileSystem, CacheFileSystem); - var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout); - return operation; - } - #endregion - - #region IBundleQuery接口 - private BundleInfo CreateBundleInfo(PackageBundle packageBundle, AssetInfo assetInfo) - { - if (packageBundle == null) - throw new Exception("Should never get here !"); - - if (BuildinFileSystem != null && BuildinFileSystem.Belong(packageBundle)) - { - BundleInfo bundleInfo = new BundleInfo(BuildinFileSystem, packageBundle); - return bundleInfo; - } - if (CacheFileSystem.Belong(packageBundle)) - { - BundleInfo bundleInfo = new BundleInfo(CacheFileSystem, packageBundle); - return bundleInfo; - } - - throw new Exception($"Can not found belong file system : {packageBundle.BundleName}"); - } - BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - throw new Exception("Should never get here !"); - - // 注意:如果清单里未找到资源包会抛出异常! - var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath); - return CreateBundleInfo(packageBundle, assetInfo); - } - BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - throw new Exception("Should never get here !"); - - // 注意:如果清单里未找到资源包会抛出异常! - var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath); - List result = new List(depends.Length); - foreach (var packageBundle in depends) - { - BundleInfo bundleInfo = CreateBundleInfo(packageBundle, assetInfo); - result.Add(bundleInfo); - } - return result.ToArray(); - } - string IBundleQuery.GetMainBundleName(int bundleID) - { - // 注意:如果清单里未找到资源包会抛出异常! - var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID); - return packageBundle.BundleName; - } - string IBundleQuery.GetMainBundleName(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - throw new Exception("Should never get here !"); - - // 注意:如果清单里未找到资源包会抛出异常! - var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath); - return packageBundle.BundleName; - } - string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - throw new Exception("Should never get here !"); - - // 注意:如果清单里未找到资源包会抛出异常! - var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath); - List result = new List(depends.Length); - foreach (var packageBundle in depends) - { - result.Add(packageBundle.BundleName); - } - return result.ToArray(); - } - bool IBundleQuery.ManifestValid() - { - return ActiveManifest != null; - } - #endregion - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs.meta b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs.meta deleted file mode 100644 index 1d8ae52f..00000000 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 84c10fd3507a1c24a9043aebb72db5f5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs deleted file mode 100644 index 75316285..00000000 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs +++ /dev/null @@ -1,173 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace YooAsset -{ - internal class OfflinePlayModeImpl : IPlayMode, IBundleQuery - { - public readonly string PackageName; - public IFileSystem BuildinFileSystem { set; get; } - - - public OfflinePlayModeImpl(string packageName) - { - PackageName = packageName; - } - - /// - /// 异步初始化 - /// - public InitializationOperation InitializeAsync(OfflinePlayModeParameters initParameters) - { - var operation = new OfflinePlayModeInitializationOperation(this, initParameters); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - - #region IPlayMode接口 - public PackageManifest ActiveManifest { set; get; } - - void IPlayMode.DestroyFileSystem() - { - if (BuildinFileSystem != null) - BuildinFileSystem.OnDestroy(); - } - - RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout) - { - var operation = new RequestPackageVersionImplOperation(BuildinFileSystem, appendTimeTicks, timeout); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, int timeout) - { - var operation = new UpdatePackageManifestImplOperation(this, BuildinFileSystem, packageVersion, timeout); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout) - { - var operation = new OfflinePlayModePreDownloadContentOperation(this); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam) - { - var operation = new ClearCacheFilesImplOperation(this, BuildinFileSystem, null, null, clearMode, clearParam); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - - ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) - { - List downloadList = PlayModeHelper.GetDownloadListByAll(ActiveManifest, BuildinFileSystem); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - List downloadList = PlayModeHelper.GetDownloadListByTags(ActiveManifest, tags, BuildinFileSystem); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - List downloadList = PlayModeHelper.GetDownloadListByPaths(ActiveManifest, assetInfos, recursiveDownload, BuildinFileSystem); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) - { - List unpcakList = PlayModeHelper.GetUnpackListByAll(ActiveManifest, BuildinFileSystem); - var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) - { - List unpcakList = PlayModeHelper.GetUnpackListByTags(ActiveManifest, tags, BuildinFileSystem); - var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout) - { - List importerList = PlayModeHelper.GetImporterListByFilePaths(ActiveManifest, filePaths, BuildinFileSystem); - var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout); - return operation; - } - #endregion - - #region IBundleQuery接口 - private BundleInfo CreateBundleInfo(PackageBundle packageBundle, AssetInfo assetInfo) - { - if (packageBundle == null) - throw new Exception("Should never get here !"); - - if (BuildinFileSystem.Belong(packageBundle)) - { - BundleInfo bundleInfo = new BundleInfo(BuildinFileSystem, packageBundle); - return bundleInfo; - } - - throw new Exception($"Can not found belong file system : {packageBundle.BundleName}"); - } - BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - throw new Exception("Should never get here !"); - - // 注意:如果清单里未找到资源包会抛出异常! - var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath); - return CreateBundleInfo(packageBundle, assetInfo); - } - BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - throw new Exception("Should never get here !"); - - // 注意:如果清单里未找到资源包会抛出异常! - var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath); - List result = new List(depends.Length); - foreach (var packageBundle in depends) - { - BundleInfo bundleInfo = CreateBundleInfo(packageBundle, assetInfo); - result.Add(bundleInfo); - } - return result.ToArray(); - } - string IBundleQuery.GetMainBundleName(int bundleID) - { - // 注意:如果清单里未找到资源包会抛出异常! - var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID); - return packageBundle.BundleName; - } - string IBundleQuery.GetMainBundleName(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - throw new Exception("Should never get here !"); - - // 注意:如果清单里未找到资源包会抛出异常! - var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath); - return packageBundle.BundleName; - } - string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - throw new Exception("Should never get here !"); - - // 注意:如果清单里未找到资源包会抛出异常! - var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath); - List result = new List(depends.Length); - foreach (var packageBundle in depends) - { - result.Add(packageBundle.BundleName); - } - return result.ToArray(); - } - bool IBundleQuery.ManifestValid() - { - return ActiveManifest != null; - } - #endregion - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeHelper.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeHelper.cs deleted file mode 100644 index 43878f8d..00000000 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeHelper.cs +++ /dev/null @@ -1,276 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace YooAsset -{ - internal class PlayModeHelper - { - public static List GetDownloadListByAll(PackageManifest manifest, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null) - { - List result = new List(1000); - foreach (var packageBundle in manifest.BundleList) - { - IFileSystem fileSystem = null; - if (fileSystemA != null && fileSystemA.Belong(packageBundle)) - { - if (fileSystemA.NeedDownload(packageBundle)) - fileSystem = fileSystemA; - } - else if (fileSystemB != null && fileSystemB.Belong(packageBundle)) - { - if (fileSystemB.NeedDownload(packageBundle)) - fileSystem = fileSystemB; - } - else if (fileSystemC != null && fileSystemC.Belong(packageBundle)) - { - if (fileSystemC.NeedDownload(packageBundle)) - fileSystem = fileSystemC; - } - else - { - YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}"); - } - if (fileSystem == null) - continue; - - var bundleInfo = new BundleInfo(fileSystem, packageBundle); - result.Add(bundleInfo); - } - return result; - } - public static List GetDownloadListByTags(PackageManifest manifest, string[] tags, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null) - { - List result = new List(1000); - foreach (var packageBundle in manifest.BundleList) - { - IFileSystem fileSystem = null; - if (fileSystemA != null && fileSystemA.Belong(packageBundle)) - { - if (fileSystemA.NeedDownload(packageBundle)) - fileSystem = fileSystemA; - } - else if (fileSystemB != null && fileSystemB.Belong(packageBundle)) - { - if (fileSystemB.NeedDownload(packageBundle)) - fileSystem = fileSystemB; - } - else if (fileSystemC != null && fileSystemC.Belong(packageBundle)) - { - if (fileSystemC.NeedDownload(packageBundle)) - fileSystem = fileSystemC; - } - else - { - YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}"); - } - if (fileSystem == null) - continue; - - // 如果未带任何标记,则统一下载 - if (packageBundle.HasAnyTags() == false) - { - var bundleInfo = new BundleInfo(fileSystem, packageBundle); - result.Add(bundleInfo); - } - else - { - // 查询DLC资源 - if (packageBundle.HasTag(tags)) - { - var bundleInfo = new BundleInfo(fileSystem, packageBundle); - result.Add(bundleInfo); - } - } - } - return result; - } - public static List GetDownloadListByPaths(PackageManifest manifest, AssetInfo[] assetInfos, bool recursiveDownload, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null) - { - // 获取资源对象的资源包和所有依赖资源包 - List checkList = new List(); - foreach (var assetInfo in assetInfos) - { - if (assetInfo.IsInvalid) - { - YooLogger.Warning(assetInfo.Error); - continue; - } - - // 注意:如果清单里未找到资源包会抛出异常! - PackageBundle mainBundle = manifest.GetMainPackageBundle(assetInfo.AssetPath); - if (checkList.Contains(mainBundle) == false) - checkList.Add(mainBundle); - - // 注意:如果清单里未找到资源包会抛出异常! - PackageBundle[] mainDependBundles = manifest.GetAllDependencies(assetInfo.AssetPath); - foreach (var dependBundle in mainDependBundles) - { - if (checkList.Contains(dependBundle) == false) - checkList.Add(dependBundle); - } - - // 下载主资源包内所有资源对象依赖的资源包 - if (recursiveDownload) - { - foreach (var otherMainAsset in mainBundle.IncludeMainAssets) - { - var otherMainBundle = manifest.GetMainPackageBundle(otherMainAsset.BundleID); - if (checkList.Contains(otherMainBundle) == false) - checkList.Add(otherMainBundle); - - PackageBundle[] otherDependBundles = manifest.GetAllDependencies(otherMainAsset); - foreach (var dependBundle in otherDependBundles) - { - if (checkList.Contains(dependBundle) == false) - checkList.Add(dependBundle); - } - } - } - } - - List result = new List(1000); - foreach (var packageBundle in checkList) - { - IFileSystem fileSystem = null; - if (fileSystemA != null && fileSystemA.Belong(packageBundle)) - { - if (fileSystemA.NeedDownload(packageBundle)) - fileSystem = fileSystemA; - } - else if (fileSystemB != null && fileSystemB.Belong(packageBundle)) - { - if (fileSystemB.NeedDownload(packageBundle)) - fileSystem = fileSystemB; - } - else if (fileSystemC != null && fileSystemC.Belong(packageBundle)) - { - if (fileSystemC.NeedDownload(packageBundle)) - fileSystem = fileSystemC; - } - else - { - YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}"); - } - if (fileSystem == null) - continue; - - var bundleInfo = new BundleInfo(fileSystem, packageBundle); - result.Add(bundleInfo); - } - return result; - } - public static List GetUnpackListByAll(PackageManifest manifest, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null) - { - List result = new List(1000); - foreach (var packageBundle in manifest.BundleList) - { - IFileSystem fileSystem = null; - if (fileSystemA != null && fileSystemA.Belong(packageBundle)) - { - if (fileSystemA.NeedUnpack(packageBundle)) - fileSystem = fileSystemA; - } - else if (fileSystemB != null && fileSystemB.Belong(packageBundle)) - { - if (fileSystemB.NeedUnpack(packageBundle)) - fileSystem = fileSystemB; - } - else if (fileSystemC != null && fileSystemC.Belong(packageBundle)) - { - if (fileSystemC.NeedUnpack(packageBundle)) - fileSystem = fileSystemC; - } - else - { - YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}"); - } - if (fileSystem == null) - continue; - - var bundleInfo = new BundleInfo(fileSystem, packageBundle); - result.Add(bundleInfo); - } - - return result; - } - public static List GetUnpackListByTags(PackageManifest manifest, string[] tags, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null) - { - List result = new List(1000); - foreach (var packageBundle in manifest.BundleList) - { - IFileSystem fileSystem = null; - if (fileSystemA != null && fileSystemA.Belong(packageBundle)) - { - if (fileSystemA.NeedUnpack(packageBundle)) - fileSystem = fileSystemA; - } - else if (fileSystemB != null && fileSystemB.Belong(packageBundle)) - { - if (fileSystemB.NeedUnpack(packageBundle)) - fileSystem = fileSystemB; - } - else if (fileSystemC != null && fileSystemC.Belong(packageBundle)) - { - if (fileSystemC.NeedUnpack(packageBundle)) - fileSystem = fileSystemC; - } - else - { - YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}"); - } - if (fileSystem == null) - continue; - - // 查询DLC资源 - if (packageBundle.HasTag(tags)) - { - var bundleInfo = new BundleInfo(fileSystem, packageBundle); - result.Add(bundleInfo); - } - } - - return result; - } - public static List GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null) - { - List result = new List(); - foreach (var filePath in filePaths) - { - string fileName = System.IO.Path.GetFileName(filePath); - if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle)) - { - IFileSystem fileSystem = null; - if (fileSystemA != null && fileSystemA.Belong(packageBundle)) - { - if (fileSystemA.NeedImport(packageBundle)) - fileSystem = fileSystemA; - } - else if (fileSystemB != null && fileSystemB.Belong(packageBundle)) - { - if (fileSystemB.NeedImport(packageBundle)) - fileSystem = fileSystemB; - } - else if (fileSystemC != null && fileSystemC.Belong(packageBundle)) - { - if (fileSystemC.NeedImport(packageBundle)) - fileSystem = fileSystemC; - } - else - { - YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}"); - } - if (fileSystem == null) - continue; - - var bundleInfo = new BundleInfo(fileSystem, packageBundle, filePath); - result.Add(bundleInfo); - } - else - { - YooLogger.Warning($"Not found package bundle, importer file path : {filePath}"); - } - } - return result; - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeHelper.cs.meta b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeHelper.cs.meta deleted file mode 100644 index 8d222d8b..00000000 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: fbbce8ae4b0d0784683413d6466d27f8 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeImpl.cs new file mode 100644 index 00000000..388c26e0 --- /dev/null +++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeImpl.cs @@ -0,0 +1,440 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +namespace YooAsset +{ + internal class PlayModeImpl : IPlayMode, IBundleQuery + { + public readonly string PackageName; + public readonly List FileSystems = new List(10); + + + public PlayModeImpl(string packageName) + { + PackageName = packageName; + } + + /// + /// 异步初始化 + /// + public InitializationOperation InitializeAsync(FileSystemParameters fileSystemParameter) + { + var fileSystemParamList = new List(); + if (fileSystemParameter != null) + fileSystemParamList.Add(fileSystemParameter); + return InitializeAsync(fileSystemParamList); + } + + /// + /// 异步初始化 + /// + public InitializationOperation InitializeAsync(FileSystemParameters fileSystemParameterA, FileSystemParameters fileSystemParameterB) + { + var fileSystemParamList = new List(); + if (fileSystemParameterA != null) + fileSystemParamList.Add(fileSystemParameterA); + if (fileSystemParameterB != null) + fileSystemParamList.Add(fileSystemParameterB); + return InitializeAsync(fileSystemParamList); + } + + /// + /// 异步初始化 + /// + public InitializationOperation InitializeAsync(List fileSystemParameterList) + { + var operation = new InitializationOperation(this, fileSystemParameterList); + OperationSystem.StartOperation(PackageName, operation); + return operation; + } + + #region IPlayMode接口 + /// + /// 当前激活的清单 + /// + public PackageManifest ActiveManifest { set; get; } + + /// + /// 销毁文件系统 + /// + void IPlayMode.DestroyFileSystem() + { + foreach (var fileSystem in FileSystems) + { + fileSystem.OnDestroy(); + } + FileSystems.Clear(); + } + + /// + /// 向网络端请求最新的资源版本 + /// + RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout) + { + var operation = new RequestPackageVersionImplOperation(this, appendTimeTicks, timeout); + OperationSystem.StartOperation(PackageName, operation); + return operation; + } + + /// + /// 向网络端请求并更新清单 + /// + UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, int timeout) + { + var operation = new UpdatePackageManifestOperation(this, packageVersion, timeout); + OperationSystem.StartOperation(PackageName, operation); + return operation; + } + + /// + /// 预下载指定版本的包裹内容 + /// + PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout) + { + var operation = new PreDownloadContentOperation(this, packageVersion, timeout); + OperationSystem.StartOperation(PackageName, operation); + return operation; + } + + /// + /// 清理缓存文件 + /// + ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam) + { + var operation = new ClearCacheFilesOperation(this, clearMode, clearParam); + OperationSystem.StartOperation(PackageName, operation); + return operation; + } + + // 下载相关 + ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) + { + List downloadList = GetDownloadListByAll(ActiveManifest); + var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); + return operation; + } + ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) + { + List downloadList = GetDownloadListByTags(ActiveManifest, tags); + var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); + return operation; + } + ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout) + { + List downloadList = GetDownloadListByPaths(ActiveManifest, assetInfos, recursiveDownload); + var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); + return operation; + } + + // 解压相关 + ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) + { + List unpcakList = GetUnpackListByAll(ActiveManifest); + var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); + return operation; + } + ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) + { + List unpcakList = GetUnpackListByTags(ActiveManifest, tags); + var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); + return operation; + } + + // 导入相关 + ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout) + { + List importerList = GetImporterListByFilePaths(ActiveManifest, filePaths); + var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout); + return operation; + } + #endregion + + #region IBundleQuery接口 + private BundleInfo CreateBundleInfo(PackageBundle packageBundle) + { + if (packageBundle == null) + throw new Exception("Should never get here !"); + + var fileSystem = GetBelongFileSystem(packageBundle); + if (fileSystem != null) + { + BundleInfo bundleInfo = new BundleInfo(fileSystem, packageBundle); + return bundleInfo; + } + + throw new Exception($"Can not found belong file system : {packageBundle.BundleName}"); + } + BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo) + { + if (assetInfo.IsInvalid) + throw new Exception("Should never get here !"); + + // 注意:如果清单里未找到资源包会抛出异常! + var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath); + return CreateBundleInfo(packageBundle); + } + BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo) + { + if (assetInfo.IsInvalid) + throw new Exception("Should never get here !"); + + // 注意:如果清单里未找到资源包会抛出异常! + var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath); + List result = new List(depends.Length); + foreach (var packageBundle in depends) + { + BundleInfo bundleInfo = CreateBundleInfo(packageBundle); + result.Add(bundleInfo); + } + return result.ToArray(); + } + string IBundleQuery.GetMainBundleName(int bundleID) + { + // 注意:如果清单里未找到资源包会抛出异常! + var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID); + return packageBundle.BundleName; + } + string IBundleQuery.GetMainBundleName(AssetInfo assetInfo) + { + if (assetInfo.IsInvalid) + throw new Exception("Should never get here !"); + + // 注意:如果清单里未找到资源包会抛出异常! + var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath); + return packageBundle.BundleName; + } + string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo) + { + if (assetInfo.IsInvalid) + throw new Exception("Should never get here !"); + + // 注意:如果清单里未找到资源包会抛出异常! + var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath); + List result = new List(depends.Length); + foreach (var packageBundle in depends) + { + result.Add(packageBundle.BundleName); + } + return result.ToArray(); + } + #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; + } + + public List GetDownloadListByAll(PackageManifest manifest) + { + if (manifest == null) + return new List(); + + List result = new List(1000); + foreach (var packageBundle in manifest.BundleList) + { + var fileSystem = GetBelongFileSystem(packageBundle); + if (fileSystem == null) + continue; + + if (fileSystem.NeedDownload(packageBundle)) + { + var bundleInfo = new BundleInfo(fileSystem, packageBundle); + result.Add(bundleInfo); + } + } + return result; + } + public List GetDownloadListByTags(PackageManifest manifest, string[] tags) + { + if (manifest == null) + return new List(); + + List result = new List(1000); + foreach (var packageBundle in manifest.BundleList) + { + var fileSystem = GetBelongFileSystem(packageBundle); + if (fileSystem == null) + continue; + + if (fileSystem.NeedDownload(packageBundle)) + { + // 如果未带任何标记,则统一下载 + if (packageBundle.HasAnyTags() == false) + { + var bundleInfo = new BundleInfo(fileSystem, packageBundle); + result.Add(bundleInfo); + } + else + { + // 查询DLC资源 + if (packageBundle.HasTag(tags)) + { + var bundleInfo = new BundleInfo(fileSystem, packageBundle); + result.Add(bundleInfo); + } + } + } + } + return result; + } + public List GetDownloadListByPaths(PackageManifest manifest, AssetInfo[] assetInfos, bool recursiveDownload) + { + if (manifest == null) + return new List(); + + // 获取资源对象的资源包和所有依赖资源包 + List checkList = new List(); + foreach (var assetInfo in assetInfos) + { + if (assetInfo.IsInvalid) + { + YooLogger.Warning(assetInfo.Error); + continue; + } + + // 注意:如果清单里未找到资源包会抛出异常! + PackageBundle mainBundle = manifest.GetMainPackageBundle(assetInfo.AssetPath); + if (checkList.Contains(mainBundle) == false) + checkList.Add(mainBundle); + + // 注意:如果清单里未找到资源包会抛出异常! + PackageBundle[] mainDependBundles = manifest.GetAllDependencies(assetInfo.AssetPath); + foreach (var dependBundle in mainDependBundles) + { + if (checkList.Contains(dependBundle) == false) + checkList.Add(dependBundle); + } + + // 下载主资源包内所有资源对象依赖的资源包 + if (recursiveDownload) + { + foreach (var otherMainAsset in mainBundle.IncludeMainAssets) + { + var otherMainBundle = manifest.GetMainPackageBundle(otherMainAsset.BundleID); + if (checkList.Contains(otherMainBundle) == false) + checkList.Add(otherMainBundle); + + PackageBundle[] otherDependBundles = manifest.GetAllDependencies(otherMainAsset); + foreach (var dependBundle in otherDependBundles) + { + if (checkList.Contains(dependBundle) == false) + checkList.Add(dependBundle); + } + } + } + } + + List result = new List(1000); + foreach (var packageBundle in checkList) + { + var fileSystem = GetBelongFileSystem(packageBundle); + if (fileSystem == null) + continue; + + if (fileSystem.NeedDownload(packageBundle)) + { + var bundleInfo = new BundleInfo(fileSystem, packageBundle); + result.Add(bundleInfo); + } + } + return result; + } + public List GetUnpackListByAll(PackageManifest manifest) + { + if (manifest == null) + return new List(); + + List result = new List(1000); + foreach (var packageBundle in manifest.BundleList) + { + var fileSystem = GetBelongFileSystem(packageBundle); + if (fileSystem == null) + continue; + + if (fileSystem.NeedUnpack(packageBundle)) + { + var bundleInfo = new BundleInfo(fileSystem, packageBundle); + result.Add(bundleInfo); + } + } + return result; + } + public List GetUnpackListByTags(PackageManifest manifest, string[] tags) + { + if (manifest == null) + return new List(); + + List result = new List(1000); + foreach (var packageBundle in manifest.BundleList) + { + var fileSystem = GetBelongFileSystem(packageBundle); + if (fileSystem == null) + continue; + + if (fileSystem.NeedUnpack(packageBundle)) + { + if (packageBundle.HasTag(tags)) + { + var bundleInfo = new BundleInfo(fileSystem, packageBundle); + result.Add(bundleInfo); + } + } + } + return result; + } + public List GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths) + { + if (manifest == null) + return new List(); + + List result = new List(); + foreach (var filePath in filePaths) + { + string fileName = System.IO.Path.GetFileName(filePath); + if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle)) + { + var fileSystem = GetBelongFileSystem(packageBundle); + if (fileSystem == null) + continue; + + if (fileSystem.NeedImport(packageBundle)) + { + var bundleInfo = new BundleInfo(fileSystem, packageBundle, filePath); + result.Add(bundleInfo); + } + } + else + { + YooLogger.Warning($"Not found package bundle, importer file path : {filePath}"); + } + } + return result; + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs.meta b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeImpl.cs.meta similarity index 83% rename from Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs.meta rename to Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeImpl.cs.meta index 115c1a44..1f8c0a3f 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs.meta +++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeImpl.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: fc10550f17aaeb14795135a51444de1c +guid: 7fa439f7b3213444290b3df1af1d8140 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs deleted file mode 100644 index 957e7db8..00000000 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs +++ /dev/null @@ -1,201 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace YooAsset -{ - internal class WebPlayModeImpl : IPlayMode, IBundleQuery - { - public readonly string PackageName; - public IFileSystem WebServerFileSystem { set; get; } //可以为空! - public IFileSystem WebRemoteFileSystem { set; get; } //可以为空! - - - public WebPlayModeImpl(string packageName) - { - PackageName = packageName; - } - - /// - /// 异步初始化 - /// - public InitializationOperation InitializeAsync(WebPlayModeParameters initParameters) - { - var operation = new WebPlayModeInitializationOperation(this, initParameters); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - - #region IPlayMode接口 - public PackageManifest ActiveManifest { set; get; } - - void IPlayMode.DestroyFileSystem() - { - if (WebServerFileSystem != null) - WebServerFileSystem.OnDestroy(); - - if (WebRemoteFileSystem != null) - WebRemoteFileSystem.OnDestroy(); - } - - RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout) - { - if (WebRemoteFileSystem != null) - { - var operation = new RequestPackageVersionImplOperation(WebRemoteFileSystem, appendTimeTicks, timeout); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - else - { - var operation = new RequestPackageVersionImplOperation(WebServerFileSystem, appendTimeTicks, timeout); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - } - UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, int timeout) - { - if (WebRemoteFileSystem != null) - { - var operation = new UpdatePackageManifestImplOperation(this, WebRemoteFileSystem, packageVersion, timeout); ; - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - else - { - var operation = new UpdatePackageManifestImplOperation(this, WebServerFileSystem, packageVersion, timeout); ; - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - } - PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout) - { - var operation = new WebPlayModePreDownloadContentOperation(this); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam) - { - var operation = new ClearCacheFilesImplOperation(this, WebServerFileSystem, WebRemoteFileSystem, null, clearMode, clearParam); - OperationSystem.StartOperation(PackageName, operation); - return operation; - } - - ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) - { - List downloadList = PlayModeHelper.GetDownloadListByAll(ActiveManifest, WebServerFileSystem, WebRemoteFileSystem); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - List downloadList = PlayModeHelper.GetDownloadListByTags(ActiveManifest, tags, WebServerFileSystem, WebRemoteFileSystem); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout) - { - List downloadList = PlayModeHelper.GetDownloadListByPaths(ActiveManifest, assetInfos, recursiveDownload, WebServerFileSystem, WebRemoteFileSystem); - var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout) - { - List unpcakList = PlayModeHelper.GetUnpackListByAll(ActiveManifest, WebServerFileSystem, WebRemoteFileSystem); - var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout) - { - List unpcakList = PlayModeHelper.GetUnpackListByTags(ActiveManifest, tags, WebServerFileSystem, WebRemoteFileSystem); - var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout); - return operation; - } - ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout) - { - List importerList = PlayModeHelper.GetImporterListByFilePaths(ActiveManifest, filePaths, WebServerFileSystem, WebRemoteFileSystem); - var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout); - return operation; - } - #endregion - - #region IBundleQuery接口 - private BundleInfo CreateBundleInfo(PackageBundle packageBundle, AssetInfo assetInfo) - { - if (packageBundle == null) - throw new Exception("Should never get here !"); - - if (WebServerFileSystem != null && WebServerFileSystem.Belong(packageBundle)) - { - BundleInfo bundleInfo = new BundleInfo(WebServerFileSystem, packageBundle); - return bundleInfo; - } - - if (WebRemoteFileSystem != null && WebRemoteFileSystem.Belong(packageBundle)) - { - BundleInfo bundleInfo = new BundleInfo(WebRemoteFileSystem, packageBundle); - return bundleInfo; - } - - throw new Exception($"Can not found belong file system : {packageBundle.BundleName}"); - } - BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - throw new Exception("Should never get here !"); - - // 注意:如果清单里未找到资源包会抛出异常! - var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath); - return CreateBundleInfo(packageBundle, assetInfo); - } - BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - throw new Exception("Should never get here !"); - - // 注意:如果清单里未找到资源包会抛出异常! - var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath); - List result = new List(depends.Length); - foreach (var packageBundle in depends) - { - BundleInfo bundleInfo = CreateBundleInfo(packageBundle, assetInfo); - result.Add(bundleInfo); - } - return result.ToArray(); - } - string IBundleQuery.GetMainBundleName(int bundleID) - { - // 注意:如果清单里未找到资源包会抛出异常! - var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID); - return packageBundle.BundleName; - } - string IBundleQuery.GetMainBundleName(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - throw new Exception("Should never get here !"); - - // 注意:如果清单里未找到资源包会抛出异常! - var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath); - return packageBundle.BundleName; - } - string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo) - { - if (assetInfo.IsInvalid) - throw new Exception("Should never get here !"); - - // 注意:如果清单里未找到资源包会抛出异常! - var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath); - List result = new List(depends.Length); - foreach (var packageBundle in depends) - { - result.Add(packageBundle.BundleName); - } - return result.ToArray(); - } - bool IBundleQuery.ManifestValid() - { - return ActiveManifest != null; - } - #endregion - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs.meta b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs.meta deleted file mode 100644 index a4b003af..00000000 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: fa7d8823ee040534db067e6e2c254267 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs index 93007c40..0f62fe4e 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs @@ -95,48 +95,39 @@ namespace YooAsset _resourceManager = null; } - // 创建资源管理器 - InitializationOperation initializeOperation; + // 创建资源管理器 _resourceManager = new ResourceManager(PackageName); + var playModeImpl = new PlayModeImpl(PackageName); + _bundleQuery = playModeImpl; + _playModeImpl = playModeImpl; + _resourceManager.Initialize(_bundleQuery); + + // 初始化资源系统 + InitializationOperation initializeOperation; if (_playMode == EPlayMode.EditorSimulateMode) { - var editorSimulateModeImpl = new EditorSimulateModeImpl(PackageName); - _bundleQuery = editorSimulateModeImpl; - _playModeImpl = editorSimulateModeImpl; - _resourceManager.Initialize(parameters, _bundleQuery); - var initializeParameters = parameters as EditorSimulateModeParameters; - initializeOperation = editorSimulateModeImpl.InitializeAsync(initializeParameters); + initializeOperation = playModeImpl.InitializeAsync(initializeParameters.EditorFileSystemParameters); } else if (_playMode == EPlayMode.OfflinePlayMode) { - var offlinePlayModeImpl = new OfflinePlayModeImpl(PackageName); - _bundleQuery = offlinePlayModeImpl; - _playModeImpl = offlinePlayModeImpl; - _resourceManager.Initialize(parameters, _bundleQuery); - var initializeParameters = parameters as OfflinePlayModeParameters; - initializeOperation = offlinePlayModeImpl.InitializeAsync(initializeParameters); + initializeOperation = playModeImpl.InitializeAsync(initializeParameters.BuildinFileSystemParameters); } else if (_playMode == EPlayMode.HostPlayMode) { - var hostPlayModeImpl = new HostPlayModeImpl(PackageName); - _bundleQuery = hostPlayModeImpl; - _playModeImpl = hostPlayModeImpl; - _resourceManager.Initialize(parameters, _bundleQuery); - var initializeParameters = parameters as HostPlayModeParameters; - initializeOperation = hostPlayModeImpl.InitializeAsync(initializeParameters); + initializeOperation = playModeImpl.InitializeAsync(initializeParameters.BuildinFileSystemParameters, initializeParameters.CacheFileSystemParameters); } else if (_playMode == EPlayMode.WebPlayMode) { - var webPlayModeImpl = new WebPlayModeImpl(PackageName); - _bundleQuery = webPlayModeImpl; - _playModeImpl = webPlayModeImpl; - _resourceManager.Initialize(parameters, _bundleQuery); - var initializeParameters = parameters as WebPlayModeParameters; - initializeOperation = webPlayModeImpl.InitializeAsync(initializeParameters); + initializeOperation = playModeImpl.InitializeAsync(initializeParameters.WebServerFileSystemParameters, initializeParameters.WebRemoteFileSystemParameters); + } + else if (_playMode == EPlayMode.CustomPlayMode) + { + var initializeParameters = parameters as CustomPlayModeParameters; + initializeOperation = playModeImpl.InitializeAsync(initializeParameters.FileSystemParameterList); } else { @@ -179,6 +170,8 @@ namespace YooAsset _playMode = EPlayMode.HostPlayMode; else if (parameters is WebPlayModeParameters) _playMode = EPlayMode.WebPlayMode; + else if (parameters is CustomPlayModeParameters) + _playMode = EPlayMode.CustomPlayMode; else throw new NotImplementedException();