update package system

1. 移除了HostPlayModeParameters.DefaultHostServer字段
2. 移除了HostPlayModeParameters.FallbackHostServer字段
3. 新增了HostPlayModeParameters.RemoteServices字段
pull/134/head
hevinci 2023-07-12 19:15:10 +08:00
parent 829ea66d0e
commit 472a5ae97a
8 changed files with 35 additions and 44 deletions

View File

@ -73,9 +73,7 @@ namespace YooAsset
if (IsValidWithWarning == false) if (IsValidWithWarning == false)
return null; return null;
string filePath = Provider.RawFilePath; string filePath = Provider.RawFilePath;
if (File.Exists(filePath) == false) return FileUtility.ReadAllBytes(filePath);
return null;
return File.ReadAllBytes(filePath);
} }
/// <summary> /// <summary>

View File

@ -80,19 +80,14 @@ namespace YooAsset
/// </summary> /// </summary>
public class HostPlayModeParameters : InitializeParameters public class HostPlayModeParameters : InitializeParameters
{ {
/// <summary>
/// 默认的资源服务器下载地址
/// </summary>
public string DefaultHostServer = string.Empty;
/// <summary>
/// 备用的资源服务器下载地址
/// </summary>
public string FallbackHostServer = string.Empty;
/// <summary> /// <summary>
/// 内置资源查询服务接口 /// 内置资源查询服务接口
/// </summary> /// </summary>
public IQueryServices QueryServices = null; public IQueryServices QueryServices = null;
/// <summary>
/// 远端资源地址查询服务类
/// </summary>
public IRemoteServices RemoteServices = null;
} }
} }

View File

@ -169,7 +169,7 @@ namespace YooAsset
{ {
if (_downloadManifestOp == null) if (_downloadManifestOp == null)
{ {
_downloadManifestOp = new DownloadManifestOperation(_impl, _packageName, _packageVersion, _timeout); _downloadManifestOp = new DownloadManifestOperation(_impl.RemoteServices, _packageName, _packageVersion, _timeout);
OperationSystem.StartOperation(_downloadManifestOp); OperationSystem.StartOperation(_downloadManifestOp);
} }

View File

@ -137,7 +137,7 @@ namespace YooAsset
{ {
if (_downloadManifestOp == null) if (_downloadManifestOp == null)
{ {
_downloadManifestOp = new DownloadManifestOperation(_impl, _packageName, _packageVersion, _timeout); _downloadManifestOp = new DownloadManifestOperation(_impl.RemoteServices, _packageName, _packageVersion, _timeout);
OperationSystem.StartOperation(_downloadManifestOp); OperationSystem.StartOperation(_downloadManifestOp);
} }

View File

@ -82,7 +82,7 @@ namespace YooAsset
{ {
if (_queryRemotePackageVersionOp == null) if (_queryRemotePackageVersionOp == null)
{ {
_queryRemotePackageVersionOp = new QueryRemotePackageVersionOperation(_impl, _packageName, _appendTimeTicks, _timeout); _queryRemotePackageVersionOp = new QueryRemotePackageVersionOperation(_impl.RemoteServices, _packageName, _appendTimeTicks, _timeout);
OperationSystem.StartOperation(_queryRemotePackageVersionOp); OperationSystem.StartOperation(_queryRemotePackageVersionOp);
} }

View File

@ -4,25 +4,28 @@ using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
internal class HostPlayModeImpl : IPlayModeServices, IBundleServices, IRemoteServices internal class HostPlayModeImpl : IPlayModeServices, IBundleServices
{ {
private PackageManifest _activeManifest; private PackageManifest _activeManifest;
// 参数相关 // 参数相关
private string _packageName; private string _packageName;
private string _defaultHostServer;
private string _fallbackHostServer;
private IQueryServices _queryServices; private IQueryServices _queryServices;
private IRemoteServices _remoteServices;
public IRemoteServices RemoteServices
{
get { return _remoteServices; }
}
/// <summary> /// <summary>
/// 异步初始化 /// 异步初始化
/// </summary> /// </summary>
public InitializationOperation InitializeAsync(string packageName, string defaultHostServer, string fallbackHostServer, IQueryServices queryServices) public InitializationOperation InitializeAsync(string packageName, IQueryServices queryServices, IRemoteServices remoteServices)
{ {
_packageName = packageName; _packageName = packageName;
_defaultHostServer = defaultHostServer;
_fallbackHostServer = fallbackHostServer;
_queryServices = queryServices; _queryServices = queryServices;
_remoteServices = remoteServices;
var operation = new HostPlayModeInitializationOperation(this, packageName); var operation = new HostPlayModeInitializationOperation(this, packageName);
OperationSystem.StartOperation(operation); OperationSystem.StartOperation(operation);
@ -42,23 +45,12 @@ namespace YooAsset
} }
private BundleInfo ConvertToDownloadInfo(PackageBundle packageBundle) private BundleInfo ConvertToDownloadInfo(PackageBundle packageBundle)
{ {
string remoteMainURL = GetRemoteMainURL(packageBundle.FileName); string remoteMainURL = _remoteServices.GetRemoteMainURL(packageBundle.FileName);
string remoteFallbackURL = GetRemoteFallbackURL(packageBundle.FileName); string remoteFallbackURL = _remoteServices.GetRemoteFallbackURL(packageBundle.FileName);
BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL); BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL);
return bundleInfo; return bundleInfo;
} }
#region IRemoteServices接口
public string GetRemoteMainURL(string fileName)
{
return $"{_defaultHostServer}/{fileName}";
}
public string GetRemoteFallbackURL(string fileName)
{
return $"{_fallbackHostServer}/{fileName}";
}
#endregion
#region IPlayModeServices接口 #region IPlayModeServices接口
public PackageManifest ActiveManifest public PackageManifest ActiveManifest
{ {

View File

@ -122,9 +122,8 @@ namespace YooAsset
var initializeParameters = parameters as HostPlayModeParameters; var initializeParameters = parameters as HostPlayModeParameters;
initializeOperation = hostPlayModeImpl.InitializeAsync( initializeOperation = hostPlayModeImpl.InitializeAsync(
PackageName, PackageName,
initializeParameters.DefaultHostServer, initializeParameters.QueryServices,
initializeParameters.FallbackHostServer, initializeParameters.RemoteServices
initializeParameters.QueryServices
); );
} }
else else
@ -172,12 +171,10 @@ namespace YooAsset
if (parameters is HostPlayModeParameters) if (parameters is HostPlayModeParameters)
{ {
var hostPlayModeParameters = parameters as 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) if (hostPlayModeParameters.QueryServices == null)
throw new Exception($"{nameof(IQueryServices)} is null."); throw new Exception($"{nameof(IQueryServices)} is null.");
if (hostPlayModeParameters.RemoteServices == null)
throw new Exception($"{nameof(IRemoteServices)} is null.");
} }
// 鉴定运行模式 // 鉴定运行模式

View File

@ -1,9 +1,18 @@
 
namespace YooAsset namespace YooAsset
{ {
internal interface IRemoteServices public interface IRemoteServices
{ {
/// <summary>
/// 获取主资源站的资源地址
/// </summary>
/// <param name="fileName">请求的文件名称</param>
string GetRemoteMainURL(string fileName); string GetRemoteMainURL(string fileName);
/// <summary>
/// 获取备用资源站的资源地址
/// </summary>
/// <param name="fileName">请求的文件名称</param>
string GetRemoteFallbackURL(string fileName); string GetRemoteFallbackURL(string fileName);
} }
} }