update runtime code

pull/62/head
hevinci 2022-12-26 00:48:56 +08:00
parent dd824254a9
commit f3e3f7cf85
18 changed files with 327 additions and 259 deletions

View File

@ -90,7 +90,7 @@ namespace YooAsset
_assetSystemImpl.Initialize(PackageName, true, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices); _assetSystemImpl.Initialize(PackageName, true, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
var initializeParameters = parameters as EditorSimulateModeParameters; var initializeParameters = parameters as EditorSimulateModeParameters;
initializeOperation = editorSimulateModeImpl.InitializeAsync(PackageName, initializeParameters.LocationToLower, initializeParameters.SimulatePatchManifestPath); initializeOperation = editorSimulateModeImpl.InitializeAsync(initializeParameters.LocationToLower, initializeParameters.SimulatePatchManifestPath);
} }
else if (_playMode == EPlayMode.OfflinePlayMode) else if (_playMode == EPlayMode.OfflinePlayMode)
{ {
@ -219,12 +219,23 @@ namespace YooAsset
} }
/// <summary> /// <summary>
/// 检查包裹内容的完整性 /// 预下载指定版本的包裹资源
/// </summary> /// </summary>
public CheckContentsIntegrityOperation CheckContentsIntegrityAsync() /// <param name="packageVersion">下载的包裹版本</param>
/// <param name="timeout">超时时间默认值60秒</param>
public PreDownloadPackageOperation PreDownloadPackageAsync(string packageVersion, int timeout = 60)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
return _playModeServices.CheckContentsIntegrityAsync(); return _playModeServices.PreDownloadPackageAsync(packageVersion, timeout);
}
/// <summary>
/// 检查包裹内容的完整性
/// </summary>
public CheckPackageContentsOperation CheckPackageContentsAsync(string packageVersion)
{
DebugCheckInitialize();
return _playModeServices.CheckPackageContentsOperation(packageVersion);
} }
/// <summary> /// <summary>

View File

@ -8,13 +8,13 @@ namespace YooAsset
/// <summary> /// <summary>
/// 检查包裹内容的完整性 /// 检查包裹内容的完整性
/// </summary> /// </summary>
public abstract class CheckContentsIntegrityOperation : AsyncOperationBase public abstract class CheckPackageContentsOperation : AsyncOperationBase
{ {
} }
internal sealed class EditorSimulateModeCheckContentsIntegrityOperation : CheckContentsIntegrityOperation internal sealed class EditorSimulateModeCheckPackageContentsOperation : CheckPackageContentsOperation
{ {
internal EditorSimulateModeCheckContentsIntegrityOperation() internal EditorSimulateModeCheckPackageContentsOperation()
{ {
} }
internal override void Start() internal override void Start()
@ -25,9 +25,9 @@ namespace YooAsset
{ {
} }
} }
internal sealed class OfflinePlayModeCheckContentsIntegrityOperation : CheckContentsIntegrityOperation internal sealed class OfflinePlayModeCheckPackageContentsOperation : CheckPackageContentsOperation
{ {
internal OfflinePlayModeCheckContentsIntegrityOperation() internal OfflinePlayModeCheckPackageContentsOperation()
{ {
} }
internal override void Start() internal override void Start()
@ -38,54 +38,83 @@ namespace YooAsset
{ {
} }
} }
internal sealed class HostPlayModeCheckContentsIntegrityOperation : CheckContentsIntegrityOperation internal sealed class HostPlayModeCheckPackageContentsOperation : CheckPackageContentsOperation
{ {
private enum ESteps private enum ESteps
{ {
None, None,
CheckLoadedManifest, CheckActiveManifest,
LoadCacheManifest,
VerifyPackage, VerifyPackage,
Done, Done,
} }
private readonly HostPlayModeImpl _impl; private readonly HostPlayModeImpl _impl;
private readonly string _packageName; private readonly string _packageName;
private readonly string _packageVersion;
private LoadCacheManifestOperation _loadCacheManifestOp;
private VerifyPackageOperation _verifyOperation; private VerifyPackageOperation _verifyOperation;
private PatchManifest _verifyManifest;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal HostPlayModeCheckContentsIntegrityOperation(HostPlayModeImpl impl, string packageName) internal HostPlayModeCheckPackageContentsOperation(HostPlayModeImpl impl, string packageName, string packageVersion)
{ {
_impl = impl; _impl = impl;
_packageName = packageName; _packageName = packageName;
_packageVersion = packageVersion;
} }
internal override void Start() internal override void Start()
{ {
_steps = ESteps.CheckLoadedManifest; _steps = ESteps.CheckActiveManifest;
} }
internal override void Update() internal override void Update()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; return;
if (_steps == ESteps.CheckLoadedManifest) if (_steps == ESteps.CheckActiveManifest)
{ {
if (_impl.ActiveManifest == null) // 检测当前激活的清单对象
if (_impl.ActiveManifest != null && _impl.ActiveManifest.PackageVersion == _packageVersion)
{ {
_steps = ESteps.Done; _verifyManifest = _impl.ActiveManifest;
Status = EOperationStatus.Failed; _steps = ESteps.VerifyPackage;
Error = $"Not found loaded package : {_packageName}";
} }
else else
{ {
_steps = ESteps.LoadCacheManifest;
}
}
if (_steps == ESteps.LoadCacheManifest)
{
if (_loadCacheManifestOp == null)
{
_loadCacheManifestOp = new LoadCacheManifestOperation(_packageName, _packageVersion);
OperationSystem.StartOperation(_loadCacheManifestOp);
}
if (_loadCacheManifestOp.IsDone == false)
return;
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
{
_verifyManifest = _loadCacheManifestOp.Manifest;
_steps = ESteps.VerifyPackage; _steps = ESteps.VerifyPackage;
} }
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadCacheManifestOp.Error;
}
} }
if (_steps == ESteps.VerifyPackage) if (_steps == ESteps.VerifyPackage)
{ {
if (_verifyOperation == null) if (_verifyOperation == null)
{ {
_verifyOperation = VerifyPackageOperation.CreateOperation(_impl.ActiveManifest, _impl); _verifyOperation = VerifyPackageOperation.CreateOperation(_verifyManifest, _impl);
OperationSystem.StartOperation(_verifyOperation); OperationSystem.StartOperation(_verifyOperation);
} }

View File

@ -184,8 +184,7 @@ namespace YooAsset
QueryCachePackageVersion, QueryCachePackageVersion,
TryLoadCacheManifest, TryLoadCacheManifest,
QueryBuildinPackageVersion, QueryBuildinPackageVersion,
CopyBuildinPackageHash, UnpackBuildinManifest,
CopyBuildinManifest,
LoadBuildinManifest, LoadBuildinManifest,
VerifyPackage, VerifyPackage,
Done, Done,
@ -195,8 +194,7 @@ namespace YooAsset
private readonly string _packageName; private readonly string _packageName;
private QueryBuildinPackageVersionOperation _queryBuildinPackageVersionOp; private QueryBuildinPackageVersionOperation _queryBuildinPackageVersionOp;
private QueryCachePackageVersionOperation _queryCachePackageVersionOp; private QueryCachePackageVersionOperation _queryCachePackageVersionOp;
private CopyBuildinPackageHashOperation _copyBuildinPackageHashOp; private UnpackBuildinManifestOperation _unpackBuildinManifestOp;
private CopyBuildinManifestOperation _copyBuildinManifestOp;
private LoadBuildinManifestOperation _loadBuildinManifestOp; private LoadBuildinManifestOperation _loadBuildinManifestOp;
private LoadCacheManifestOperation _loadCacheManifestOp; private LoadCacheManifestOperation _loadCacheManifestOp;
private VerifyPackageOperation _verifyOperation; private VerifyPackageOperation _verifyOperation;
@ -289,7 +287,7 @@ namespace YooAsset
// 注意为了兼容MOD模式初始化动态新增的包裹的时候如果内置清单不存在也不需要报错 // 注意为了兼容MOD模式初始化动态新增的包裹的时候如果内置清单不存在也不需要报错
if (_queryBuildinPackageVersionOp.Status == EOperationStatus.Succeed) if (_queryBuildinPackageVersionOp.Status == EOperationStatus.Succeed)
{ {
_steps = ESteps.CopyBuildinPackageHash; _steps = ESteps.UnpackBuildinManifest;
} }
else else
{ {
@ -300,41 +298,18 @@ namespace YooAsset
} }
} }
if (_steps == ESteps.CopyBuildinPackageHash) if (_steps == ESteps.UnpackBuildinManifest)
{ {
if (_copyBuildinPackageHashOp == null) if (_unpackBuildinManifestOp == null)
{ {
_copyBuildinPackageHashOp = new CopyBuildinPackageHashOperation(_packageName, _queryBuildinPackageVersionOp.PackageVersion); _unpackBuildinManifestOp = new UnpackBuildinManifestOperation(_packageName, _queryBuildinPackageVersionOp.PackageVersion);
OperationSystem.StartOperation(_copyBuildinPackageHashOp); OperationSystem.StartOperation(_unpackBuildinManifestOp);
} }
if (_copyBuildinPackageHashOp.IsDone == false) if (_unpackBuildinManifestOp.IsDone == false)
return; return;
if (_copyBuildinPackageHashOp.Status == EOperationStatus.Succeed) if (_unpackBuildinManifestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.CopyBuildinManifest;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _copyBuildinPackageHashOp.Error;
}
}
if (_steps == ESteps.CopyBuildinManifest)
{
if (_copyBuildinManifestOp == null)
{
_copyBuildinManifestOp = new CopyBuildinManifestOperation(_packageName, _queryBuildinPackageVersionOp.PackageVersion);
OperationSystem.StartOperation(_copyBuildinManifestOp);
}
if (_copyBuildinManifestOp.IsDone == false)
return;
if (_copyBuildinManifestOp.Status == EOperationStatus.Succeed)
{ {
_steps = ESteps.LoadBuildinManifest; _steps = ESteps.LoadBuildinManifest;
} }
@ -342,7 +317,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _copyBuildinManifestOp.Error; Error = _unpackBuildinManifestOp.Error;
} }
} }

