update download system
parent
a5e24be5d4
commit
bcf6372602
|
@ -1,28 +0,0 @@
|
||||||
using JetBrains.Annotations;
|
|
||||||
using UnityEngine.Networking;
|
|
||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
public delegate UnityWebRequest DownloadRequestDelegate(string url);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 自定义下载器的请求
|
|
||||||
/// </summary>
|
|
||||||
internal static class DownloadRequestUtil
|
|
||||||
{
|
|
||||||
|
|
||||||
[CanBeNull] private static DownloadRequestDelegate _downloadRequestDelegate;
|
|
||||||
|
|
||||||
public static void SetRequestDelegate(DownloadRequestDelegate requestDelegate)
|
|
||||||
{
|
|
||||||
_downloadRequestDelegate = requestDelegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UnityWebRequest NewRequest(string requestURL)
|
|
||||||
{
|
|
||||||
return _downloadRequestDelegate != null
|
|
||||||
? _downloadRequestDelegate?.Invoke(requestURL)
|
|
||||||
: new UnityWebRequest(requestURL, UnityWebRequest.kHttpVerbGET);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 3b21da9f048045e2af56d9d396b11c2f
|
|
||||||
timeCreated: 1677207036
|
|
|
@ -6,6 +6,11 @@ using UnityEngine.Networking;
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 自定义下载器的请求委托
|
||||||
|
/// </summary>
|
||||||
|
public delegate UnityWebRequest DownloadRequestDelegate(string url);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 1. 保证每一时刻资源文件只存在一个下载器
|
/// 1. 保证每一时刻资源文件只存在一个下载器
|
||||||
/// 2. 保证下载器下载完成后立刻验证并缓存
|
/// 2. 保证下载器下载完成后立刻验证并缓存
|
||||||
|
@ -17,10 +22,15 @@ namespace YooAsset
|
||||||
private static readonly List<string> _removeList = new List<string>(100);
|
private static readonly List<string> _removeList = new List<string>(100);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 自定义下载器的请求委托
|
||||||
|
/// </summary>
|
||||||
|
public static DownloadRequestDelegate RequestDelegate = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 自定义的证书认证实例
|
/// 自定义的证书认证实例
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static CertificateHandler CertificateHandlerInstance;
|
public static CertificateHandler CertificateHandlerInstance = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 启用断点续传功能文件的最小字节数
|
/// 启用断点续传功能文件的最小字节数
|
||||||
|
@ -32,14 +42,6 @@ namespace YooAsset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static List<long> ClearFileResponseCodes { set; get; }
|
public static List<long> ClearFileResponseCodes { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 自定义下载请求
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="requestDelegate"></param>
|
|
||||||
public static void SetRequestDelegate(DownloadRequestDelegate requestDelegate)
|
|
||||||
{
|
|
||||||
DownloadRequestUtil.SetRequestDelegate(requestDelegate);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新所有下载器
|
/// 更新所有下载器
|
||||||
|
@ -75,7 +77,11 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
_downloaderDic.Clear();
|
_downloaderDic.Clear();
|
||||||
_removeList.Clear();
|
_removeList.Clear();
|
||||||
|
|
||||||
|
RequestDelegate = null;
|
||||||
|
CertificateHandlerInstance = null;
|
||||||
BreakpointResumeFileSize = int.MaxValue;
|
BreakpointResumeFileSize = int.MaxValue;
|
||||||
|
ClearFileResponseCodes.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,6 +116,18 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建一个新的网络请求
|
||||||
|
/// </summary>
|
||||||
|
public static UnityWebRequest NewRequest(string requestURL)
|
||||||
|
{
|
||||||
|
if (RequestDelegate != null)
|
||||||
|
return RequestDelegate.Invoke(requestURL);
|
||||||
|
|
||||||
|
var request = new UnityWebRequest(requestURL, UnityWebRequest.kHttpVerbGET);
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取下载器的总数
|
/// 获取下载器的总数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -80,7 +80,7 @@ namespace YooAsset
|
||||||
if (File.Exists(_tempFilePath))
|
if (File.Exists(_tempFilePath))
|
||||||
File.Delete(_tempFilePath);
|
File.Delete(_tempFilePath);
|
||||||
|
|
||||||
_webRequest = DownloadRequestUtil.NewRequest(_requestURL);
|
_webRequest = DownloadSystem.NewRequest(_requestURL);
|
||||||
DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath);
|
DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath);
|
||||||
handler.removeFileOnAbort = true;
|
handler.removeFileOnAbort = true;
|
||||||
_webRequest.downloadHandler = handler;
|
_webRequest.downloadHandler = handler;
|
||||||
|
@ -109,11 +109,11 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_2019_4_OR_NEWER
|
#if UNITY_2019_4_OR_NEWER
|
||||||
_webRequest = DownloadRequestUtil.NewRequest(_requestURL);
|
_webRequest = DownloadSystem.NewRequest(_requestURL);
|
||||||
var handler = new DownloadHandlerFile(_tempFilePath, true);
|
var handler = new DownloadHandlerFile(_tempFilePath, true);
|
||||||
handler.removeFileOnAbort = false;
|
handler.removeFileOnAbort = false;
|
||||||
#else
|
#else
|
||||||
_webRequest = UnityWebRequestUtil.NewRequest(_requestURL);
|
_webRequest = DownloadSystem.NewRequest(_requestURL);
|
||||||
var handler = new DownloadHandlerFileRange(_tempFilePath, _bundleInfo.Bundle.FileSize, _webRequest);
|
var handler = new DownloadHandlerFileRange(_tempFilePath, _bundleInfo.Bundle.FileSize, _webRequest);
|
||||||
_downloadHandle = handler;
|
_downloadHandle = handler;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace YooAsset
|
||||||
if (_webRequest == null)
|
if (_webRequest == null)
|
||||||
{
|
{
|
||||||
URL = url;
|
URL = url;
|
||||||
_webRequest = DownloadRequestUtil.NewRequest(URL);
|
_webRequest = DownloadSystem.NewRequest(URL);
|
||||||
DownloadHandlerBuffer handler = new DownloadHandlerBuffer();
|
DownloadHandlerBuffer handler = new DownloadHandlerBuffer();
|
||||||
_webRequest.downloadHandler = handler;
|
_webRequest.downloadHandler = handler;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace YooAsset
|
||||||
_latestDownloadBytes = 0;
|
_latestDownloadBytes = 0;
|
||||||
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
||||||
|
|
||||||
_webRequest = DownloadRequestUtil.NewRequest(URL);
|
_webRequest = DownloadSystem.NewRequest(URL);
|
||||||
DownloadHandlerFile handler = new DownloadHandlerFile(savePath);
|
DownloadHandlerFile handler = new DownloadHandlerFile(savePath);
|
||||||
handler.removeFileOnAbort = true;
|
handler.removeFileOnAbort = true;
|
||||||
_webRequest.downloadHandler = handler;
|
_webRequest.downloadHandler = handler;
|
||||||
|
|
|
@ -168,15 +168,6 @@ namespace YooAsset
|
||||||
DownloadSystem.BreakpointResumeFileSize = fileBytes;
|
DownloadSystem.BreakpointResumeFileSize = fileBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 自定义下载请求
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="requestDelegate"></param>
|
|
||||||
public static void SetDownloadSystemUnityWebRequest(DownloadRequestDelegate requestDelegate)
|
|
||||||
{
|
|
||||||
DownloadSystem.SetRequestDelegate(requestDelegate);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置下载系统参数,下载失败后清理文件的HTTP错误码
|
/// 设置下载系统参数,下载失败后清理文件的HTTP错误码
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -193,6 +184,14 @@ namespace YooAsset
|
||||||
DownloadSystem.CertificateHandlerInstance = instance;
|
DownloadSystem.CertificateHandlerInstance = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置下载系统参数,自定义下载请求
|
||||||
|
/// </summary>
|
||||||
|
public static void SetDownloadSystemUnityWebRequest(DownloadRequestDelegate requestDelegate)
|
||||||
|
{
|
||||||
|
DownloadSystem.RequestDelegate = requestDelegate;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置异步系统参数,每帧执行消耗的最大时间切片(单位:毫秒)
|
/// 设置异步系统参数,每帧执行消耗的最大时间切片(单位:毫秒)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue