update runtime code

pull/62/head
hevinci 2022-12-27 10:19:35 +08:00
parent 4fa01e1a29
commit ac839450e2
10 changed files with 82 additions and 53 deletions

View File

@ -110,7 +110,7 @@ namespace YooAsset
if (_steps == ESteps.Unpack)
{
int failedTryAgain = 1;
var bundleInfo = HostPlayModeImpl.ConvertToUnpackInfo(MainBundleInfo.Bundle);
var bundleInfo = PatchManifestTools.GetUnpackInfo(MainBundleInfo.Bundle);
_unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
_steps = ESteps.CheckUnpack;
}

View File

@ -93,7 +93,7 @@ namespace YooAsset
if (_steps == ESteps.Unpack)
{
int failedTryAgain = 1;
var bundleInfo = HostPlayModeImpl.ConvertToUnpackInfo(MainBundleInfo.Bundle);
var bundleInfo = PatchManifestTools.GetUnpackInfo(MainBundleInfo.Bundle);
_unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
_steps = ESteps.CheckUnpack;
}

View File

@ -12,7 +12,7 @@ namespace YooAsset
}
private static int RequestCount = 0;
private readonly HostPlayModeImpl _impl;
private readonly IRemoteServices _remoteServices;
private readonly string _packageName;
private readonly string _packageVersion;
private readonly int _timeout;
@ -20,9 +20,9 @@ namespace YooAsset
private UnityWebFileRequester _downloader2;
private ESteps _steps = ESteps.None;
internal DownloadManifestOperation(HostPlayModeImpl impl, string packageName, string packageVersion, int timeout)
internal DownloadManifestOperation(IRemoteServices remoteServices, string packageName, string packageVersion, int timeout)
{
_impl = impl;
_remoteServices = remoteServices;
_packageName = packageName;
_packageVersion = packageVersion;
_timeout = timeout;
@ -103,9 +103,9 @@ namespace YooAsset
{
// 轮流返回请求地址
if (RequestCount % 2 == 0)
return _impl.GetPatchDownloadFallbackURL(fileName);
return _remoteServices.GetRemoteFallbackURL(fileName);
else
return _impl.GetPatchDownloadMainURL(fileName);
return _remoteServices.GetRemoteMainURL(fileName);
}
}
}

View File

@ -12,7 +12,7 @@ namespace YooAsset
}
private static int RequestCount = 0;
private readonly HostPlayModeImpl _impl;
private readonly IRemoteServices _remoteServices;
private readonly string _packageName;
private readonly bool _appendTimeTicks;
private readonly int _timeout;
@ -25,9 +25,9 @@ namespace YooAsset
public string PackageVersion { private set; get; }
public QueryRemotePackageVersionOperation(HostPlayModeImpl impl, string packageName, bool appendTimeTicks, int timeout)
public QueryRemotePackageVersionOperation(IRemoteServices remoteServices, string packageName, bool appendTimeTicks, int timeout)
{
_impl = impl;
_remoteServices = remoteServices;
_packageName = packageName;
_appendTimeTicks = appendTimeTicks;
_timeout = timeout;
@ -89,9 +89,9 @@ namespace YooAsset
// 轮流返回请求地址
if (RequestCount % 2 == 0)
url = _impl.GetPatchDownloadFallbackURL(fileName);
url = _remoteServices.GetRemoteFallbackURL(fileName);
else
url = _impl.GetPatchDownloadMainURL(fileName);
url = _remoteServices.GetRemoteMainURL(fileName);
// 在URL末尾添加时间戳
if (_appendTimeTicks)

View File

@ -120,7 +120,7 @@ namespace YooAsset
{
_packageName = packageName;
_cacheKey = $"{packageName}-{FileHash}";
_fileName = PatchManifest.CreateBundleFileName(nameStype, BundleName, FileHash, IsRawFile);
_fileName = PatchManifestTools.CreateBundleFileName(nameStype, BundleName, FileHash, IsRawFile);
}
/// <summary>

View File

@ -292,28 +292,6 @@ namespace YooAsset
}
}
/// <summary>
/// 生成Bundle文件的正式名称
/// </summary>
public static string CreateBundleFileName(int nameStyle, string bundleName, string fileHash, bool isRawFile)
{
if (nameStyle == 1) //HashName
{
string fileExtension = isRawFile ? YooAssetSettingsData.Setting.RawFileVariant : YooAssetSettingsData.Setting.AssetBundleFileVariant;
return StringUtility.Format("{0}.{1}", fileHash, fileExtension);
}
else if (nameStyle == 4) //BundleName_HashName
{
string fileName = bundleName.Remove(bundleName.LastIndexOf('.'));
string fileExtension = isRawFile ? YooAssetSettingsData.Setting.RawFileVariant : YooAssetSettingsData.Setting.AssetBundleFileVariant;
return StringUtility.Format("{0}_{1}.{2}", fileName, fileHash, fileExtension);
}
else
{
throw new NotImplementedException($"Invalid name style : {nameStyle}");
}
}
#region 调试方法
[Conditional("DEBUG")]
private void DebugCheckLocation(string location)