View File

@ -1,63 +0,0 @@

namespace YooAsset
{
internal class CopyBuildinManifestOperation : AsyncOperationBase
{
private enum ESteps
{
None,
CopyBuildinManifestFile,
Done,
}
private readonly string _buildinPackageName;
private readonly string _buildinPackageVersion;
private UnityWebFileRequester _downloader;
private ESteps _steps = ESteps.None;
public CopyBuildinManifestOperation(string buildinPackageName, string buildinPackageVersion)
{
_buildinPackageName = buildinPackageName;
_buildinPackageVersion = buildinPackageVersion;
}
internal override void Start()
{
_steps = ESteps.CopyBuildinManifestFile;
}
internal override void Update()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CopyBuildinManifestFile)
{
if (_downloader == null)
{
string savePath = PersistentHelper.GetCacheManifestFilePath(_buildinPackageName, _buildinPackageVersion);
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
string url = PathHelper.ConvertToWWWPath(filePath);
_downloader = new UnityWebFileRequester();
_downloader.SendRequest(url, savePath);
}
if (_downloader.IsDone() == false)
return;
if (_downloader.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloader.GetError();
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
_downloader.Dispose();
}
}
}
}

View File

@ -1,63 +0,0 @@

namespace YooAsset
{
internal class CopyBuildinPackageHashOperation : AsyncOperationBase
{
private enum ESteps
{
None,
CopyBuildinPackageHashFile,
Done,
}
private readonly string _buildinPackageName;
private readonly string _buildinPackageVersion;
private UnityWebFileRequester _downloader;
private ESteps _steps = ESteps.None;
public CopyBuildinPackageHashOperation(string buildinPackageName, string buildinPackageVersion)
{
_buildinPackageName = buildinPackageName;
_buildinPackageVersion = buildinPackageVersion;
}
internal override void Start()
{
_steps = ESteps.CopyBuildinPackageHashFile;
}
internal override void Update()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CopyBuildinPackageHashFile)
{
if (_downloader == null)
{
string savePath = PersistentHelper.GetCachePackageHashFilePath(_buildinPackageName, _buildinPackageVersion);
string fileName = YooAssetSettingsData.GetPackageHashFileName(_buildinPackageName, _buildinPackageVersion);
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
string url = PathHelper.ConvertToWWWPath(filePath);
_downloader = new UnityWebFileRequester();
_downloader.SendRequest(url, savePath);
}
if (_downloader.IsDone() == false)
return;
if (_downloader.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloader.GetError();
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
_downloader.Dispose();
}
}
}
}

View File

@ -6,8 +6,8 @@ namespace YooAsset
private enum ESteps private enum ESteps
{ {
None, None,
DownloadPackageHash, DownloadPackageHashFile,
DownloadManifest, DownloadManifestFile,
Done, Done,
} }
@ -30,14 +30,14 @@ namespace YooAsset
internal override void Start() internal override void Start()
{ {
RequestCount++; RequestCount++;
_steps = ESteps.DownloadPackageHash; _steps = ESteps.DownloadPackageHashFile;
} }
internal override void Update() internal override void Update()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; return;
if (_steps == ESteps.DownloadPackageHash) if (_steps == ESteps.DownloadPackageHashFile)
{ {
if (_downloader1 == null) if (_downloader1 == null)
{ {
@ -61,13 +61,13 @@ namespace YooAsset
} }
else else
{ {
_steps = ESteps.DownloadManifest; _steps = ESteps.DownloadManifestFile;
} }
_downloader1.Dispose(); _downloader1.Dispose();
} }
if (_steps == ESteps.DownloadManifest) if (_steps == ESteps.DownloadManifestFile)
{ {
if (_downloader2 == null) if (_downloader2 == null)
{ {

View File

@ -0,0 +1,103 @@
using System.IO;
namespace YooAsset
{
internal class QueryRemotePackageVersionOperation : AsyncOperationBase
{
private enum ESteps
{
None,
DownloadPackageVersion,
Done,
}
private static int RequestCount = 0;
private readonly HostPlayModeImpl _impl;
private readonly string _packageName;
private readonly bool _appendTimeTicks;
private readonly int _timeout;
private UnityWebDataRequester _downloader;
private ESteps _steps = ESteps.None;
/// <summary>
/// 包裹版本
/// </summary>
public string PackageVersion { private set; get; }
public QueryRemotePackageVersionOperation(HostPlayModeImpl impl, string packageName, bool appendTimeTicks, int timeout)
{
_impl = impl;
_packageName = packageName;
_appendTimeTicks = appendTimeTicks;
_timeout = timeout;
}
internal override void Start()
{
RequestCount++;
_steps = ESteps.DownloadPackageVersion;
}
internal override void Update()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.DownloadPackageVersion)
{
if (_downloader == null)
{
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
string webURL = GetPackageVersionRequestURL(fileName);
YooLogger.Log($"Beginning to request package version : {webURL}");
_downloader = new UnityWebDataRequester();
_downloader.SendRequest(webURL, _timeout);
}
Progress = _downloader.Progress();
if (_downloader.IsDone() == false)
return;
if (_downloader.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloader.GetError();
}
else
{
PackageVersion = _downloader.GetText();
if (string.IsNullOrEmpty(PackageVersion))
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Remote package version is empty : {_downloader.URL}";
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
}
_downloader.Dispose();
}
}
private string GetPackageVersionRequestURL(string fileName)
{
string url;
// 轮流返回请求地址
if (RequestCount % 2 == 0)
url = _impl.GetPatchDownloadFallbackURL(fileName);
else
url = _impl.GetPatchDownloadMainURL(fileName);
// 在URL末尾添加时间戳
if (_appendTimeTicks)
return $"{url}?{System.DateTime.UtcNow.Ticks}";
else
return url;
}
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: bb073431e4f3b434e8431b3a8a808dfb guid: 1d702a1a39789a34da99cbb854708b82
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -0,0 +1,94 @@

namespace YooAsset
{
internal class UnpackBuildinManifestOperation : AsyncOperationBase
{
private enum ESteps
{
None,
UnpackManifestHashFile,
UnpackManifestFile,
Done,
}
private readonly string _buildinPackageName;
private readonly string _buildinPackageVersion;
private UnityWebFileRequester _downloader1;
private UnityWebFileRequester _downloader2;
private ESteps _steps = ESteps.None;
public UnpackBuildinManifestOperation(string buildinPackageName, string buildinPackageVersion)
{
_buildinPackageName = buildinPackageName;
_buildinPackageVersion = buildinPackageVersion;
}
internal override void Start()
{
_steps = ESteps.UnpackManifestHashFile;
}
internal override void Update()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if(_steps == ESteps.UnpackManifestHashFile)
{
if (_downloader1 == null)
{
string savePath = PersistentHelper.GetCachePackageHashFilePath(_buildinPackageName, _buildinPackageVersion);
string fileName = YooAssetSettingsData.GetPackageHashFileName(_buildinPackageName, _buildinPackageVersion);
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
string url = PathHelper.ConvertToWWWPath(filePath);
_downloader1 = new UnityWebFileRequester();
_downloader1.SendRequest(url, savePath);
}
if (_downloader1.IsDone() == false)
return;
if (_downloader1.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloader1.GetError();
}
else
{
_steps = ESteps.UnpackManifestFile;
}
_downloader1.Dispose();
}
if (_steps == ESteps.UnpackManifestFile)
{
if (_downloader2 == null)
{
string savePath = PersistentHelper.GetCacheManifestFilePath(_buildinPackageName, _buildinPackageVersion);
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_buildinPackageName, _buildinPackageVersion);
string filePath = PathHelper.MakeStreamingLoadPath(fileName);
string url = PathHelper.ConvertToWWWPath(filePath);
_downloader2 = new UnityWebFileRequester();
_downloader2.SendRequest(url, savePath);
}
if (_downloader2.IsDone() == false)
return;
if (_downloader2.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloader2.GetError();
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
_downloader2.Dispose();
}
}
}
}

View File

@ -64,7 +64,6 @@ namespace YooAsset
{ {
} }
} }
public class OfflinePlayModePreDownloadPackageOperation : PreDownloadPackageOperation public class OfflinePlayModePreDownloadPackageOperation : PreDownloadPackageOperation
{ {
internal override void Start() internal override void Start()
@ -75,7 +74,6 @@ namespace YooAsset
{ {
} }
} }
public class HostPlayModePreDownloadPackageOperation : PreDownloadPackageOperation public class HostPlayModePreDownloadPackageOperation : PreDownloadPackageOperation
{ {
private enum ESteps private enum ESteps

View File

@ -47,7 +47,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 联机模式的更新清单操作 /// 联机模式的更新清单操作
/// 注意:优先比对沙盒清单哈希值,如果有变化就更新远端清单文件,并保存到本地。 /// 注意:优先加载沙盒里缓存的清单文件,如果有变化就更新远端清单文件,并保存到本地。
/// </summary> /// </summary>
internal sealed class HostPlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation internal sealed class HostPlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
{ {
@ -93,16 +93,15 @@ namespace YooAsset
if (_steps == ESteps.CheckActiveManifest) if (_steps == ESteps.CheckActiveManifest)
{ {
// 检测当前激活的清单对象 // 检测当前激活的清单对象
if (_impl.ActiveManifest != null) if (_impl.ActiveManifest != null && _impl.ActiveManifest.PackageVersion == _packageVersion)
{ {
if (_impl.ActiveManifest.PackageVersion == _packageVersion) _steps = ESteps.Done;
{ Status = EOperationStatus.Succeed;
_steps = ESteps.Done; }
Status = EOperationStatus.Succeed; else
return; {
} _steps = ESteps.TryLoadCacheManifest;
} }
_steps = ESteps.TryLoadCacheManifest;
} }
if (_steps == ESteps.TryLoadCacheManifest) if (_steps == ESteps.TryLoadCacheManifest)

View File

@ -51,16 +51,15 @@ namespace YooAsset
private enum ESteps private enum ESteps
{ {
None, None,
DownloadPackageVersion, QueryRemotePackageVersion,
Done, Done,
} }
private static int RequestCount = 0;
private readonly HostPlayModeImpl _impl; private readonly HostPlayModeImpl _impl;
private readonly string _packageName; private readonly string _packageName;
private readonly bool _appendTimeTicks; private readonly bool _appendTimeTicks;
private readonly int _timeout; private readonly int _timeout;
private UnityWebDataRequester _downloader; private QueryRemotePackageVersionOperation _queryRemotePackageVersionOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal HostPlayModeUpdatePackageVersionOperation(HostPlayModeImpl impl, string packageName, bool appendTimeTicks, int timeout) internal HostPlayModeUpdatePackageVersionOperation(HostPlayModeImpl impl, string packageName, bool appendTimeTicks, int timeout)
@ -72,70 +71,37 @@ namespace YooAsset
} }
internal override void Start() internal override void Start()
{ {
RequestCount++; _steps = ESteps.QueryRemotePackageVersion;
_steps = ESteps.DownloadPackageVersion;
} }
internal override void Update() internal override void Update()
{ {
if (_steps == ESteps.None || _steps == ESteps.Done) if (_steps == ESteps.None || _steps == ESteps.Done)
return; return;
if (_steps == ESteps.DownloadPackageVersion) if (_steps == ESteps.QueryRemotePackageVersion)
{ {
if (_downloader == null) if (_queryRemotePackageVersionOp == null)
{ {
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName); _queryRemotePackageVersionOp = new QueryRemotePackageVersionOperation(_impl, _packageName, _appendTimeTicks, _timeout);
string webURL = GetPackageVersionRequestURL(fileName); OperationSystem.StartOperation(_queryRemotePackageVersionOp);
YooLogger.Log($"Beginning to request package version : {webURL}");
_downloader = new UnityWebDataRequester();
_downloader.SendRequest(webURL, _timeout);
} }
Progress = _downloader.Progress(); if (_queryRemotePackageVersionOp.IsDone == false)
if (_downloader.IsDone() == false)
return; return;
if (_downloader.HasError()) if (_queryRemotePackageVersionOp.Status == EOperationStatus.Succeed)
{ {
PackageVersion = _queryRemotePackageVersionOp.PackageVersion;
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Succeed;
Error = _downloader.GetError();
} }
else else
{ {
PackageVersion = _downloader.GetText(); _steps = ESteps.Done;
if (string.IsNullOrEmpty(PackageVersion)) Status = EOperationStatus.Failed;
{ Error = _queryRemotePackageVersionOp.Error;
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Package version is empty : {_downloader.URL}";
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
} }
_downloader.Dispose();
} }
} }
private string GetPackageVersionRequestURL(string fileName)
{
string url;
// 轮流返回请求地址
if (RequestCount % 2 == 0)
url = _impl.GetPatchDownloadFallbackURL(fileName);
else
url = _impl.GetPatchDownloadMainURL(fileName);
// 在URL末尾添加时间戳
if (_appendTimeTicks)
return $"{url}?{System.DateTime.UtcNow.Ticks}";
else
return url;
}
} }
} }

