mirror of https://github.com/tuyoogame/YooAsset
Update PatchSystem
parent
68430488b3
commit
cdef1358e0
|
@ -238,5 +238,13 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
YooLogger.Error($"Failed to download : {_requestURL} Error : {_lastError}");
|
YooLogger.Error($"Failed to download : {_requestURL} Error : {_lastError}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取最近一条错误日志
|
||||||
|
/// </summary>
|
||||||
|
public string GetLastError()
|
||||||
|
{
|
||||||
|
return _lastError;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,7 +9,7 @@ namespace YooAsset
|
||||||
/// 下载器
|
/// 下载器
|
||||||
/// 说明:UnityWebRequest(UWR) supports reading streaming assets since 2017.1
|
/// 说明:UnityWebRequest(UWR) supports reading streaming assets since 2017.1
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class UnityWebRequester
|
internal class UnityWebDataRequester
|
||||||
{
|
{
|
||||||
protected UnityWebRequest _webRequest;
|
protected UnityWebRequest _webRequest;
|
||||||
protected UnityWebRequestAsyncOperation _operationHandle;
|
protected UnityWebRequestAsyncOperation _operationHandle;
|
|
@ -0,0 +1,90 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 下载器
|
||||||
|
/// 说明:UnityWebRequest(UWR) supports reading streaming assets since 2017.1
|
||||||
|
/// </summary>
|
||||||
|
internal class UnityWebFileRequester
|
||||||
|
{
|
||||||
|
protected UnityWebRequest _webRequest;
|
||||||
|
protected UnityWebRequestAsyncOperation _operationHandle;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 请求URL地址
|
||||||
|
/// </summary>
|
||||||
|
public string URL { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发送GET请求
|
||||||
|
/// </summary>
|
||||||
|
public void SendRequest(string url, string savePath)
|
||||||
|
{
|
||||||
|
if (_webRequest == null)
|
||||||
|
{
|
||||||
|
URL = url;
|
||||||
|
_webRequest = new UnityWebRequest(URL, UnityWebRequest.kHttpVerbGET);
|
||||||
|
DownloadHandlerFile handler = new DownloadHandlerFile(savePath);
|
||||||
|
handler.removeFileOnAbort = true;
|
||||||
|
_webRequest.downloadHandler = handler;
|
||||||
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
|
_operationHandle = _webRequest.SendWebRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 释放下载器
|
||||||
|
/// </summary>
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (_webRequest != null)
|
||||||
|
{
|
||||||
|
_webRequest.Dispose();
|
||||||
|
_webRequest = null;
|
||||||
|
_operationHandle = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否完毕(无论成功失败)
|
||||||
|
/// </summary>
|
||||||
|
public bool IsDone()
|
||||||
|
{
|
||||||
|
if (_operationHandle == null)
|
||||||
|
return false;
|
||||||
|
return _operationHandle.isDone;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 下载是否发生错误
|
||||||
|
/// </summary>
|
||||||
|
public bool HasError()
|
||||||
|
{
|
||||||
|
#if UNITY_2020_3_OR_NEWER
|
||||||
|
return _webRequest.result != UnityWebRequest.Result.Success;
|
||||||
|
#else
|
||||||
|
if (_webRequest.isNetworkError || _webRequest.isHttpError)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取错误信息
|
||||||
|
/// </summary>
|
||||||
|
public string GetError()
|
||||||
|
{
|
||||||
|
if (_webRequest != null)
|
||||||
|
{
|
||||||
|
return $"URL : {URL} Error : {_webRequest.error}";
|
||||||
|
}
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2ab5f2486d06e2642ba7aa9c9623430e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -41,7 +41,7 @@ namespace YooAsset
|
||||||
|
|
||||||
private OfflinePlayModeImpl _impl;
|
private OfflinePlayModeImpl _impl;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
private UnityWebRequester _downloader;
|
private UnityWebDataRequester _downloader;
|
||||||
private string _downloadURL;
|
private string _downloadURL;
|
||||||
|
|
||||||
internal OfflinePlayModeInitializationOperation(OfflinePlayModeImpl impl)
|
internal OfflinePlayModeInitializationOperation(OfflinePlayModeImpl impl)
|
||||||
|
@ -61,7 +61,7 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
string filePath = PathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
|
string filePath = PathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
|
||||||
_downloadURL = PathHelper.ConvertToWWWPath(filePath);
|
_downloadURL = PathHelper.ConvertToWWWPath(filePath);
|
||||||
_downloader = new UnityWebRequester();
|
_downloader = new UnityWebDataRequester();
|
||||||
_downloader.SendRequest(_downloadURL);
|
_downloader.SendRequest(_downloadURL);
|
||||||
_steps = ESteps.CheckAppManifest;
|
_steps = ESteps.CheckAppManifest;
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ namespace YooAsset
|
||||||
|
|
||||||
private HostPlayModeImpl _impl;
|
private HostPlayModeImpl _impl;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
private UnityWebRequester _downloader;
|
private UnityWebDataRequester _downloader;
|
||||||
private string _downloadURL;
|
private string _downloadURL;
|
||||||
|
|
||||||
internal HostPlayModeInitializationOperation(HostPlayModeImpl impl)
|
internal HostPlayModeInitializationOperation(HostPlayModeImpl impl)
|
||||||
|
@ -151,7 +151,7 @@ namespace YooAsset
|
||||||
YooLogger.Log($"Load application patch manifest.");
|
YooLogger.Log($"Load application patch manifest.");
|
||||||
string filePath = PathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
|
string filePath = PathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
|
||||||
_downloadURL = PathHelper.ConvertToWWWPath(filePath);
|
_downloadURL = PathHelper.ConvertToWWWPath(filePath);
|
||||||
_downloader = new UnityWebRequester();
|
_downloader = new UnityWebDataRequester();
|
||||||
_downloader.SendRequest(_downloadURL);
|
_downloader.SendRequest(_downloadURL);
|
||||||
_steps = ESteps.CheckAppManifest;
|
_steps = ESteps.CheckAppManifest;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +64,8 @@ namespace YooAsset
|
||||||
private readonly int _updateResourceVersion;
|
private readonly int _updateResourceVersion;
|
||||||
private readonly int _timeout;
|
private readonly int _timeout;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
private UnityWebRequester _downloaderHash;
|
private UnityWebDataRequester _downloaderHash;
|
||||||
private UnityWebRequester _downloaderManifest;
|
private UnityWebDataRequester _downloaderManifest;
|
||||||
private float _verifyTime;
|
private float _verifyTime;
|
||||||
|
|
||||||
public HostPlayModeUpdateManifestOperation(HostPlayModeImpl impl, int updateResourceVersion, int timeout)
|
public HostPlayModeUpdateManifestOperation(HostPlayModeImpl impl, int updateResourceVersion, int timeout)
|
||||||
|
@ -97,7 +97,7 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
string webURL = GetPatchManifestRequestURL(_updateResourceVersion, ResourceSettingData.Setting.PatchManifestHashFileName);
|
string webURL = GetPatchManifestRequestURL(_updateResourceVersion, ResourceSettingData.Setting.PatchManifestHashFileName);
|
||||||
YooLogger.Log($"Beginning to request patch manifest hash : {webURL}");
|
YooLogger.Log($"Beginning to request patch manifest hash : {webURL}");
|
||||||
_downloaderHash = new UnityWebRequester();
|
_downloaderHash = new UnityWebDataRequester();
|
||||||
_downloaderHash.SendRequest(webURL, _timeout);
|
_downloaderHash.SendRequest(webURL, _timeout);
|
||||||
_steps = ESteps.CheckWebManifestHash;
|
_steps = ESteps.CheckWebManifestHash;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
string webURL = GetPatchManifestRequestURL(_updateResourceVersion, ResourceSettingData.Setting.PatchManifestFileName);
|
string webURL = GetPatchManifestRequestURL(_updateResourceVersion, ResourceSettingData.Setting.PatchManifestFileName);
|
||||||
YooLogger.Log($"Beginning to request patch manifest : {webURL}");
|
YooLogger.Log($"Beginning to request patch manifest : {webURL}");
|
||||||
_downloaderManifest = new UnityWebRequester();
|
_downloaderManifest = new UnityWebDataRequester();
|
||||||
_downloaderManifest.SendRequest(webURL, _timeout);
|
_downloaderManifest.SendRequest(webURL, _timeout);
|
||||||
_steps = ESteps.CheckWebManifest;
|
_steps = ESteps.CheckWebManifest;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue