From f73abba79f63276d4b588dc2ab22c67af10fdd77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Wed, 11 Dec 2024 18:19:09 +0800 Subject: [PATCH] feat : web play mode support remote services MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WebPlayMode支持跨域加载。 --- .../DefaultWebRemoteFileSystem.meta | 8 + .../DefaultWebRemoteFileSystem.cs | 162 ++++++++++++++++++ .../DefaultWebRemoteFileSystem.cs.meta | 11 ++ .../DefaultWebRemoteFileSystem/Operation.meta | 8 + .../Operation/DWRFSInitializeOperation.cs | 20 +++ .../DWRFSInitializeOperation.cs.meta | 11 ++ .../Operation/DWRFSLoadBundleOperation.cs | 83 +++++++++ .../DWRFSLoadBundleOperation.cs.meta | 11 ++ .../DWRFSLoadPackageManifestOperation.cs} | 45 ++--- .../DWRFSLoadPackageManifestOperation.cs.meta | 11 ++ .../DWRFSRequestPackageVersionOperation.cs | 62 +++++++ ...WRFSRequestPackageVersionOperation.cs.meta | 11 ++ .../Operation/internal.meta | 8 + .../LoadWebRemotePackageManifestOperation.cs | 122 +++++++++++++ ...dWebRemotePackageManifestOperation.cs.meta | 11 ++ .../RequestWebRemotePackageHashOperation.cs | 90 ++++++++++ ...questWebRemotePackageHashOperation.cs.meta | 11 ++ ...RequestWebRemotePackageVersionOperation.cs | 98 +++++++++++ ...stWebRemotePackageVersionOperation.cs.meta | 11 ++ ...m.meta => DefaultWebServerFileSystem.meta} | 0 .../DefaultWebServerFileSystem.cs} | 14 +- .../DefaultWebServerFileSystem.cs.meta} | 0 .../Operation.meta | 0 .../Operation/DWSFSInitializeOperation.cs} | 10 +- .../DWSFSInitializeOperation.cs.meta} | 0 .../Operation/DWSFSLoadBundleOperation.cs} | 8 +- .../DWSFSLoadBundleOperation.cs.meta} | 0 .../DWSFSLoadPackageManifestOperation.cs | 88 ++++++++++ ...DWSFSLoadPackageManifestOperation.cs.meta} | 0 .../DWSFSRequestPackageVersionOperation.cs} | 10 +- ...SFSRequestPackageVersionOperation.cs.meta} | 0 .../Operation/internal.meta | 0 .../LoadWebServerCatalogFileOperation.cs} | 12 +- ...LoadWebServerCatalogFileOperation.cs.meta} | 0 .../LoadWebServerPackageManifestOperation.cs} | 8 +- ...WebServerPackageManifestOperation.cs.meta} | 0 .../RequestWebServerPackageHashOperation.cs} | 8 +- ...uestWebServerPackageHashOperation.cs.meta} | 0 ...equestWebServerPackageVersionOperation.cs} | 8 +- ...tWebServerPackageVersionOperation.cs.meta} | 0 .../DownloadHandlerAssetBundleOperation.cs | 8 +- ...ownloadHandlerAssetBundleOperation.cs.meta | 0 .../YooAsset/Runtime/InitializeParameters.cs | 5 +- .../Operation/InitializationOperation.cs | 101 ++++++++--- .../PlayMode/WebPlayModeImpl.cs | 66 +++++-- .../ResourcePackage/ResourcePackage.cs | 18 +- 46 files changed, 1033 insertions(+), 125 deletions(-) create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem.meta create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/DefaultWebRemoteFileSystem.cs create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/DefaultWebRemoteFileSystem.cs.meta create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation.meta create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSInitializeOperation.cs create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSInitializeOperation.cs.meta create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadBundleOperation.cs create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadBundleOperation.cs.meta rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/DWFSLoadPackageManifestOperation.cs => DefaultWebRemoteFileSystem/Operation/DWRFSLoadPackageManifestOperation.cs} (55%) create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadPackageManifestOperation.cs.meta create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSRequestPackageVersionOperation.cs create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSRequestPackageVersionOperation.cs.meta create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal.meta create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/LoadWebRemotePackageManifestOperation.cs create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/LoadWebRemotePackageManifestOperation.cs.meta create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/RequestWebRemotePackageHashOperation.cs create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/RequestWebRemotePackageHashOperation.cs.meta create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/RequestWebRemotePackageVersionOperation.cs create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/RequestWebRemotePackageVersionOperation.cs.meta rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem.meta => DefaultWebServerFileSystem.meta} (100%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/DefaultWebFileSystem.cs => DefaultWebServerFileSystem/DefaultWebServerFileSystem.cs} (93%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/DefaultWebFileSystem.cs.meta => DefaultWebServerFileSystem/DefaultWebServerFileSystem.cs.meta} (100%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem => DefaultWebServerFileSystem}/Operation.meta (100%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/DWFSInitializeOperation.cs => DefaultWebServerFileSystem/Operation/DWSFSInitializeOperation.cs} (81%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/DWFSInitializeOperation.cs.meta => DefaultWebServerFileSystem/Operation/DWSFSInitializeOperation.cs.meta} (100%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/DWFSLoadBundleOperation.cs => DefaultWebServerFileSystem/Operation/DWSFSLoadBundleOperation.cs} (89%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/DWFSLoadBundleOperation.cs.meta => DefaultWebServerFileSystem/Operation/DWSFSLoadBundleOperation.cs.meta} (100%) create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSLoadPackageManifestOperation.cs rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/DWFSLoadPackageManifestOperation.cs.meta => DefaultWebServerFileSystem/Operation/DWSFSLoadPackageManifestOperation.cs.meta} (100%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/DWFSRequestPackageVersionOperation.cs => DefaultWebServerFileSystem/Operation/DWSFSRequestPackageVersionOperation.cs} (80%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/DWFSRequestPackageVersionOperation.cs.meta => DefaultWebServerFileSystem/Operation/DWSFSRequestPackageVersionOperation.cs.meta} (100%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem => DefaultWebServerFileSystem}/Operation/internal.meta (100%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/internal/LoadWebCatalogFileOperation.cs => DefaultWebServerFileSystem/Operation/internal/LoadWebServerCatalogFileOperation.cs} (76%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/internal/LoadWebCatalogFileOperation.cs.meta => DefaultWebServerFileSystem/Operation/internal/LoadWebServerCatalogFileOperation.cs.meta} (100%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/internal/LoadWebPackageManifestOperation.cs => DefaultWebServerFileSystem/Operation/internal/LoadWebServerPackageManifestOperation.cs} (90%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/internal/LoadWebPackageManifestOperation.cs.meta => DefaultWebServerFileSystem/Operation/internal/LoadWebServerPackageManifestOperation.cs.meta} (100%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/internal/RequestWebPackageHashOperation.cs => DefaultWebServerFileSystem/Operation/internal/RequestWebServerPackageHashOperation.cs} (86%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/internal/RequestWebPackageHashOperation.cs.meta => DefaultWebServerFileSystem/Operation/internal/RequestWebServerPackageHashOperation.cs.meta} (100%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/internal/RequestWebPackageVersionOperation.cs => DefaultWebServerFileSystem/Operation/internal/RequestWebServerPackageVersionOperation.cs} (86%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/internal/RequestWebPackageVersionOperation.cs.meta => DefaultWebServerFileSystem/Operation/internal/RequestWebServerPackageVersionOperation.cs.meta} (100%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/internal => Operation/Internal}/DownloadHandlerAssetBundleOperation.cs (93%) rename Assets/YooAsset/Runtime/FileSystem/{DefaultWebFileSystem/Operation/internal => Operation/Internal}/DownloadHandlerAssetBundleOperation.cs.meta (100%) diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem.meta new file mode 100644 index 0000000..8e32bad --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2bf1355f3cbe3d543b53bd9553bba02c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/DefaultWebRemoteFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/DefaultWebRemoteFileSystem.cs new file mode 100644 index 0000000..038e856 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/DefaultWebRemoteFileSystem.cs @@ -0,0 +1,162 @@ +using System; +using System.IO; +using System.Collections.Generic; +using UnityEngine; + +namespace YooAsset +{ + /// + /// Web文件系统 + /// + internal class DefaultWebRemoteFileSystem : IFileSystem + { + /// + /// 包裹名称 + /// + public string PackageName { private set; get; } + + /// + /// 文件根目录 + /// + public string FileRoot + { + get + { + return string.Empty; + } + } + + /// + /// 文件数量 + /// + public int FileCount + { + get + { + return 0; + } + } + + #region 自定义参数 + /// + /// 禁用Unity的网络缓存 + /// + public bool DisableUnityWebCache { private set; get; } = false; + + /// + /// 自定义参数:跨域下载服务接口 + /// + public IRemoteServices RemoteServices { private set; get; } = null; + #endregion + + + public DefaultWebRemoteFileSystem() + { + } + public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync() + { + var operation = new DWRFSInitializeOperation(this); + OperationSystem.StartOperation(PackageName, operation); + return operation; + } + public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout) + { + var operation = new DWRFSLoadPackageManifestOperation(this, packageVersion, timeout); + OperationSystem.StartOperation(PackageName, operation); + return operation; + } + public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout) + { + var operation = new DWRFSRequestPackageVersionOperation(this, appendTimeTicks, timeout); + OperationSystem.StartOperation(PackageName, operation); + return operation; + } + public virtual FSClearAllBundleFilesOperation ClearAllBundleFilesAsync() + { + var operation = new FSClearAllBundleFilesCompleteOperation(); + OperationSystem.StartOperation(PackageName, operation); + return operation; + } + public virtual FSClearUnusedBundleFilesOperation ClearUnusedBundleFilesAsync(PackageManifest manifest) + { + var operation = new FSClearUnusedBundleFilesCompleteOperation(); + OperationSystem.StartOperation(PackageName, operation); + return operation; + } + public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadParam param) + { + throw new System.NotImplementedException(); + } + public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle) + { + var operation = new DWRFSLoadAssetBundleOperation(this, bundle); + OperationSystem.StartOperation(PackageName, operation); + return operation; + } + public virtual void UnloadBundleFile(PackageBundle bundle, object result) + { + AssetBundle assetBundle = result as AssetBundle; + if (assetBundle == null) + return; + + if (assetBundle != null) + assetBundle.Unload(true); + } + + public virtual void SetParameter(string name, object value) + { + if (name == FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE) + { + DisableUnityWebCache = (bool)value; + } + else if (name == FileSystemParametersDefine.REMOTE_SERVICES) + { + RemoteServices = (IRemoteServices)value; + } + else + { + YooLogger.Warning($"Invalid parameter : {name}"); + } + } + public virtual void OnCreate(string packageName, string rootDirectory) + { + PackageName = packageName; + } + public virtual void OnUpdate() + { + } + + public virtual bool Belong(PackageBundle bundle) + { + return true; + } + public virtual bool Exists(PackageBundle bundle) + { + return true; + } + public virtual bool NeedDownload(PackageBundle bundle) + { + return false; + } + public virtual bool NeedUnpack(PackageBundle bundle) + { + return false; + } + public virtual bool NeedImport(PackageBundle bundle) + { + return false; + } + + public virtual byte[] ReadFileData(PackageBundle bundle) + { + throw new System.NotImplementedException(); + } + public virtual string ReadFileText(PackageBundle bundle) + { + throw new System.NotImplementedException(); + } + + #region 内部方法 + #endregion + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/DefaultWebRemoteFileSystem.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/DefaultWebRemoteFileSystem.cs.meta new file mode 100644 index 0000000..9b19d12 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/DefaultWebRemoteFileSystem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f511714bfc7c1104aa6200ee0826e9e3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation.meta new file mode 100644 index 0000000..e8afc8b --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1086ea45b8b84fe43ba1ef69b4f813dc +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSInitializeOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSInitializeOperation.cs new file mode 100644 index 0000000..20328f4 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSInitializeOperation.cs @@ -0,0 +1,20 @@ + +namespace YooAsset +{ + internal class DWRFSInitializeOperation : FSInitializeFileSystemOperation + { + private readonly DefaultWebRemoteFileSystem _fileSystem; + + public DWRFSInitializeOperation(DefaultWebRemoteFileSystem fileSystem) + { + _fileSystem = fileSystem; + } + internal override void InternalOnStart() + { + Status = EOperationStatus.Succeed; + } + internal override void InternalOnUpdate() + { + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSInitializeOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSInitializeOperation.cs.meta new file mode 100644 index 0000000..ec72428 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSInitializeOperation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f30b92e4f3b9e594ca0481128b56cc21 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadBundleOperation.cs new file mode 100644 index 0000000..884b86a --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadBundleOperation.cs @@ -0,0 +1,83 @@ + +namespace YooAsset +{ + internal class DWRFSLoadAssetBundleOperation : FSLoadBundleOperation + { + private enum ESteps + { + None, + DownloadFile, + Done, + } + + private readonly DefaultWebRemoteFileSystem _fileSystem; + private readonly PackageBundle _bundle; + private DownloadHandlerAssetBundleOperation _downloadhanlderAssetBundleOp; + private ESteps _steps = ESteps.None; + + + internal DWRFSLoadAssetBundleOperation(DefaultWebRemoteFileSystem fileSystem, PackageBundle bundle) + { + _fileSystem = fileSystem; + _bundle = bundle; + } + internal override void InternalOnStart() + { + _steps = ESteps.DownloadFile; + } + internal override void InternalOnUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.DownloadFile) + { + if (_downloadhanlderAssetBundleOp == null) + { + DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60); + downloadParam.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName); + downloadParam.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName); + _downloadhanlderAssetBundleOp = new DownloadHandlerAssetBundleOperation(_fileSystem.DisableUnityWebCache, _bundle, downloadParam); + OperationSystem.StartOperation(_fileSystem.PackageName, _downloadhanlderAssetBundleOp); + } + + DownloadProgress = _downloadhanlderAssetBundleOp.DownloadProgress; + DownloadedBytes = _downloadhanlderAssetBundleOp.DownloadedBytes; + Progress = _downloadhanlderAssetBundleOp.Progress; + if (_downloadhanlderAssetBundleOp.IsDone == false) + return; + + if (_downloadhanlderAssetBundleOp.Status == EOperationStatus.Succeed) + { + _steps = ESteps.Done; + Result = _downloadhanlderAssetBundleOp.Result; + Status = EOperationStatus.Succeed; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _downloadhanlderAssetBundleOp.Error; + } + } + } + internal override void InternalWaitForAsyncComplete() + { + if (_steps != ESteps.Done) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = "WebGL platform not support sync load method !"; + UnityEngine.Debug.LogError(Error); + } + } + public override void AbortDownloadOperation() + { + if (_steps == ESteps.DownloadFile) + { + if (_downloadhanlderAssetBundleOp != null) + _downloadhanlderAssetBundleOp.SetAbort(); + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadBundleOperation.cs.meta new file mode 100644 index 0000000..0295664 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadBundleOperation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 270b776fd379b0f45bc602c845720733 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSLoadPackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadPackageManifestOperation.cs similarity index 55% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSLoadPackageManifestOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadPackageManifestOperation.cs index 1752115..6691f63 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSLoadPackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadPackageManifestOperation.cs @@ -1,68 +1,44 @@  namespace YooAsset { - internal class DWFSLoadPackageManifestOperation : FSLoadPackageManifestOperation + internal class DWRFSLoadPackageManifestOperation : FSLoadPackageManifestOperation { private enum ESteps { None, - RequestWebPackageVersion, RequestWebPackageHash, LoadWebPackageManifest, Done, } - private readonly DefaultWebFileSystem _fileSystem; + private readonly DefaultWebRemoteFileSystem _fileSystem; + private readonly string _packageVersion; private readonly int _timeout; - private RequestWebPackageVersionOperation _requestWebPackageVersionOp; - private RequestWebPackageHashOperation _requestWebPackageHashOp; - private LoadWebPackageManifestOperation _loadWebPackageManifestOp; + private RequestWebRemotePackageHashOperation _requestWebPackageHashOp; + private LoadWebRemotePackageManifestOperation _loadWebPackageManifestOp; private ESteps _steps = ESteps.None; - public DWFSLoadPackageManifestOperation(DefaultWebFileSystem fileSystem, int timeout) + public DWRFSLoadPackageManifestOperation(DefaultWebRemoteFileSystem fileSystem, string packageVersion, int timeout) { _fileSystem = fileSystem; + _packageVersion = packageVersion; _timeout = timeout; } internal override void InternalOnStart() { - _steps = ESteps.RequestWebPackageVersion; + _steps = ESteps.RequestWebPackageHash; } internal override void InternalOnUpdate() { if (_steps == ESteps.None || _steps == ESteps.Done) return; - if (_steps == ESteps.RequestWebPackageVersion) - { - if (_requestWebPackageVersionOp == null) - { - _requestWebPackageVersionOp = new RequestWebPackageVersionOperation(_fileSystem, _timeout); - OperationSystem.StartOperation(_fileSystem.PackageName, _requestWebPackageVersionOp); - } - - if (_requestWebPackageVersionOp.IsDone == false) - return; - - if (_requestWebPackageVersionOp.Status == EOperationStatus.Succeed) - { - _steps = ESteps.RequestWebPackageHash; - } - else - { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = _requestWebPackageVersionOp.Error; - } - } - if (_steps == ESteps.RequestWebPackageHash) { if (_requestWebPackageHashOp == null) { - string packageVersion = _requestWebPackageVersionOp.PackageVersion; - _requestWebPackageHashOp = new RequestWebPackageHashOperation(_fileSystem, packageVersion, _timeout); + _requestWebPackageHashOp = new RequestWebRemotePackageHashOperation(_fileSystem, _packageVersion, _timeout); OperationSystem.StartOperation(_fileSystem.PackageName, _requestWebPackageHashOp); } @@ -85,9 +61,8 @@ namespace YooAsset { if (_loadWebPackageManifestOp == null) { - string packageVersion = _requestWebPackageVersionOp.PackageVersion; string packageHash = _requestWebPackageHashOp.PackageHash; - _loadWebPackageManifestOp = new LoadWebPackageManifestOperation(_fileSystem, packageVersion, packageHash); + _loadWebPackageManifestOp = new LoadWebRemotePackageManifestOperation(_fileSystem, _packageVersion, packageHash); OperationSystem.StartOperation(_fileSystem.PackageName, _loadWebPackageManifestOp); } diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadPackageManifestOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadPackageManifestOperation.cs.meta new file mode 100644 index 0000000..0b4295e --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSLoadPackageManifestOperation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2611f6fbc97de1a4d9a38116045d4faf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSRequestPackageVersionOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSRequestPackageVersionOperation.cs new file mode 100644 index 0000000..1b1c9f3 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSRequestPackageVersionOperation.cs @@ -0,0 +1,62 @@ + +namespace YooAsset +{ + internal class DWRFSRequestPackageVersionOperation : FSRequestPackageVersionOperation + { + private enum ESteps + { + None, + RequestPackageVersion, + Done, + } + + private readonly DefaultWebRemoteFileSystem _fileSystem; + private readonly bool _appendTimeTicks; + private readonly int _timeout; + private RequestWebRemotePackageVersionOperation _requestWebPackageVersionOp; + private ESteps _steps = ESteps.None; + + + internal DWRFSRequestPackageVersionOperation(DefaultWebRemoteFileSystem fileSystem, bool appendTimeTicks, int timeout) + { + _fileSystem = fileSystem; + _appendTimeTicks = appendTimeTicks; + _timeout = timeout; + } + internal override void InternalOnStart() + { + _steps = ESteps.RequestPackageVersion; + } + internal override void InternalOnUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.RequestPackageVersion) + { + if (_requestWebPackageVersionOp == null) + { + _requestWebPackageVersionOp = new RequestWebRemotePackageVersionOperation(_fileSystem, _appendTimeTicks, _timeout); + OperationSystem.StartOperation(_fileSystem.PackageName, _requestWebPackageVersionOp); + } + + Progress = _requestWebPackageVersionOp.Progress; + if (_requestWebPackageVersionOp.IsDone == false) + return; + + if (_requestWebPackageVersionOp.Status == EOperationStatus.Succeed) + { + _steps = ESteps.Done; + PackageVersion = _requestWebPackageVersionOp.PackageVersion; + Status = EOperationStatus.Succeed; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _requestWebPackageVersionOp.Error; + } + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSRequestPackageVersionOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSRequestPackageVersionOperation.cs.meta new file mode 100644 index 0000000..905dbaa --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/DWRFSRequestPackageVersionOperation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d1c5335974b2432458ed902e20cc954e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal.meta new file mode 100644 index 0000000..c24d382 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9be3163f53935514d9e64e09686db957 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/LoadWebRemotePackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/LoadWebRemotePackageManifestOperation.cs new file mode 100644 index 0000000..a715e0f --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/LoadWebRemotePackageManifestOperation.cs @@ -0,0 +1,122 @@ + +namespace YooAsset +{ + internal class LoadWebRemotePackageManifestOperation : AsyncOperationBase + { + private enum ESteps + { + None, + RequestFileData, + VerifyFileData, + LoadManifest, + Done, + } + + private readonly DefaultWebRemoteFileSystem _fileSystem; + private readonly string _packageVersion; + private readonly string _packageHash; + private UnityWebDataRequestOperation _webDataRequestOp; + private DeserializeManifestOperation _deserializer; + private int _requestCount = 0; + private ESteps _steps = ESteps.None; + + /// + /// 包裹清单 + /// + public PackageManifest Manifest { private set; get; } + + + internal LoadWebRemotePackageManifestOperation(DefaultWebRemoteFileSystem fileSystem, string packageVersion, string packageHash) + { + _fileSystem = fileSystem; + _packageVersion = packageVersion; + _packageHash = packageHash; + } + internal override void InternalOnStart() + { + _requestCount = WebRequestCounter.GetRequestFailedCount(_fileSystem.PackageName, nameof(LoadWebRemotePackageManifestOperation)); + _steps = ESteps.RequestFileData; + } + internal override void InternalOnUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.RequestFileData) + { + if (_webDataRequestOp == null) + { + string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_fileSystem.PackageName, _packageVersion); + string url = GetWebRequestURL(fileName); + _webDataRequestOp = new UnityWebDataRequestOperation(url); + OperationSystem.StartOperation(_fileSystem.PackageName, _webDataRequestOp); + } + + if (_webDataRequestOp.IsDone == false) + return; + + if (_webDataRequestOp.Status == EOperationStatus.Succeed) + { + _steps = ESteps.VerifyFileData; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _webDataRequestOp.Error; + WebRequestCounter.RecordRequestFailed(_fileSystem.PackageName, nameof(LoadWebRemotePackageManifestOperation)); + } + } + + if (_steps == ESteps.VerifyFileData) + { + string fileHash = HashUtility.BytesMD5(_webDataRequestOp.Result); + if (fileHash == _packageHash) + { + _steps = ESteps.LoadManifest; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = "Failed to verify web remote package manifest file!"; + } + } + + if (_steps == ESteps.LoadManifest) + { + if (_deserializer == null) + { + _deserializer = new DeserializeManifestOperation(_webDataRequestOp.Result); + OperationSystem.StartOperation(_fileSystem.PackageName, _deserializer); + } + + Progress = _deserializer.Progress; + if (_deserializer.IsDone == false) + return; + + if (_deserializer.Status == EOperationStatus.Succeed) + { + _steps = ESteps.Done; + Manifest = _deserializer.Manifest; + Status = EOperationStatus.Succeed; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _deserializer.Error; + } + } + } + + private string GetWebRequestURL(string fileName) + { + // 轮流返回请求地址 + if (_requestCount % 2 == 0) + return _fileSystem.RemoteServices.GetRemoteMainURL(fileName); + else + return _fileSystem.RemoteServices.GetRemoteFallbackURL(fileName); + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/LoadWebRemotePackageManifestOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/LoadWebRemotePackageManifestOperation.cs.meta new file mode 100644 index 0000000..fd09c87 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/LoadWebRemotePackageManifestOperation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8ac57bde14f2e1a4e9323751a7157ed7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/RequestWebRemotePackageHashOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/RequestWebRemotePackageHashOperation.cs new file mode 100644 index 0000000..9a0dbda --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/RequestWebRemotePackageHashOperation.cs @@ -0,0 +1,90 @@ + +namespace YooAsset +{ + internal class RequestWebRemotePackageHashOperation : AsyncOperationBase + { + private enum ESteps + { + None, + RequestPackageHash, + Done, + } + + private readonly DefaultWebRemoteFileSystem _fileSystem; + private readonly string _packageVersion; + private readonly int _timeout; + private UnityWebTextRequestOperation _webTextRequestOp; + private int _requestCount = 0; + private ESteps _steps = ESteps.None; + + /// + /// 包裹哈希值 + /// + public string PackageHash { private set; get; } + + + public RequestWebRemotePackageHashOperation(DefaultWebRemoteFileSystem fileSystem, string packageVersion, int timeout) + { + _fileSystem = fileSystem; + _packageVersion = packageVersion; + _timeout = timeout; + } + internal override void InternalOnStart() + { + _requestCount = WebRequestCounter.GetRequestFailedCount(_fileSystem.PackageName, nameof(RequestWebRemotePackageHashOperation)); + _steps = ESteps.RequestPackageHash; + } + internal override void InternalOnUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.RequestPackageHash) + { + if (_webTextRequestOp == null) + { + string fileName = YooAssetSettingsData.GetPackageHashFileName(_fileSystem.PackageName, _packageVersion); + string url = GetWebRequestURL(fileName); + _webTextRequestOp = new UnityWebTextRequestOperation(url, _timeout); + OperationSystem.StartOperation(_fileSystem.PackageName, _webTextRequestOp); + } + + Progress = _webTextRequestOp.Progress; + if (_webTextRequestOp.IsDone == false) + return; + + if (_webTextRequestOp.Status == EOperationStatus.Succeed) + { + PackageHash = _webTextRequestOp.Result; + if (string.IsNullOrEmpty(PackageHash)) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"Web remote package hash file content is empty !"; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Succeed; + } + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _webTextRequestOp.Error; + WebRequestCounter.RecordRequestFailed(_fileSystem.PackageName, nameof(RequestWebRemotePackageHashOperation)); + } + } + } + + private string GetWebRequestURL(string fileName) + { + // 轮流返回请求地址 + if (_requestCount % 2 == 0) + return _fileSystem.RemoteServices.GetRemoteMainURL(fileName); + else + return _fileSystem.RemoteServices.GetRemoteFallbackURL(fileName); + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/RequestWebRemotePackageHashOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/RequestWebRemotePackageHashOperation.cs.meta new file mode 100644 index 0000000..ecc02a7 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/RequestWebRemotePackageHashOperation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f2a5bb0106a45e540a43a05b72a75bcd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/RequestWebRemotePackageVersionOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/RequestWebRemotePackageVersionOperation.cs new file mode 100644 index 0000000..1e14492 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/RequestWebRemotePackageVersionOperation.cs @@ -0,0 +1,98 @@ + +namespace YooAsset +{ + internal class RequestWebRemotePackageVersionOperation : AsyncOperationBase + { + private enum ESteps + { + None, + RequestPackageVersion, + Done, + } + + private readonly DefaultWebRemoteFileSystem _fileSystem; + private readonly bool _appendTimeTicks; + private readonly int _timeout; + private UnityWebTextRequestOperation _webTextRequestOp; + private int _requestCount = 0; + private ESteps _steps = ESteps.None; + + /// + /// 包裹版本 + /// + public string PackageVersion { private set; get; } + + + internal RequestWebRemotePackageVersionOperation(DefaultWebRemoteFileSystem fileSystem, bool appendTimeTicks, int timeout) + { + _fileSystem = fileSystem; + _appendTimeTicks = appendTimeTicks; + _timeout = timeout; + } + internal override void InternalOnStart() + { + _requestCount = WebRequestCounter.GetRequestFailedCount(_fileSystem.PackageName, nameof(RequestWebRemotePackageVersionOperation)); + _steps = ESteps.RequestPackageVersion; + } + internal override void InternalOnUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.RequestPackageVersion) + { + if (_webTextRequestOp == null) + { + string fileName = YooAssetSettingsData.GetPackageVersionFileName(_fileSystem.PackageName); + string url = GetWebRequestURL(fileName); + _webTextRequestOp = new UnityWebTextRequestOperation(url, _timeout); + OperationSystem.StartOperation(_fileSystem.PackageName, _webTextRequestOp); + } + + Progress = _webTextRequestOp.Progress; + if (_webTextRequestOp.IsDone == false) + return; + + if (_webTextRequestOp.Status == EOperationStatus.Succeed) + { + PackageVersion = _webTextRequestOp.Result; + if (string.IsNullOrEmpty(PackageVersion)) + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"Web remote package version file content is empty !"; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Succeed; + } + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _webTextRequestOp.Error; + WebRequestCounter.RecordRequestFailed(_fileSystem.PackageName, nameof(RequestWebRemotePackageVersionOperation)); + } + } + } + + private string GetWebRequestURL(string fileName) + { + string url; + + // 轮流返回请求地址 + if (_requestCount % 2 == 0) + url = _fileSystem.RemoteServices.GetRemoteMainURL(fileName); + else + url = _fileSystem.RemoteServices.GetRemoteFallbackURL(fileName); + + // 在URL末尾添加时间戳 + if (_appendTimeTicks) + return $"{url}?{System.DateTime.UtcNow.Ticks}"; + else + return url; + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/RequestWebRemotePackageVersionOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/RequestWebRemotePackageVersionOperation.cs.meta new file mode 100644 index 0000000..717217f --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebRemoteFileSystem/Operation/internal/RequestWebRemotePackageVersionOperation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9a38597f546a46a429b24abd595c76e4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem.meta rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/DefaultWebFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/DefaultWebServerFileSystem.cs similarity index 93% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/DefaultWebFileSystem.cs rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/DefaultWebServerFileSystem.cs index f2da0eb..24c4a81 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/DefaultWebFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/DefaultWebServerFileSystem.cs @@ -8,7 +8,7 @@ namespace YooAsset /// /// Web文件系统 /// - internal class DefaultWebFileSystem : IFileSystem + internal class DefaultWebServerFileSystem : IFileSystem { public class FileWrapper { @@ -59,24 +59,24 @@ namespace YooAsset #endregion - public DefaultWebFileSystem() + public DefaultWebServerFileSystem() { } public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync() { - var operation = new DWFSInitializeOperation(this); + var operation = new DWSFSInitializeOperation(this); OperationSystem.StartOperation(PackageName, operation); return operation; } public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout) { - var operation = new DWFSLoadPackageManifestOperation(this, timeout); + var operation = new DWSFSLoadPackageManifestOperation(this, packageVersion, timeout); OperationSystem.StartOperation(PackageName, operation); return operation; } public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout) { - var operation = new DWFSRequestPackageVersionOperation(this, timeout); + var operation = new DWSFSRequestPackageVersionOperation(this, timeout); OperationSystem.StartOperation(PackageName, operation); return operation; } @@ -98,7 +98,7 @@ namespace YooAsset } public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle) { - var operation = new DWFSLoadAssetBundleOperation(this, bundle); + var operation = new DWSFSLoadAssetBundleOperation(this, bundle); OperationSystem.StartOperation(PackageName, operation); return operation; } @@ -214,7 +214,7 @@ namespace YooAsset { if (_wrappers.ContainsKey(bundleGUID)) { - YooLogger.Error($"{nameof(DefaultWebFileSystem)} has element : {bundleGUID}"); + YooLogger.Error($"{nameof(DefaultWebServerFileSystem)} has element : {bundleGUID}"); return false; } diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/DefaultWebFileSystem.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/DefaultWebServerFileSystem.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/DefaultWebFileSystem.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/DefaultWebServerFileSystem.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation.meta rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSInitializeOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSInitializeOperation.cs similarity index 81% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSInitializeOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSInitializeOperation.cs index 7196d1b..f9c2df4 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSInitializeOperation.cs @@ -1,7 +1,7 @@  namespace YooAsset { - internal class DWFSInitializeOperation : FSInitializeFileSystemOperation + internal class DWSFSInitializeOperation : FSInitializeFileSystemOperation { private enum ESteps { @@ -10,12 +10,12 @@ namespace YooAsset Done, } - private readonly DefaultWebFileSystem _fileSystem; - private LoadWebCatalogFileOperation _loadCatalogFileOp; + private readonly DefaultWebServerFileSystem _fileSystem; + private LoadWebServerCatalogFileOperation _loadCatalogFileOp; private ESteps _steps = ESteps.None; - public DWFSInitializeOperation(DefaultWebFileSystem fileSystem) + public DWSFSInitializeOperation(DefaultWebServerFileSystem fileSystem) { _fileSystem = fileSystem; } @@ -39,7 +39,7 @@ namespace YooAsset DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.PackageName, packageRoot); #endif - _loadCatalogFileOp = new LoadWebCatalogFileOperation(_fileSystem); + _loadCatalogFileOp = new LoadWebServerCatalogFileOperation(_fileSystem); OperationSystem.StartOperation(_fileSystem.PackageName, _loadCatalogFileOp); } diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSInitializeOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSInitializeOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSInitializeOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSInitializeOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSLoadBundleOperation.cs similarity index 89% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSLoadBundleOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSLoadBundleOperation.cs index fe4f8f6..a0f6b11 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSLoadBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSLoadBundleOperation.cs @@ -1,7 +1,7 @@  namespace YooAsset { - internal class DWFSLoadAssetBundleOperation : FSLoadBundleOperation + internal class DWSFSLoadAssetBundleOperation : FSLoadBundleOperation { private enum ESteps { @@ -10,13 +10,13 @@ namespace YooAsset Done, } - private readonly DefaultWebFileSystem _fileSystem; + private readonly DefaultWebServerFileSystem _fileSystem; private readonly PackageBundle _bundle; private DownloadHandlerAssetBundleOperation _downloadhanlderAssetBundleOp; private ESteps _steps = ESteps.None; - internal DWFSLoadAssetBundleOperation(DefaultWebFileSystem fileSystem, PackageBundle bundle) + internal DWSFSLoadAssetBundleOperation(DefaultWebServerFileSystem fileSystem, PackageBundle bundle) { _fileSystem = fileSystem; _bundle = bundle; @@ -38,7 +38,7 @@ namespace YooAsset string fileLoadPath = _fileSystem.GetWebFileLoadPath(_bundle); downloadParam.MainURL = DownloadSystemHelper.ConvertToWWWPath(fileLoadPath); downloadParam.FallbackURL = downloadParam.MainURL; - _downloadhanlderAssetBundleOp = new DownloadHandlerAssetBundleOperation(_fileSystem, _bundle, downloadParam); + _downloadhanlderAssetBundleOp = new DownloadHandlerAssetBundleOperation(_fileSystem.DisableUnityWebCache, _bundle, downloadParam); OperationSystem.StartOperation(_fileSystem.PackageName, _downloadhanlderAssetBundleOp); } diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSLoadBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSLoadBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSLoadBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSLoadBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSLoadPackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSLoadPackageManifestOperation.cs new file mode 100644 index 0000000..1445ab1 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSLoadPackageManifestOperation.cs @@ -0,0 +1,88 @@ + +namespace YooAsset +{ + internal class DWSFSLoadPackageManifestOperation : FSLoadPackageManifestOperation + { + private enum ESteps + { + None, + RequestWebPackageHash, + LoadWebPackageManifest, + Done, + } + + private readonly DefaultWebServerFileSystem _fileSystem; + private readonly string _packageVersion; + private readonly int _timeout; + private RequestWebServerPackageHashOperation _requestWebPackageHashOp; + private LoadWebServerPackageManifestOperation _loadWebPackageManifestOp; + private ESteps _steps = ESteps.None; + + + public DWSFSLoadPackageManifestOperation(DefaultWebServerFileSystem fileSystem, string packageVersion, int timeout) + { + _fileSystem = fileSystem; + _packageVersion = packageVersion; + _timeout = timeout; + } + internal override void InternalOnStart() + { + _steps = ESteps.RequestWebPackageHash; + } + internal override void InternalOnUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.RequestWebPackageHash) + { + if (_requestWebPackageHashOp == null) + { + _requestWebPackageHashOp = new RequestWebServerPackageHashOperation(_fileSystem, _packageVersion, _timeout); + OperationSystem.StartOperation(_fileSystem.PackageName, _requestWebPackageHashOp); + } + + if (_requestWebPackageHashOp.IsDone == false) + return; + + if (_requestWebPackageHashOp.Status == EOperationStatus.Succeed) + { + _steps = ESteps.LoadWebPackageManifest; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _requestWebPackageHashOp.Error; + } + } + + if (_steps == ESteps.LoadWebPackageManifest) + { + if (_loadWebPackageManifestOp == null) + { + string packageHash = _requestWebPackageHashOp.PackageHash; + _loadWebPackageManifestOp = new LoadWebServerPackageManifestOperation(_fileSystem, _packageVersion, packageHash); + OperationSystem.StartOperation(_fileSystem.PackageName, _loadWebPackageManifestOp); + } + + Progress = _loadWebPackageManifestOp.Progress; + if (_loadWebPackageManifestOp.IsDone == false) + return; + + if (_loadWebPackageManifestOp.Status == EOperationStatus.Succeed) + { + _steps = ESteps.Done; + Manifest = _loadWebPackageManifestOp.Manifest; + Status = EOperationStatus.Succeed; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _loadWebPackageManifestOp.Error; + } + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSLoadPackageManifestOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSLoadPackageManifestOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSLoadPackageManifestOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSLoadPackageManifestOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSRequestPackageVersionOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSRequestPackageVersionOperation.cs similarity index 80% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSRequestPackageVersionOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSRequestPackageVersionOperation.cs index 00685eb..448d9bb 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSRequestPackageVersionOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSRequestPackageVersionOperation.cs @@ -1,7 +1,7 @@  namespace YooAsset { - internal class DWFSRequestPackageVersionOperation : FSRequestPackageVersionOperation + internal class DWSFSRequestPackageVersionOperation : FSRequestPackageVersionOperation { private enum ESteps { @@ -10,13 +10,13 @@ namespace YooAsset Done, } - private readonly DefaultWebFileSystem _fileSystem; + private readonly DefaultWebServerFileSystem _fileSystem; private readonly int _timeout; - private RequestWebPackageVersionOperation _requestWebPackageVersionOp; + private RequestWebServerPackageVersionOperation _requestWebPackageVersionOp; private ESteps _steps = ESteps.None; - internal DWFSRequestPackageVersionOperation(DefaultWebFileSystem fileSystem, int timeout) + internal DWSFSRequestPackageVersionOperation(DefaultWebServerFileSystem fileSystem, int timeout) { _fileSystem = fileSystem; _timeout = timeout; @@ -34,7 +34,7 @@ namespace YooAsset { if (_requestWebPackageVersionOp == null) { - _requestWebPackageVersionOp = new RequestWebPackageVersionOperation(_fileSystem, _timeout); + _requestWebPackageVersionOp = new RequestWebServerPackageVersionOperation(_fileSystem, _timeout); OperationSystem.StartOperation(_fileSystem.PackageName, _requestWebPackageVersionOp); } diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSRequestPackageVersionOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSRequestPackageVersionOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSRequestPackageVersionOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/DWSFSRequestPackageVersionOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal.meta rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/LoadWebCatalogFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/LoadWebServerCatalogFileOperation.cs similarity index 76% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/LoadWebCatalogFileOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/LoadWebServerCatalogFileOperation.cs index b3d920f..f39ebbf 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/LoadWebCatalogFileOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/LoadWebServerCatalogFileOperation.cs @@ -6,7 +6,7 @@ using UnityEngine; namespace YooAsset { - internal sealed class LoadWebCatalogFileOperation : AsyncOperationBase + internal sealed class LoadWebServerCatalogFileOperation : AsyncOperationBase { private enum ESteps { @@ -15,7 +15,7 @@ namespace YooAsset Done, } - private readonly DefaultWebFileSystem _fileSystem; + private readonly DefaultWebServerFileSystem _fileSystem; private ESteps _steps = ESteps.None; /// @@ -23,7 +23,7 @@ namespace YooAsset /// public string PackageVersion { private set; get; } - internal LoadWebCatalogFileOperation(DefaultWebFileSystem fileSystem) + internal LoadWebServerCatalogFileOperation(DefaultWebServerFileSystem fileSystem) { _fileSystem = fileSystem; } @@ -44,7 +44,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = $"Failed to load web catalog file : {catalogFilePath}"; + Error = $"Failed to load web server catalog file : {catalogFilePath}"; return; } @@ -52,14 +52,14 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = $"Web catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}"; + Error = $"Web server catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}"; return; } PackageVersion = catalog.PackageVersion; foreach (var wrapper in catalog.Wrappers) { - var fileWrapper = new DefaultWebFileSystem.FileWrapper(wrapper.FileName); + var fileWrapper = new DefaultWebServerFileSystem.FileWrapper(wrapper.FileName); _fileSystem.RecordFile(wrapper.BundleGUID, fileWrapper); } diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/LoadWebCatalogFileOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/LoadWebServerCatalogFileOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/LoadWebCatalogFileOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/LoadWebServerCatalogFileOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/LoadWebPackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/LoadWebServerPackageManifestOperation.cs similarity index 90% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/LoadWebPackageManifestOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/LoadWebServerPackageManifestOperation.cs index 6d1cff2..2d278ea 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/LoadWebPackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/LoadWebServerPackageManifestOperation.cs @@ -1,7 +1,7 @@  namespace YooAsset { - internal class LoadWebPackageManifestOperation : AsyncOperationBase + internal class LoadWebServerPackageManifestOperation : AsyncOperationBase { private enum ESteps { @@ -12,7 +12,7 @@ namespace YooAsset Done, } - private readonly DefaultWebFileSystem _fileSystem; + private readonly DefaultWebServerFileSystem _fileSystem; private readonly string _packageVersion; private readonly string _packageHash; private UnityWebDataRequestOperation _webDataRequestOp; @@ -25,7 +25,7 @@ namespace YooAsset public PackageManifest Manifest { private set; get; } - internal LoadWebPackageManifestOperation(DefaultWebFileSystem fileSystem, string packageVersion, string packageHash) + internal LoadWebServerPackageManifestOperation(DefaultWebServerFileSystem fileSystem, string packageVersion, string packageHash) { _fileSystem = fileSystem; _packageVersion = packageVersion; @@ -76,7 +76,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = "Failed to verify web package manifest file!"; + Error = "Failed to verify web server package manifest file!"; } } diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/LoadWebPackageManifestOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/LoadWebServerPackageManifestOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/LoadWebPackageManifestOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/LoadWebServerPackageManifestOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/RequestWebPackageHashOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/RequestWebServerPackageHashOperation.cs similarity index 86% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/RequestWebPackageHashOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/RequestWebServerPackageHashOperation.cs index 6467366..c2a7a58 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/RequestWebPackageHashOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/RequestWebServerPackageHashOperation.cs @@ -1,7 +1,7 @@  namespace YooAsset { - internal class RequestWebPackageHashOperation : AsyncOperationBase + internal class RequestWebServerPackageHashOperation : AsyncOperationBase { private enum ESteps { @@ -10,7 +10,7 @@ namespace YooAsset Done, } - private readonly DefaultWebFileSystem _fileSystem; + private readonly DefaultWebServerFileSystem _fileSystem; private readonly string _packageVersion; private readonly int _timeout; private UnityWebTextRequestOperation _webTextRequestOp; @@ -22,7 +22,7 @@ namespace YooAsset public string PackageHash { private set; get; } - public RequestWebPackageHashOperation(DefaultWebFileSystem fileSystem, string packageVersion, int timeout) + public RequestWebServerPackageHashOperation(DefaultWebServerFileSystem fileSystem, string packageVersion, int timeout) { _fileSystem = fileSystem; _packageVersion = packageVersion; @@ -58,7 +58,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = $"Web package hash file content is empty !"; + Error = $"Web server package hash file content is empty !"; } else { diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/RequestWebPackageHashOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/RequestWebServerPackageHashOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/RequestWebPackageHashOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/RequestWebServerPackageHashOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/RequestWebPackageVersionOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/RequestWebServerPackageVersionOperation.cs similarity index 86% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/RequestWebPackageVersionOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/RequestWebServerPackageVersionOperation.cs index c84ec91..c28a4ed 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/RequestWebPackageVersionOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/RequestWebServerPackageVersionOperation.cs @@ -1,7 +1,7 @@  namespace YooAsset { - internal class RequestWebPackageVersionOperation : AsyncOperationBase + internal class RequestWebServerPackageVersionOperation : AsyncOperationBase { private enum ESteps { @@ -10,7 +10,7 @@ namespace YooAsset Done, } - private readonly DefaultWebFileSystem _fileSystem; + private readonly DefaultWebServerFileSystem _fileSystem; private readonly int _timeout; private UnityWebTextRequestOperation _webTextRequestOp; private ESteps _steps = ESteps.None; @@ -21,7 +21,7 @@ namespace YooAsset public string PackageVersion { private set; get; } - internal RequestWebPackageVersionOperation(DefaultWebFileSystem fileSystem, int timeout) + internal RequestWebServerPackageVersionOperation(DefaultWebServerFileSystem fileSystem, int timeout) { _fileSystem = fileSystem; _timeout = timeout; @@ -55,7 +55,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = $"Web package version file content is empty !"; + Error = $"Web server package version file content is empty !"; } else { diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/RequestWebPackageVersionOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/RequestWebServerPackageVersionOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/RequestWebPackageVersionOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebServerFileSystem/Operation/internal/RequestWebServerPackageVersionOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/DownloadHandlerAssetBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Operation/Internal/DownloadHandlerAssetBundleOperation.cs similarity index 93% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/DownloadHandlerAssetBundleOperation.cs rename to Assets/YooAsset/Runtime/FileSystem/Operation/Internal/DownloadHandlerAssetBundleOperation.cs index d969959..2791763 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/DownloadHandlerAssetBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Operation/Internal/DownloadHandlerAssetBundleOperation.cs @@ -5,16 +5,16 @@ namespace YooAsset { internal class DownloadHandlerAssetBundleOperation : DefaultDownloadFileOperation { - private readonly DefaultWebFileSystem _fileSystem; + private readonly bool _disableUnityWebCache; private DownloadHandlerAssetBundle _downloadhandler; private ESteps _steps = ESteps.None; public AssetBundle Result { private set; get; } - internal DownloadHandlerAssetBundleOperation(DefaultWebFileSystem fileSystem, PackageBundle bundle, DownloadParam param) : base(bundle, param) + internal DownloadHandlerAssetBundleOperation(bool disableUnityWebCache, PackageBundle bundle, DownloadParam param) : base(bundle, param) { - _fileSystem = fileSystem; + _disableUnityWebCache = disableUnityWebCache; } internal override void InternalOnStart() { @@ -113,7 +113,7 @@ namespace YooAsset } private DownloadHandlerAssetBundle CreateDownloadHandler() { - if (_fileSystem.DisableUnityWebCache) + if (_disableUnityWebCache) { var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, 0); #if UNITY_2020_3_OR_NEWER diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/DownloadHandlerAssetBundleOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/Operation/Internal/DownloadHandlerAssetBundleOperation.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/DownloadHandlerAssetBundleOperation.cs.meta rename to Assets/YooAsset/Runtime/FileSystem/Operation/Internal/DownloadHandlerAssetBundleOperation.cs.meta diff --git a/Assets/YooAsset/Runtime/InitializeParameters.cs b/Assets/YooAsset/Runtime/InitializeParameters.cs index 7490073..8c93cb7 100644 --- a/Assets/YooAsset/Runtime/InitializeParameters.cs +++ b/Assets/YooAsset/Runtime/InitializeParameters.cs @@ -170,7 +170,7 @@ namespace YooAsset /// 禁用Unity的网络缓存 public static FileSystemParameters CreateDefaultWebFileSystemParameters(bool disableUnityWebCache = false) { - string fileSystemClass = typeof(DefaultWebFileSystem).FullName; + string fileSystemClass = typeof(DefaultWebServerFileSystem).FullName; var fileSystemParams = new FileSystemParameters(fileSystemClass, null); fileSystemParams.AddParameter(FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE, disableUnityWebCache); return fileSystemParams; @@ -215,6 +215,7 @@ namespace YooAsset /// public class WebPlayModeParameters : InitializeParameters { - public FileSystemParameters WebFileSystemParameters; + public FileSystemParameters WebServerFileSystemParameters; + public FileSystemParameters WebRemoteFileSystemParameters; } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/InitializationOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/InitializationOperation.cs index f570b23..8cb33ce 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/InitializationOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/InitializationOperation.cs @@ -333,14 +333,18 @@ namespace YooAsset private enum ESteps { None, - CreateFileSystem, - InitWebFileSystem, + CreateWebServerFileSystem, + InitWebServerFileSystem, + CreateWebRemoteFileSystem, + InitWebRemoteFileSystem, + CheckResult, Done, } private readonly WebPlayModeImpl _impl; private readonly WebPlayModeParameters _parameters; - private FSInitializeFileSystemOperation _initWebFileSystemOp; + private FSInitializeFileSystemOperation _initWebServerFileSystemOp; + private FSInitializeFileSystemOperation _initWebRemoteFileSystemOp; private ESteps _steps = ESteps.None; internal WebPlayModeInitializationOperation(WebPlayModeImpl impl, WebPlayModeParameters parameters) @@ -350,54 +354,107 @@ namespace YooAsset } internal override void InternalOnStart() { - _steps = ESteps.CreateFileSystem; + _steps = ESteps.CreateWebServerFileSystem; } internal override void InternalOnUpdate() { if (_steps == ESteps.None || _steps == ESteps.Done) return; - if (_steps == ESteps.CreateFileSystem) + if (_steps == ESteps.CreateWebServerFileSystem) { - if (_parameters.WebFileSystemParameters == null) + if (_parameters.WebServerFileSystemParameters == null) { - _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = "Web file system parameters is null"; + _steps = ESteps.CreateWebRemoteFileSystem; return; } - _impl.WebFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.WebFileSystemParameters); - if (_impl.WebFileSystem == null) + _impl.WebServerFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.WebServerFileSystemParameters); + if (_impl.WebServerFileSystem == null) { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = "Failed to create web file system"; + Error = "Failed to create web server file system"; return; } - _steps = ESteps.InitWebFileSystem; + _steps = ESteps.InitWebServerFileSystem; } - if (_steps == ESteps.InitWebFileSystem) + if (_steps == ESteps.InitWebServerFileSystem) { - if (_initWebFileSystemOp == null) - _initWebFileSystemOp = _impl.WebFileSystem.InitializeFileSystemAsync(); + if (_initWebServerFileSystemOp == null) + _initWebServerFileSystemOp = _impl.WebServerFileSystem.InitializeFileSystemAsync(); - Progress = _initWebFileSystemOp.Progress; - if (_initWebFileSystemOp.IsDone == false) + Progress = _initWebServerFileSystemOp.Progress; + if (_initWebServerFileSystemOp.IsDone == false) return; - if (_initWebFileSystemOp.Status == EOperationStatus.Succeed) + if (_initWebServerFileSystemOp.Status == EOperationStatus.Succeed) { - _steps = ESteps.Done; - Status = EOperationStatus.Succeed; + _steps = ESteps.CreateWebRemoteFileSystem; } else { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = _initWebFileSystemOp.Error; + Error = _initWebServerFileSystemOp.Error; + } + } + + if (_steps == ESteps.CreateWebRemoteFileSystem) + { + if (_parameters.WebRemoteFileSystemParameters == null) + { + _steps = ESteps.CheckResult; + return; + } + + _impl.WebRemoteFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.WebRemoteFileSystemParameters); + 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.WebServerFileSystem.InitializeFileSystemAsync(); + + 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/PlayMode/WebPlayModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs index 14f42e1..1cb8a0b 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs @@ -7,7 +7,8 @@ namespace YooAsset internal class WebPlayModeImpl : IPlayMode, IBundleQuery { public readonly string PackageName; - public IFileSystem WebFileSystem { set; get; } + public IFileSystem WebServerFileSystem { set; get; } //可以为空! + public IFileSystem WebRemoteFileSystem { set; get; } //可以为空! public WebPlayModeImpl(string packageName) @@ -30,21 +31,42 @@ namespace YooAsset void IPlayMode.UpdatePlayMode() { - if (WebFileSystem != null) - WebFileSystem.OnUpdate(); + if (WebServerFileSystem != null) + WebServerFileSystem.OnUpdate(); + + if (WebRemoteFileSystem != null) + WebRemoteFileSystem.OnUpdate(); } RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout) { - var operation = new RequestPackageVersionImplOperation(WebFileSystem, appendTimeTicks, timeout); - OperationSystem.StartOperation(PackageName, operation); - return operation; + 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) { - var operation = new UpdatePackageManifestImplOperation(this, WebFileSystem, packageVersion, timeout);; - OperationSystem.StartOperation(PackageName, operation); - return operation; + 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) { @@ -55,50 +77,50 @@ namespace YooAsset ClearAllBundleFilesOperation IPlayMode.ClearAllBundleFilesAsync() { - var operation = new ClearAllBundleFilesImplOperation(this, WebFileSystem, null, null); + var operation = new ClearAllBundleFilesImplOperation(this, WebServerFileSystem, WebRemoteFileSystem, null); OperationSystem.StartOperation(PackageName, operation); return operation; } ClearUnusedBundleFilesOperation IPlayMode.ClearUnusedBundleFilesAsync() { - var operation = new ClearUnusedBundleFilesImplOperation(this, WebFileSystem, null, null); + var operation = new ClearUnusedBundleFilesImplOperation(this, WebServerFileSystem, WebRemoteFileSystem, null); OperationSystem.StartOperation(PackageName, operation); return operation; } ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout) { - List downloadList = PlayModeHelper.GetDownloadListByAll(ActiveManifest, WebFileSystem); + 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, WebFileSystem); + List downloadList = PlayModeHelper.GetDownloadListByTags(ActiveManifest, tags, WebServerFileSystem, WebRemoteFileSystem); var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout); return operation; } ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout) { - List downloadList = PlayModeHelper.GetDownloadListByPaths(ActiveManifest, assetInfos, WebFileSystem); + List downloadList = PlayModeHelper.GetDownloadListByPaths(ActiveManifest, assetInfos, 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, WebFileSystem); + 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, WebFileSystem); + 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, WebFileSystem); + List importerList = PlayModeHelper.GetImporterListByFilePaths(ActiveManifest, filePaths, WebServerFileSystem, WebRemoteFileSystem); var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout); return operation; } @@ -110,9 +132,15 @@ namespace YooAsset if (packageBundle == null) throw new Exception("Should never get here !"); - if (WebFileSystem.Belong(packageBundle)) + if (WebServerFileSystem != null && WebServerFileSystem.Belong(packageBundle)) { - BundleInfo bundleInfo = new BundleInfo(WebFileSystem, packageBundle); + BundleInfo bundleInfo = new BundleInfo(WebServerFileSystem, packageBundle); + return bundleInfo; + } + + if (WebRemoteFileSystem != null && WebRemoteFileSystem.Belong(packageBundle)) + { + BundleInfo bundleInfo = new BundleInfo(WebRemoteFileSystem, packageBundle); return bundleInfo; } diff --git a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs index 1d1f7f9..833fc28 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs @@ -181,10 +181,20 @@ namespace YooAsset if (_playMode == EPlayMode.WebPlayMode) { var webPlayModeParams = parameters as WebPlayModeParameters; - var fileSystemClassName = webPlayModeParams.WebFileSystemParameters.FileSystemClass; - if (fileSystemClassName == typeof(DefaultCacheFileSystem).FullName - || fileSystemClassName == typeof(DefaultBuildinFileSystem).FullName) - throw new Exception($"{fileSystemClassName} not support {nameof(EPlayMode.WebPlayMode)}"); + if (webPlayModeParams.WebServerFileSystemParameters != null) + { + var fileSystemClassName = webPlayModeParams.WebServerFileSystemParameters.FileSystemClass; + if (fileSystemClassName == typeof(DefaultCacheFileSystem).FullName + || fileSystemClassName == typeof(DefaultBuildinFileSystem).FullName) + throw new Exception($"{fileSystemClassName} not support {nameof(EPlayMode.WebPlayMode)}"); + } + if (webPlayModeParams.WebRemoteFileSystemParameters != null) + { + var fileSystemClassName = webPlayModeParams.WebRemoteFileSystemParameters.FileSystemClass; + if (fileSystemClassName == typeof(DefaultCacheFileSystem).FullName + || fileSystemClassName == typeof(DefaultBuildinFileSystem).FullName) + throw new Exception($"{fileSystemClassName} not support {nameof(EPlayMode.WebPlayMode)}"); + } } } private void InitializeOperation_Completed(AsyncOperationBase op)