View File

@ -7,15 +7,13 @@ namespace YooAsset
internal class EditorSimulateModeImpl : IPlayModeServices, IBundleServices internal class EditorSimulateModeImpl : IPlayModeServices, IBundleServices
{ {
private PatchManifest _activeManifest; private PatchManifest _activeManifest;
private string _packageName;
private bool _locationToLower; private bool _locationToLower;
/// <summary> /// <summary>
/// 异步初始化 /// 异步初始化
/// </summary> /// </summary>
public InitializationOperation InitializeAsync(string packageName, bool locationToLower, string simulatePatchManifestPath) public InitializationOperation InitializeAsync(bool locationToLower, string simulatePatchManifestPath)
{ {
_packageName = packageName;
_locationToLower = locationToLower; _locationToLower = locationToLower;
var operation = new EditorSimulateModeInitializationOperation(this, simulatePatchManifestPath); var operation = new EditorSimulateModeInitializationOperation(this, simulatePatchManifestPath);
OperationSystem.StartOperation(operation); OperationSystem.StartOperation(operation);
@ -52,9 +50,15 @@ namespace YooAsset
OperationSystem.StartOperation(operation); OperationSystem.StartOperation(operation);
return operation; return operation;
} }
CheckContentsIntegrityOperation IPlayModeServices.CheckContentsIntegrityAsync() PreDownloadPackageOperation IPlayModeServices.PreDownloadPackageAsync(string packageVersion, int timeout)
{ {
var operation = new EditorSimulateModeCheckContentsIntegrityOperation(); var operation = new EditorPlayModePreDownloadPackageOperation();
OperationSystem.StartOperation(operation);
return operation;
}
CheckPackageContentsOperation IPlayModeServices.CheckPackageContentsOperation(string packageVersion)
{
var operation = new EditorSimulateModeCheckPackageContentsOperation();
OperationSystem.StartOperation(operation); OperationSystem.StartOperation(operation);
return operation; return operation;
} }

View File

@ -110,9 +110,15 @@ namespace YooAsset
OperationSystem.StartOperation(operation); OperationSystem.StartOperation(operation);
return operation; return operation;
} }
CheckContentsIntegrityOperation IPlayModeServices.CheckContentsIntegrityAsync() PreDownloadPackageOperation IPlayModeServices.PreDownloadPackageAsync(string packageVersion, int timeout)
{ {
var operation = new HostPlayModeCheckContentsIntegrityOperation(this, _packageName); var operation = new HostPlayModePreDownloadPackageOperation(this, _packageName, packageVersion, timeout);
OperationSystem.StartOperation(operation);
return operation;
}
CheckPackageContentsOperation IPlayModeServices.CheckPackageContentsOperation(string packageVersion)
{
var operation = new HostPlayModeCheckPackageContentsOperation(this, _packageName, packageVersion);
OperationSystem.StartOperation(operation); OperationSystem.StartOperation(operation);
return operation; return operation;
} }

View File

@ -7,7 +7,6 @@ namespace YooAsset
internal class OfflinePlayModeImpl : IPlayModeServices, IBundleServices internal class OfflinePlayModeImpl : IPlayModeServices, IBundleServices
{ {
private PatchManifest _activeManifest; private PatchManifest _activeManifest;
private string _packageName;
private bool _locationToLower; private bool _locationToLower;
/// <summary> /// <summary>
@ -15,7 +14,6 @@ namespace YooAsset
/// </summary> /// </summary>
public InitializationOperation InitializeAsync(string packageName, bool locationToLower) public InitializationOperation InitializeAsync(string packageName, bool locationToLower)
{ {
_packageName = packageName;
_locationToLower = locationToLower; _locationToLower = locationToLower;
var operation = new OfflinePlayModeInitializationOperation(this, packageName); var operation = new OfflinePlayModeInitializationOperation(this, packageName);
OperationSystem.StartOperation(operation); OperationSystem.StartOperation(operation);
@ -52,9 +50,15 @@ namespace YooAsset
OperationSystem.StartOperation(operation); OperationSystem.StartOperation(operation);
return operation; return operation;
} }
CheckContentsIntegrityOperation IPlayModeServices.CheckContentsIntegrityAsync() PreDownloadPackageOperation IPlayModeServices.PreDownloadPackageAsync(string packageVersion, int timeout)
{ {
var operation = new OfflinePlayModeCheckContentsIntegrityOperation(); var operation = new OfflinePlayModePreDownloadPackageOperation();
OperationSystem.StartOperation(operation);
return operation;
}
CheckPackageContentsOperation IPlayModeServices.CheckPackageContentsOperation(string packageVersion)
{
var operation = new OfflinePlayModeCheckPackageContentsOperation();
OperationSystem.StartOperation(operation); OperationSystem.StartOperation(operation);
return operation; return operation;
} }

View File

@ -23,10 +23,15 @@ namespace YooAsset
/// </summary> /// </summary>
UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout); UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout);
/// <summary>
/// 预下载指定版本的包裹资源
/// </summary>
PreDownloadPackageOperation PreDownloadPackageAsync(string packageVersion, int timeout);
/// <summary> /// <summary>
/// 检查包裹内容的完整性 /// 检查包裹内容的完整性
/// </summary> /// </summary>
CheckContentsIntegrityOperation CheckContentsIntegrityAsync(); CheckPackageContentsOperation CheckPackageContentsOperation(string packageVersion);
// 下载相关 // 下载相关
PatchDownloaderOperation CreatePatchDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout); PatchDownloaderOperation CreatePatchDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout);