update runtime code

This commit is contained in:
hevinci
2022-12-24 22:09:14 +08:00
parent a95697088b
commit 16943d4590
30 changed files with 922 additions and 511 deletions

View File

@@ -11,8 +11,8 @@ namespace YooAsset
/// </summary>
internal class UnityWebDataRequester
{
protected UnityWebRequest _webRequest;
protected UnityWebRequestAsyncOperation _operationHandle;
private UnityWebRequest _webRequest;
private UnityWebRequestAsyncOperation _operationHandle;
/// <summary>
/// 请求URL地址

View File

@@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Networking;
using UnityEngine;
namespace YooAsset
{
@@ -11,8 +12,14 @@ namespace YooAsset
/// </summary>
internal class UnityWebFileRequester
{
protected UnityWebRequest _webRequest;
protected UnityWebRequestAsyncOperation _operationHandle;
private UnityWebRequest _webRequest;
private UnityWebRequestAsyncOperation _operationHandle;
// 超时相关
private float _timeout;
private bool _isAbort = false;
private ulong _latestDownloadBytes;
private float _latestDownloadRealtime;
/// <summary>
/// 请求URL地址
@@ -23,11 +30,12 @@ namespace YooAsset
/// <summary>
/// 发送GET请求
/// </summary>
public void SendRequest(string url, string savePath)
public void SendRequest(string url, string savePath, float timeout = 60)
{
if (_webRequest == null)
{
URL = url;
_timeout = timeout;
_webRequest = new UnityWebRequest(URL, UnityWebRequest.kHttpVerbGET);
DownloadHandlerFile handler = new DownloadHandlerFile(savePath);
handler.removeFileOnAbort = true;
@@ -96,5 +104,28 @@ namespace YooAsset
}
return string.Empty;
}
/// <summary>
/// 检测超时
/// </summary>
public void CheckTimeout()
{
// 注意:在连续时间段内无新增下载数据及判定为超时
if (_isAbort == false)
{
if (_latestDownloadBytes != _webRequest.downloadedBytes)
{
_latestDownloadBytes = _webRequest.downloadedBytes;
_latestDownloadRealtime = Time.realtimeSinceStartup;
}
float offset = Time.realtimeSinceStartup - _latestDownloadRealtime;
if (offset > _timeout)
{
_webRequest.Abort();
_isAbort = true;
}
}
}
}
}