update download system

新增方法YooAssets.SetDownloadSystemRedirectLimit()
mlyDevMerge1.5.7
hevinci 2023-06-29 15:47:10 +08:00 committed by QiJing
parent 480325827b
commit fb28bcc535
4 changed files with 45 additions and 21 deletions

View File

@ -171,17 +171,17 @@ namespace YooAsset
if (CacheSystem.DisableUnityCacheOnWebGL) if (CacheSystem.DisableUnityCacheOnWebGL)
{ {
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(FileLoadPath); _webRequest = UnityWebRequestAssetBundle.GetAssetBundle(FileLoadPath);
_webRequest.SendWebRequest();
_steps = ESteps.CheckLoadWebFile;
} }
else else
{ {
var hash = Hash128.Parse(MainBundleInfo.Bundle.FileHash); var hash = Hash128.Parse(MainBundleInfo.Bundle.FileHash);
_webRequest = UnityWebRequestAssetBundle.GetAssetBundle(FileLoadPath, hash); _webRequest = UnityWebRequestAssetBundle.GetAssetBundle(FileLoadPath, hash);
}
DownloadSystem.SetUnityWebRequest(_webRequest);
_webRequest.SendWebRequest(); _webRequest.SendWebRequest();
_steps = ESteps.CheckLoadWebFile; _steps = ESteps.CheckLoadWebFile;
} }
}
// 6. 检测AssetBundle加载结果 // 6. 检测AssetBundle加载结果
if (_steps == ESteps.CheckLoadWebFile) if (_steps == ESteps.CheckLoadWebFile)

View File

@ -32,6 +32,11 @@ namespace YooAsset
/// </summary> /// </summary>
public static CertificateHandler CertificateHandlerInstance = null; public static CertificateHandler CertificateHandlerInstance = null;
/// <summary>
/// 网络重定向次数
/// </summary>
public static int RedirectLimit { set; get; } = -1;
/// <summary> /// <summary>
/// 启用断点续传功能文件的最小字节数 /// 启用断点续传功能文件的最小字节数
/// </summary> /// </summary>
@ -128,11 +133,29 @@ namespace YooAsset
/// </summary> /// </summary>
public static UnityWebRequest NewRequest(string requestURL) public static UnityWebRequest NewRequest(string requestURL)
{ {
UnityWebRequest webRequest;
if (RequestDelegate != null) if (RequestDelegate != null)
return RequestDelegate.Invoke(requestURL); webRequest = RequestDelegate.Invoke(requestURL);
else
webRequest = new UnityWebRequest(requestURL, UnityWebRequest.kHttpVerbGET);
var request = new UnityWebRequest(requestURL, UnityWebRequest.kHttpVerbGET); SetUnityWebRequest(webRequest);
return request; return webRequest;
}
/// <summary>
/// 设置网络请求的自定义参数
/// </summary>
public static void SetUnityWebRequest(UnityWebRequest webRequest)
{
if (RedirectLimit >= 0)
webRequest.redirectLimit = RedirectLimit;
if (CertificateHandlerInstance != null)
{
webRequest.certificateHandler = CertificateHandlerInstance;
webRequest.disposeCertificateHandlerOnDispose = false;
}
} }
/// <summary> /// <summary>

View File

@ -101,13 +101,6 @@ namespace YooAsset
handler.removeFileOnAbort = true; handler.removeFileOnAbort = true;
_webRequest.downloadHandler = handler; _webRequest.downloadHandler = handler;
_webRequest.disposeDownloadHandlerOnDispose = true; _webRequest.disposeDownloadHandlerOnDispose = true;
if (DownloadSystem.CertificateHandlerInstance != null)
{
_webRequest.certificateHandler = DownloadSystem.CertificateHandlerInstance;
_webRequest.disposeCertificateHandlerOnDispose = false;
}
_webRequest.SendWebRequest(); _webRequest.SendWebRequest();
_steps = ESteps.CheckDownload; _steps = ESteps.CheckDownload;
} }
@ -137,13 +130,6 @@ namespace YooAsset
_webRequest.disposeDownloadHandlerOnDispose = true; _webRequest.disposeDownloadHandlerOnDispose = true;
if (fileLength > 0) if (fileLength > 0)
_webRequest.SetRequestHeader("Range", $"bytes={fileLength}-"); _webRequest.SetRequestHeader("Range", $"bytes={fileLength}-");
if (DownloadSystem.CertificateHandlerInstance != null)
{
_webRequest.certificateHandler = DownloadSystem.CertificateHandlerInstance;
_webRequest.disposeCertificateHandlerOnDispose = false;
}
_webRequest.SendWebRequest(); _webRequest.SendWebRequest();
_steps = ESteps.CheckDownload; _steps = ESteps.CheckDownload;
} }

View File

@ -217,6 +217,21 @@ namespace YooAsset
DownloadSystem.RequestDelegate = requestDelegate; DownloadSystem.RequestDelegate = requestDelegate;
} }
/// <summary>
/// 设置下载系统参数网络重定向次数Unity引擎默认值32
/// 注意:不支持设置为负值
/// </summary>
public static void SetDownloadSystemRedirectLimit(int redirectLimit)
{
if (redirectLimit < 0)
{
YooLogger.Warning($"Invalid param value : {redirectLimit}");
return;
}
DownloadSystem.RedirectLimit = redirectLimit;
}
/// <summary> /// <summary>
/// 设置异步系统参数,每帧执行消耗的最大时间切片(单位:毫秒) /// 设置异步系统参数,每帧执行消耗的最大时间切片(单位:毫秒)
/// </summary> /// </summary>