From ad8eb2691f22d45efa50e904b14100ada0d962e6 Mon Sep 17 00:00:00 2001 From: Y-way Date: Mon, 20 Jun 2022 11:04:09 +0800 Subject: [PATCH] =?UTF-8?q?YooAsset=20=E6=96=B0=E5=A2=9EIRemoteHostService?= =?UTF-8?q?s=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HostPlayModeParameters 使用 IRemoteHostServices 获取资源服地址 --- .../Handles/AssetOperationHandle.cs | 2 +- .../Operations/InstantiateOperation.cs | 2 +- .../YooAsset/Runtime/PatchSystem/AssetInfo.cs | 2 +- .../PatchSystem/PlayMode/HostPlayModeImpl.cs | 8 ++-- .../Runtime/Services/IRemoteHostServices.cs | 23 +++++++++ .../Services/IRemoteHostServices.cs.meta | 11 +++++ Assets/YooAsset/Runtime/YooAssets.cs | 47 +++++++++---------- 7 files changed, 63 insertions(+), 32 deletions(-) create mode 100644 Assets/YooAsset/Runtime/Services/IRemoteHostServices.cs create mode 100644 Assets/YooAsset/Runtime/Services/IRemoteHostServices.cs.meta diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs index c8349e8..6a74dbf 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs @@ -139,4 +139,4 @@ namespace YooAsset return operation; } } -} \ No newline at end of file +} diff --git a/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs b/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs index 1241982..65dd24d 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Operations/InstantiateOperation.cs @@ -82,4 +82,4 @@ namespace YooAsset } } } -} \ No newline at end of file +} diff --git a/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs b/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs index 9642b16..621fe0e 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs @@ -91,4 +91,4 @@ namespace YooAsset Error = error; } } -} \ No newline at end of file +} diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs index 2bf3c56..fd33316 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs @@ -25,12 +25,12 @@ namespace YooAsset /// /// 异步初始化 /// - public InitializationOperation InitializeAsync(bool locationToLower, bool clearCacheWhenDirty, string defaultHostServer, string fallbackHostServer) + public InitializationOperation InitializeAsync(bool locationToLower, bool clearCacheWhenDirty, IRemoteHostServices hostServerServices) { _locationToLower = locationToLower; _clearCacheWhenDirty = clearCacheWhenDirty; - _defaultHostServer = defaultHostServer; - _fallbackHostServer = fallbackHostServer; + _defaultHostServer = hostServerServices.GetDefaultHost(); + _fallbackHostServer = hostServerServices.GetFallbackHost(); var operation = new HostPlayModeInitializationOperation(this); OperationSystem.StartOperaiton(operation); @@ -370,4 +370,4 @@ namespace YooAsset } #endregion } -} \ No newline at end of file +} diff --git a/Assets/YooAsset/Runtime/Services/IRemoteHostServices.cs b/Assets/YooAsset/Runtime/Services/IRemoteHostServices.cs new file mode 100644 index 0000000..15f2bbd --- /dev/null +++ b/Assets/YooAsset/Runtime/Services/IRemoteHostServices.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace YooAsset +{ + public interface IRemoteHostServices + { + /// + /// 默认的资源服务器下载地址 + /// + /// + string GetDefaultHost(); + + /// + /// 备用的资源服务器下载地址 + /// + /// + string GetFallbackHost(); + } +} diff --git a/Assets/YooAsset/Runtime/Services/IRemoteHostServices.cs.meta b/Assets/YooAsset/Runtime/Services/IRemoteHostServices.cs.meta new file mode 100644 index 0000000..be6c441 --- /dev/null +++ b/Assets/YooAsset/Runtime/Services/IRemoteHostServices.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 863c6fcb409e9c4448fab48de69316b2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index 0e0338d..01ced65 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -85,21 +85,14 @@ namespace YooAsset /// public class HostPlayModeParameters : InitializeParameters { - /// - /// 当缓存池被污染的时候清理缓存池 - /// - public bool ClearCacheWhenDirty; - - /// - /// 默认的资源服务器下载地址 - /// - public string DefaultHostServer; - - /// - /// 备用的资源服务器下载地址 - /// - public string FallbackHostServer; - + /// + /// 资源更新获取URL服务接口 + /// + public IRemoteHostServices HostAddressServices; + /// + /// 当缓存池被污染的时候清理缓存池 + /// + public bool ClearCacheWhenDirty; /// /// 启用断点续传功能的文件大小 /// @@ -215,9 +208,7 @@ namespace YooAsset var hostPlayModeParameters = parameters as HostPlayModeParameters; initializeOperation = _hostPlayModeImpl.InitializeAsync( hostPlayModeParameters.LocationToLower, - hostPlayModeParameters.ClearCacheWhenDirty, - hostPlayModeParameters.DefaultHostServer, - hostPlayModeParameters.FallbackHostServer); + hostPlayModeParameters.ClearCacheWhenDirty, hostPlayModeParameters.HostAddressServices); } else { @@ -234,11 +225,17 @@ namespace YooAsset _initializeError = op.Error; } - /// - /// 向网络端请求静态资源版本 - /// - /// 超时时间(默认值:60秒) - public static UpdateStaticVersionOperation UpdateStaticVersionAsync(int timeout = 60) + /// + /// + /// + public static bool IsInitialized => _isInitialize; + + + /// + /// 向网络端请求静态资源版本 + /// + /// 超时时间(默认值:60秒) + public static UpdateStaticVersionOperation UpdateStaticVersionAsync(int timeout = 60) { DebugCheckInitialize(); if (_playMode == EPlayMode.EditorSimulateMode) @@ -557,7 +554,7 @@ namespace YooAsset /// /// 资源类型 /// 资源的定位地址 - public static AssetOperationHandle LoadAssetAsync(string location) + public static AssetOperationHandle LoadAssetAsync(string location) where TObject : UnityEngine.Object { DebugCheckInitialize(); AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject)); @@ -1012,4 +1009,4 @@ namespace YooAsset } #endregion } -} \ No newline at end of file +}