diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/RawFileOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/RawFileOperationHandle.cs index bb66549..4faad57 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/RawFileOperationHandle.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/RawFileOperationHandle.cs @@ -73,9 +73,7 @@ namespace YooAsset if (IsValidWithWarning == false) return null; string filePath = Provider.RawFilePath; - if (File.Exists(filePath) == false) - return null; - return File.ReadAllBytes(filePath); + return FileUtility.ReadAllBytes(filePath); } /// diff --git a/Assets/YooAsset/Runtime/InitializeParameters.cs b/Assets/YooAsset/Runtime/InitializeParameters.cs index 03e6548..1abd0bd 100644 --- a/Assets/YooAsset/Runtime/InitializeParameters.cs +++ b/Assets/YooAsset/Runtime/InitializeParameters.cs @@ -80,19 +80,14 @@ namespace YooAsset /// public class HostPlayModeParameters : InitializeParameters { - /// - /// 默认的资源服务器下载地址 - /// - public string DefaultHostServer = string.Empty; - - /// - /// 备用的资源服务器下载地址 - /// - public string FallbackHostServer = string.Empty; - /// /// 内置资源查询服务接口 /// public IQueryServices QueryServices = null; + + /// + /// 远端资源地址查询服务类 + /// + public IRemoteServices RemoteServices = null; } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PackageSystem/Operations/PreDownloadContentOperation.cs b/Assets/YooAsset/Runtime/PackageSystem/Operations/PreDownloadContentOperation.cs index c4dfbdc..1e21d09 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/Operations/PreDownloadContentOperation.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/Operations/PreDownloadContentOperation.cs @@ -169,7 +169,7 @@ namespace YooAsset { if (_downloadManifestOp == null) { - _downloadManifestOp = new DownloadManifestOperation(_impl, _packageName, _packageVersion, _timeout); + _downloadManifestOp = new DownloadManifestOperation(_impl.RemoteServices, _packageName, _packageVersion, _timeout); OperationSystem.StartOperation(_downloadManifestOp); } diff --git a/Assets/YooAsset/Runtime/PackageSystem/Operations/UpdatePackageManifestOperation.cs b/Assets/YooAsset/Runtime/PackageSystem/Operations/UpdatePackageManifestOperation.cs index 795df7b..2e11d41 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/Operations/UpdatePackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/Operations/UpdatePackageManifestOperation.cs @@ -137,7 +137,7 @@ namespace YooAsset { if (_downloadManifestOp == null) { - _downloadManifestOp = new DownloadManifestOperation(_impl, _packageName, _packageVersion, _timeout); + _downloadManifestOp = new DownloadManifestOperation(_impl.RemoteServices, _packageName, _packageVersion, _timeout); OperationSystem.StartOperation(_downloadManifestOp); } diff --git a/Assets/YooAsset/Runtime/PackageSystem/Operations/UpdatePackageVersionOperation.cs b/Assets/YooAsset/Runtime/PackageSystem/Operations/UpdatePackageVersionOperation.cs index fca4280..7430138 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/Operations/UpdatePackageVersionOperation.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/Operations/UpdatePackageVersionOperation.cs @@ -82,7 +82,7 @@ namespace YooAsset { if (_queryRemotePackageVersionOp == null) { - _queryRemotePackageVersionOp = new QueryRemotePackageVersionOperation(_impl, _packageName, _appendTimeTicks, _timeout); + _queryRemotePackageVersionOp = new QueryRemotePackageVersionOperation(_impl.RemoteServices, _packageName, _appendTimeTicks, _timeout); OperationSystem.StartOperation(_queryRemotePackageVersionOp); } diff --git a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/HostPlayModeImpl.cs index c80dc63..d0c1474 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/PlayMode/HostPlayModeImpl.cs @@ -4,25 +4,28 @@ using System.Collections.Generic; namespace YooAsset { - internal class HostPlayModeImpl : IPlayModeServices, IBundleServices, IRemoteServices + internal class HostPlayModeImpl : IPlayModeServices, IBundleServices { private PackageManifest _activeManifest; // 参数相关 private string _packageName; - private string _defaultHostServer; - private string _fallbackHostServer; private IQueryServices _queryServices; + private IRemoteServices _remoteServices; + + public IRemoteServices RemoteServices + { + get { return _remoteServices; } + } /// /// 异步初始化 /// - public InitializationOperation InitializeAsync(string packageName, string defaultHostServer, string fallbackHostServer, IQueryServices queryServices) + public InitializationOperation InitializeAsync(string packageName, IQueryServices queryServices, IRemoteServices remoteServices) { _packageName = packageName; - _defaultHostServer = defaultHostServer; - _fallbackHostServer = fallbackHostServer; _queryServices = queryServices; + _remoteServices = remoteServices; var operation = new HostPlayModeInitializationOperation(this, packageName); OperationSystem.StartOperation(operation); @@ -42,23 +45,12 @@ namespace YooAsset } private BundleInfo ConvertToDownloadInfo(PackageBundle packageBundle) { - string remoteMainURL = GetRemoteMainURL(packageBundle.FileName); - string remoteFallbackURL = GetRemoteFallbackURL(packageBundle.FileName); + string remoteMainURL = _remoteServices.GetRemoteMainURL(packageBundle.FileName); + string remoteFallbackURL = _remoteServices.GetRemoteFallbackURL(packageBundle.FileName); BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL); return bundleInfo; } - #region IRemoteServices接口 - public string GetRemoteMainURL(string fileName) - { - return $"{_defaultHostServer}/{fileName}"; - } - public string GetRemoteFallbackURL(string fileName) - { - return $"{_fallbackHostServer}/{fileName}"; - } - #endregion - #region IPlayModeServices接口 public PackageManifest ActiveManifest { @@ -76,7 +68,7 @@ namespace YooAsset if (_activeManifest != null) { PersistentTools.GetPersistent(_packageName).SaveSandboxPackageVersionFile(_activeManifest.PackageVersion); - } + } } private bool IsBuildinPackageBundle(PackageBundle packageBundle) diff --git a/Assets/YooAsset/Runtime/PackageSystem/ResourcePackage.cs b/Assets/YooAsset/Runtime/PackageSystem/ResourcePackage.cs index 64dfd51..c234ece 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/ResourcePackage.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/ResourcePackage.cs @@ -122,9 +122,8 @@ namespace YooAsset var initializeParameters = parameters as HostPlayModeParameters; initializeOperation = hostPlayModeImpl.InitializeAsync( PackageName, - initializeParameters.DefaultHostServer, - initializeParameters.FallbackHostServer, - initializeParameters.QueryServices + initializeParameters.QueryServices, + initializeParameters.RemoteServices ); } else @@ -172,12 +171,10 @@ namespace YooAsset if (parameters is HostPlayModeParameters) { var hostPlayModeParameters = parameters as HostPlayModeParameters; - if (string.IsNullOrEmpty(hostPlayModeParameters.DefaultHostServer)) - throw new Exception($"${hostPlayModeParameters.DefaultHostServer} is null or empty."); - if (string.IsNullOrEmpty(hostPlayModeParameters.FallbackHostServer)) - throw new Exception($"${hostPlayModeParameters.FallbackHostServer} is null or empty."); if (hostPlayModeParameters.QueryServices == null) throw new Exception($"{nameof(IQueryServices)} is null."); + if (hostPlayModeParameters.RemoteServices == null) + throw new Exception($"{nameof(IRemoteServices)} is null."); } // 鉴定运行模式 diff --git a/Assets/YooAsset/Runtime/Services/Internal/IRemoteServices.cs b/Assets/YooAsset/Runtime/Services/Internal/IRemoteServices.cs index 54a4d40..5debd30 100644 --- a/Assets/YooAsset/Runtime/Services/Internal/IRemoteServices.cs +++ b/Assets/YooAsset/Runtime/Services/Internal/IRemoteServices.cs @@ -1,9 +1,18 @@  namespace YooAsset { - internal interface IRemoteServices + public interface IRemoteServices { + /// + /// 获取主资源站的资源地址 + /// + /// 请求的文件名称 string GetRemoteMainURL(string fileName); + + /// + /// 获取备用资源站的资源地址 + /// + /// 请求的文件名称 string GetRemoteFallbackURL(string fileName); } } \ No newline at end of file