update runtime code

This commit is contained in:
hevinci
2022-12-17 22:37:39 +08:00
parent fc55b1be82
commit 2ace30acd8
16 changed files with 478 additions and 492 deletions
@@ -30,7 +30,7 @@ namespace YooAsset
}
private readonly PatchManifest _patchManifest;
private readonly IQueryServices _queryServices;
private readonly IPlayModeServices _playModeServices;
private ESteps _steps = ESteps.None;
private readonly ThreadSyncContext _syncContext = new ThreadSyncContext();
@@ -39,10 +39,10 @@ namespace YooAsset
private int _verifyMaxNum;
private int _verifyTotalCount;
public CacheFilesVerifyWithThreadOperation(PatchManifest patchManifest, IQueryServices queryServices)
public CacheFilesVerifyWithThreadOperation(PatchManifest patchManifest, IPlayModeServices playModeServices)
{
_patchManifest = patchManifest;
_queryServices = queryServices;
_playModeServices = playModeServices;
}
internal override void Start()
{
@@ -79,7 +79,7 @@ namespace YooAsset
if (CacheSystem.IsCached(patchBundle))
continue;
bool isBuildinFile = IsBuildinFile(patchBundle);
bool isBuildinFile = _playModeServices.IsBuildinPatchBundle(patchBundle);
VerifyInfo verifyInfo = new VerifyInfo(isBuildinFile, patchBundle);
_waitingList.Add(verifyInfo);
}
@@ -126,13 +126,6 @@ namespace YooAsset
return 1f;
return (float)(VerifySuccessList.Count + VerifyFailList.Count) / _verifyTotalCount;
}
private bool IsBuildinFile(PatchBundle patchBundle)
{
if (_queryServices == null)
return true;
return _queryServices.QueryStreamingAssets(patchBundle.FileName);
}
private bool VerifyFileWithThread(VerifyInfo verifyInfo)
{
return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), verifyInfo);
@@ -181,7 +174,7 @@ namespace YooAsset
}
private readonly PatchManifest _patchManifest;
private readonly IQueryServices _queryServices;
private readonly IPlayModeServices _playModeServices;
private ESteps _steps = ESteps.None;
private List<VerifyInfo> _waitingList;
@@ -189,10 +182,10 @@ namespace YooAsset
private int _verifyMaxNum;
private int _verifyTotalCount;
public CacheFilesVerifyWithoutThreadOperation(PatchManifest patchManifest, IQueryServices queryServices)
public CacheFilesVerifyWithoutThreadOperation(PatchManifest patchManifest, IPlayModeServices playModeServices)
{
_patchManifest = patchManifest;
_queryServices = queryServices;
_playModeServices = playModeServices;
}
internal override void Start()
{
@@ -225,7 +218,7 @@ namespace YooAsset
if (CacheSystem.IsCached(patchBundle))
continue;
bool isBuildinFile = IsBuildinFile(patchBundle);
bool isBuildinFile = _playModeServices.IsBuildinPatchBundle(patchBundle);
VerifyInfo verifyInfo = new VerifyInfo(isBuildinFile, patchBundle);
_waitingList.Add(verifyInfo);
}
@@ -265,13 +258,6 @@ namespace YooAsset
return 1f;
return (float)(VerifySuccessList.Count + VerifyFailList.Count) / _verifyTotalCount;
}
private bool IsBuildinFile(PatchBundle patchBundle)
{
if (_queryServices == null)
return true;
return _queryServices.QueryStreamingAssets(patchBundle.FileName);
}
private void VerifyFileWithoutThread(VerifyInfo verifyIno)
{
var verifyResult = CacheSystem.VerifyAndCacheLocalBundleFile(verifyIno.VerifyBundle, CacheSystem.InitVerifyLevel);
@@ -86,9 +86,9 @@ namespace YooAsset
if (_steps == ESteps.StartVerifyOperation)
{
#if UNITY_WEBGL
_verifyOperation = new CacheFilesVerifyWithoutThreadOperation(_impl.LocalPatchManifest, _impl.QueryServices);
_verifyOperation = new CacheFilesVerifyWithoutThreadOperation(_impl.ActivePatchManifest, _impl);
#else
_verifyOperation = new CacheFilesVerifyWithThreadOperation(_impl.ActivePatchManifest, _impl.QueryServices);
_verifyOperation = new CacheFilesVerifyWithThreadOperation(_impl.ActivePatchManifest, _impl);
#endif
OperationSystem.StartOperation(_verifyOperation);
@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using System.IO;
/*
namespace YooAsset
{
public abstract class DownloadPackageOperation : AsyncOperationBase
@@ -214,4 +215,5 @@ namespace YooAsset
return _impl.ConvertToDownloadList(downloadList);
}
}
}
}
*/
@@ -70,7 +70,7 @@ namespace YooAsset
{
var manifest = _deserializer.Manifest;
InitializedPackageVersion = manifest.PackageVersion;
_impl.SetActivePatchManifest(manifest);
_impl.ActivePatchManifest = manifest;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
@@ -160,7 +160,7 @@ namespace YooAsset
else
{
InitializedPackageVersion = manifest.PackageVersion;
_impl.SetActivePatchManifest(manifest);
_impl.ActivePatchManifest = manifest;
_steps = ESteps.StartVerifyOperation;
}
}
@@ -168,9 +168,9 @@ namespace YooAsset
if (_steps == ESteps.StartVerifyOperation)
{
#if UNITY_WEBGL
_verifyOperation = new CacheFilesVerifyWithoutThreadOperation(_impl.AppPatchManifest, null);
_verifyOperation = new CacheFilesVerifyWithoutThreadOperation(_impl.ActivePatchManifest, _impl);
#else
_verifyOperation = new CacheFilesVerifyWithThreadOperation(_impl.ActivePatchManifest, null);
_verifyOperation = new CacheFilesVerifyWithThreadOperation(_impl.ActivePatchManifest, _impl);
#endif
OperationSystem.StartOperation(_verifyOperation);
@@ -263,7 +263,7 @@ namespace YooAsset
if (manifest != null)
{
InitializedPackageVersion = manifest.PackageVersion;
_impl.SetActivePatchManifest(manifest);
_impl.ActivePatchManifest = manifest;
_steps = ESteps.StartVerifyOperation;
}
else
@@ -332,7 +332,7 @@ namespace YooAsset
else
{
InitializedPackageVersion = manifest.PackageVersion;
_impl.SetActivePatchManifest(manifest);
_impl.ActivePatchManifest = manifest;
_steps = ESteps.StartVerifyOperation;
}
}
@@ -340,9 +340,9 @@ namespace YooAsset
if (_steps == ESteps.StartVerifyOperation)
{
#if UNITY_WEBGL
_verifyOperation = new CacheFilesVerifyWithoutThreadOperation(_impl.LocalPatchManifest, _impl.QueryServices);
_verifyOperation = new CacheFilesVerifyWithoutThreadOperation(_impl.ActivePatchManifest, _impl);
#else
_verifyOperation = new CacheFilesVerifyWithThreadOperation(_impl.ActivePatchManifest, _impl.QueryServices);
_verifyOperation = new CacheFilesVerifyWithThreadOperation(_impl.ActivePatchManifest, _impl);
#endif
OperationSystem.StartOperation(_verifyOperation);
@@ -68,6 +68,8 @@ namespace YooAsset
private readonly HostPlayModeImpl _impl;
private readonly string _packageName;
private readonly string _packageVersion;
private bool _autoSaveManifest;
private bool _autoActiveManifest;
private readonly int _timeout;
private UnityWebDataRequester _downloader1;
private UnityWebDataRequester _downloader2;
@@ -76,13 +78,16 @@ namespace YooAsset
private string _cacheManifestHash;
private ESteps _steps = ESteps.None;
private byte[] _fileBytes = null;
private float _verifyTime;
internal HostPlayModeUpdatePackageManifestOperation(HostPlayModeImpl impl, string packageName, string packageVersion, int timeout)
internal HostPlayModeUpdatePackageManifestOperation(HostPlayModeImpl impl, string packageName, string packageVersion, bool autoSaveManifest, bool autoActiveManifest, int timeout)
{
_impl = impl;
_packageName = packageName;
_packageVersion = packageVersion;
_autoSaveManifest = autoSaveManifest;
_autoActiveManifest = autoActiveManifest;
_timeout = timeout;
}
internal override void Start()
@@ -171,16 +176,25 @@ namespace YooAsset
}
else
{
// 保存文件到沙盒内
byte[] bytesData = _downloader2.GetData();
string savePath = PersistentHelper.GetCacheManifestFilePath(_packageName);
FileUtility.CreateFile(savePath, bytesData);
// 保存文件到沙盒内
if (_autoSaveManifest)
{
string savePath = PersistentHelper.GetCacheManifestFilePath(_packageName);
FileUtility.CreateFile(savePath, bytesData);
}
else
{
_fileBytes = bytesData;
}
// 解析二进制数据
_deserializer = new DeserializeManifestOperation(bytesData);
OperationSystem.StartOperation(_deserializer);
_steps = ESteps.CheckDeserializeWebManifest;
}
_downloader2.Dispose();
}
@@ -191,7 +205,11 @@ namespace YooAsset
{
if (_deserializer.Status == EOperationStatus.Succeed)
{
_impl.SetActivePatchManifest(_deserializer.Manifest);
if (_autoActiveManifest)
{
_impl.ActivePatchManifest = _deserializer.Manifest;
}
FoundNewManifest = true;
_steps = ESteps.StartVerifyOperation;
}
@@ -207,9 +225,9 @@ namespace YooAsset
if (_steps == ESteps.StartVerifyOperation)
{
#if UNITY_WEBGL
_verifyOperation = new CacheFilesVerifyWithoutThreadOperation(_impl.LocalPatchManifest, _impl.QueryServices);
_verifyOperation = new CacheFilesVerifyWithoutThreadOperation(_deserializer.Manifest, _impl);
#else
_verifyOperation = new CacheFilesVerifyWithThreadOperation(_impl.ActivePatchManifest, _impl.QueryServices);
_verifyOperation = new CacheFilesVerifyWithThreadOperation(_deserializer.Manifest, _impl);
#endif
OperationSystem.StartOperation(_verifyOperation);
@@ -230,6 +248,37 @@ namespace YooAsset
}
}
/// <summary>
/// 手动保存清单文件
/// </summary>
public void SaveManifest()
{
if (_autoSaveManifest == false)
{
if (_fileBytes != null)
{
_autoSaveManifest = true;
string savePath = PersistentHelper.GetCacheManifestFilePath(_packageName);
FileUtility.CreateFile(savePath, _fileBytes);
}
}
}
/// <summary>
/// 手动激活清单文件
/// </summary>
public void ActiveManifest()
{
if (_autoActiveManifest == false)
{
if (_deserializer.Status == EOperationStatus.Succeed)
{
_autoActiveManifest = true;
_impl.ActivePatchManifest = _deserializer.Manifest;
}
}
}
/// <summary>
/// 获取补丁清单请求地址
/// </summary>
@@ -59,17 +59,17 @@ namespace YooAsset
private static int RequestCount = 0;
private readonly HostPlayModeImpl _impl;
private readonly string _packageName;
private readonly int _timeout;
private readonly bool _appendTimeTicks;
private readonly int _timeout;
private ESteps _steps = ESteps.None;
private UnityWebDataRequester _downloader;
internal HostPlayModeUpdatePackageVersionOperation(HostPlayModeImpl impl, string packageName, int timeout, bool appendTimeTicks)
internal HostPlayModeUpdatePackageVersionOperation(HostPlayModeImpl impl, string packageName, bool appendTimeTicks, int timeout)
{
_impl = impl;
_packageName = packageName;
_timeout = timeout;
_packageName = packageName;
_appendTimeTicks = appendTimeTicks;
_timeout = timeout;
}
internal override void Start()
{