View File

@ -151,5 +151,38 @@ namespace YooAsset
return manifest;
}
/// <summary>
/// 生成Bundle文件的正式名称
/// </summary>
public static string CreateBundleFileName(int nameStyle, string bundleName, string fileHash, bool isRawFile)
{
if (nameStyle == 1) //HashName
{
string fileExtension = isRawFile ? YooAssetSettingsData.Setting.RawFileVariant : YooAssetSettingsData.Setting.AssetBundleFileVariant;
return StringUtility.Format("{0}.{1}", fileHash, fileExtension);
}
else if (nameStyle == 4) //BundleName_HashName
{
string fileName = bundleName.Remove(bundleName.LastIndexOf('.'));
string fileExtension = isRawFile ? YooAssetSettingsData.Setting.RawFileVariant : YooAssetSettingsData.Setting.AssetBundleFileVariant;
return StringUtility.Format("{0}_{1}.{2}", fileName, fileHash, fileExtension);
}
else
{
throw new NotImplementedException($"Invalid name style : {nameStyle}");
}
}
/// <summary>
/// 获取解压BundleInfo
/// </summary>
public static BundleInfo GetUnpackInfo(PatchBundle patchBundle)
{
// 注意:我们把流加载路径指定为远端下载地址
string streamingPath = PathHelper.ConvertToWWWPath(patchBundle.StreamingFilePath);
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming, streamingPath, streamingPath);
return bundleInfo;
}
}
}

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace YooAsset
{
internal class HostPlayModeImpl : IPlayModeServices, IBundleServices
internal class HostPlayModeImpl : IPlayModeServices, IBundleServices, IRemoteServices
{
private PatchManifest _activeManifest;
@ -31,16 +31,6 @@ namespace YooAsset
return operation;
}
// WEB相关
public string GetPatchDownloadMainURL(string fileName)
{
return $"{_defaultHostServer}/{fileName}";
}
public string GetPatchDownloadFallbackURL(string fileName)
{
return $"{_fallbackHostServer}/{fileName}";
}
// 下载相关
private List<BundleInfo> ConvertToDownloadList(List<PatchBundle> downloadList)
{
@ -54,8 +44,8 @@ namespace YooAsset
}
private BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle)
{
string remoteMainURL = GetPatchDownloadMainURL(patchBundle.FileName);
string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.FileName);
string remoteMainURL = GetRemoteMainURL(patchBundle.FileName);
string remoteFallbackURL = GetRemoteFallbackURL(patchBundle.FileName);
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL);
return bundleInfo;
}
@ -71,14 +61,22 @@ namespace YooAsset
}
return result;
}
public static BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle)
private BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle)
{
// 注意:我们把流加载路径指定为远端下载地址
string streamingPath = PathHelper.ConvertToWWWPath(patchBundle.StreamingFilePath);
BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming, streamingPath, streamingPath);
return bundleInfo;
return PatchManifestTools.GetUnpackInfo(patchBundle);
}
#region IRemoteServices接口
public string GetRemoteMainURL(string fileName)
{
return $"{_defaultHostServer}/{fileName}";
}
public string GetRemoteFallbackURL(string fileName)
{
return $"{_fallbackHostServer}/{fileName}";
}
#endregion
#region IPlayModeServices接口
public PatchManifest ActiveManifest
{

View File

@ -0,0 +1,9 @@

namespace YooAsset
{
internal interface IRemoteServices
{
string GetRemoteMainURL(string fileName);
string GetRemoteFallbackURL(string fileName);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 55b92092303a8d44280c107e6c5a8379
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: