refactor : 重构网络下载模块
This commit is contained in:
+29
-3
@@ -58,6 +58,11 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
#region 自定义参数
|
||||
/// <summary>
|
||||
/// 自定义参数:UnityWebRequest 创建委托
|
||||
/// </summary>
|
||||
public UnityWebRequestCreator WebRequestCreator { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:覆盖安装缓存清理模式
|
||||
/// </summary>
|
||||
@@ -178,7 +183,15 @@ namespace YooAsset
|
||||
|
||||
public virtual void SetParameter(string name, object value)
|
||||
{
|
||||
if (name == FileSystemParametersDefine.INSTALL_CLEAR_MODE)
|
||||
if (name == FileSystemParametersDefine.DOWNLOAD_BACKEND)
|
||||
{
|
||||
DownloadBackend = (IDownloadBackend)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.UNITY_WEB_REQUEST_CREATOR)
|
||||
{
|
||||
WebRequestCreator = (UnityWebRequestCreator)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.INSTALL_CLEAR_MODE)
|
||||
{
|
||||
InstallClearMode = (EOverwriteInstallClearMode)value;
|
||||
}
|
||||
@@ -239,12 +252,14 @@ namespace YooAsset
|
||||
|
||||
// 创建默认的下载后台接口
|
||||
if (DownloadBackend == null)
|
||||
DownloadBackend = new UnityWebRequestBackend(DownloadSystemHelper.UnityWebRequestCreater);
|
||||
DownloadBackend = new UnityWebRequestBackend(WebRequestCreator);
|
||||
|
||||
// 创建解压文件系统
|
||||
var remoteServices = new DefaultUnpackRemoteServices(_packageRoot);
|
||||
_unpackFileSystem = new DefaultUnpackFileSystem();
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.DOWNLOAD_BACKEND, DownloadBackend);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.UNITY_WEB_REQUEST_CREATOR, WebRequestCreator);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.INSTALL_CLEAR_MODE, InstallClearMode);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, FileVerifyLevel);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.FILE_VERIFY_MAX_CONCURRENCY, FileVerifyMaxConcurrency);
|
||||
@@ -255,6 +270,17 @@ namespace YooAsset
|
||||
}
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
if (_unpackFileSystem != null)
|
||||
{
|
||||
_unpackFileSystem.OnDestroy();
|
||||
_unpackFileSystem = null;
|
||||
}
|
||||
|
||||
if (DownloadBackend != null)
|
||||
{
|
||||
DownloadBackend.Dispose();
|
||||
DownloadBackend = null;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool Belong(PackageBundle bundle)
|
||||
@@ -481,4 +507,4 @@ namespace YooAsset
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+22
-3
@@ -60,6 +60,11 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
#region 自定义参数
|
||||
/// <summary>
|
||||
/// 自定义参数:UnityWebRequest 创建委托
|
||||
/// </summary>
|
||||
public UnityWebRequestCreator WebRequestCreator { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:远程服务接口的实例类
|
||||
/// </summary>
|
||||
@@ -237,7 +242,15 @@ namespace YooAsset
|
||||
|
||||
public virtual void SetParameter(string name, object value)
|
||||
{
|
||||
if (name == FileSystemParametersDefine.REMOTE_SERVICES)
|
||||
if (name == FileSystemParametersDefine.DOWNLOAD_BACKEND)
|
||||
{
|
||||
DownloadBackend = (IDownloadBackend)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.UNITY_WEB_REQUEST_CREATOR)
|
||||
{
|
||||
WebRequestCreator = (UnityWebRequestCreator)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.REMOTE_SERVICES)
|
||||
{
|
||||
RemoteServices = (IRemoteServices)value;
|
||||
}
|
||||
@@ -334,7 +347,7 @@ namespace YooAsset
|
||||
|
||||
// 创建默认的下载后台接口
|
||||
if (DownloadBackend == null)
|
||||
DownloadBackend = new UnityWebRequestBackend(DownloadSystemHelper.UnityWebRequestCreater);
|
||||
DownloadBackend = new UnityWebRequestBackend(WebRequestCreator);
|
||||
}
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
@@ -343,6 +356,12 @@ namespace YooAsset
|
||||
DownloadScheduler.Dispose();
|
||||
DownloadScheduler = null;
|
||||
}
|
||||
|
||||
if (DownloadBackend != null)
|
||||
{
|
||||
DownloadBackend.Dispose();
|
||||
DownloadBackend = null;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool Belong(PackageBundle bundle)
|
||||
@@ -673,4 +692,4 @@ namespace YooAsset
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-3
@@ -44,6 +44,11 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
#region 自定义参数
|
||||
/// <summary>
|
||||
/// 自定义参数:UnityWebRequest 创建委托
|
||||
/// </summary>
|
||||
public UnityWebRequestCreator WebRequestCreator { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 模拟WebGL平台模式
|
||||
/// </summary>
|
||||
@@ -117,7 +122,15 @@ namespace YooAsset
|
||||
|
||||
public virtual void SetParameter(string name, object value)
|
||||
{
|
||||
if (name == FileSystemParametersDefine.VIRTUAL_WEBGL_MODE)
|
||||
if (name == FileSystemParametersDefine.DOWNLOAD_BACKEND)
|
||||
{
|
||||
DownloadBackend = (IDownloadBackend)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.UNITY_WEB_REQUEST_CREATOR)
|
||||
{
|
||||
WebRequestCreator = (UnityWebRequestCreator)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.VIRTUAL_WEBGL_MODE)
|
||||
{
|
||||
VirtualWebGLMode = Convert.ToBoolean(value);
|
||||
}
|
||||
@@ -153,10 +166,15 @@ namespace YooAsset
|
||||
|
||||
// 创建默认的下载后台接口
|
||||
if (DownloadBackend == null)
|
||||
DownloadBackend = new UnityWebRequestBackend(DownloadSystemHelper.UnityWebRequestCreater);
|
||||
DownloadBackend = new UnityWebRequestBackend(WebRequestCreator);
|
||||
}
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
if (DownloadBackend != null)
|
||||
{
|
||||
DownloadBackend.Dispose();
|
||||
DownloadBackend = null;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool Belong(PackageBundle bundle)
|
||||
@@ -247,4 +265,4 @@ namespace YooAsset
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-3
@@ -43,6 +43,11 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
#region 自定义参数
|
||||
/// <summary>
|
||||
/// 自定义参数:UnityWebRequest 创建委托
|
||||
/// </summary>
|
||||
public UnityWebRequestCreator WebRequestCreator { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 禁用Unity的网络缓存
|
||||
/// </summary>
|
||||
@@ -109,7 +114,15 @@ namespace YooAsset
|
||||
|
||||
public virtual void SetParameter(string name, object value)
|
||||
{
|
||||
if (name == FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE)
|
||||
if (name == FileSystemParametersDefine.DOWNLOAD_BACKEND)
|
||||
{
|
||||
DownloadBackend = (IDownloadBackend)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.UNITY_WEB_REQUEST_CREATOR)
|
||||
{
|
||||
WebRequestCreator = (UnityWebRequestCreator)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE)
|
||||
{
|
||||
DisableUnityWebCache = Convert.ToBoolean(value);
|
||||
}
|
||||
@@ -136,10 +149,15 @@ namespace YooAsset
|
||||
|
||||
// 创建默认的下载后台接口
|
||||
if (DownloadBackend == null)
|
||||
DownloadBackend = new UnityWebRequestBackend(DownloadSystemHelper.UnityWebRequestCreater);
|
||||
DownloadBackend = new UnityWebRequestBackend(WebRequestCreator);
|
||||
}
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
if (DownloadBackend != null)
|
||||
{
|
||||
DownloadBackend.Dispose();
|
||||
DownloadBackend = null;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool Belong(PackageBundle bundle)
|
||||
@@ -179,4 +197,4 @@ namespace YooAsset
|
||||
#region 内部方法
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-3
@@ -57,6 +57,11 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
#region 自定义参数
|
||||
/// <summary>
|
||||
/// 自定义参数:UnityWebRequest 创建委托
|
||||
/// </summary>
|
||||
public UnityWebRequestCreator WebRequestCreator { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 禁用Unity的网络缓存
|
||||
/// </summary>
|
||||
@@ -118,7 +123,15 @@ namespace YooAsset
|
||||
|
||||
public virtual void SetParameter(string name, object value)
|
||||
{
|
||||
if (name == FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE)
|
||||
if (name == FileSystemParametersDefine.DOWNLOAD_BACKEND)
|
||||
{
|
||||
DownloadBackend = (IDownloadBackend)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.UNITY_WEB_REQUEST_CREATOR)
|
||||
{
|
||||
WebRequestCreator = (UnityWebRequestCreator)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE)
|
||||
{
|
||||
DisableUnityWebCache = Convert.ToBoolean(value);
|
||||
}
|
||||
@@ -146,10 +159,15 @@ namespace YooAsset
|
||||
|
||||
// 创建默认的下载后台接口
|
||||
if (DownloadBackend == null)
|
||||
DownloadBackend = new UnityWebRequestBackend(DownloadSystemHelper.UnityWebRequestCreater);
|
||||
DownloadBackend = new UnityWebRequestBackend(WebRequestCreator);
|
||||
}
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
if (DownloadBackend != null)
|
||||
{
|
||||
DownloadBackend.Dispose();
|
||||
DownloadBackend = null;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool Belong(PackageBundle bundle)
|
||||
@@ -237,4 +255,4 @@ namespace YooAsset
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ namespace YooAsset
|
||||
public const string DISABLE_CATALOG_FILE = "DISABLE_CATALOG_FILE";
|
||||
public const string DISABLE_UNITY_WEB_CACHE = "DISABLE_UNITY_WEB_CACHE";
|
||||
public const string DISABLE_ONDEMAND_DOWNLOAD = "DISABLE_ONDEMAND_DOWNLOAD";
|
||||
public const string UNITY_WEB_REQUEST_CREATOR = "UNITY_WEB_REQUEST_CREATOR";
|
||||
public const string DOWNLOAD_BACKEND = "DOWNLOAD_BACKEND";
|
||||
public const string DOWNLOAD_MAX_CONCURRENCY = "DOWNLOAD_MAX_CONCURRENCY";
|
||||
public const string DOWNLOAD_MAX_REQUEST_PER_FRAME = "DOWNLOAD_MAX_REQUEST_PER_FRAME";
|
||||
public const string DOWNLOAD_WATCH_DOG_TIME = "DOWNLOAD_WATCH_DOG_TIME";
|
||||
@@ -28,4 +30,4 @@ namespace YooAsset
|
||||
public const string COPY_LOCAL_FILE_SERVICES = "COPY_LOCAL_FILE_SERVICES";
|
||||
public const string UNPACK_FILE_SYSTEM_ROOT = "UNPACK_FILE_SYSTEM_ROOT";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,6 +354,17 @@ var webRemoteParams = FileSystemParameters.CreateDefaultWebRemoteFileSystemParam
|
||||
```csharp
|
||||
var cacheParams = FileSystemParameters.CreateDefaultCacheFileSystemParameters(remoteServices);
|
||||
|
||||
// 设置 UnityWebRequest 创建委托(用于证书/代理/自定义 Header 等)
|
||||
cacheParams.AddParameter(FileSystemParametersDefine.UNITY_WEB_REQUEST_CREATOR, (UnityWebRequestCreator)((url) =>
|
||||
{
|
||||
var request = new UnityEngine.Networking.UnityWebRequest(url, UnityEngine.Networking.UnityWebRequest.kHttpVerbGET);
|
||||
// 自定义配置...
|
||||
return request;
|
||||
}));
|
||||
|
||||
// 设置自定义下载后端(若设置则不再创建默认 UnityWebRequestBackend)
|
||||
// cacheParams.AddParameter(FileSystemParametersDefine.DOWNLOAD_BACKEND, myDownloadBackend);
|
||||
|
||||
// 设置文件校验级别
|
||||
cacheParams.AddParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, EFileVerifyLevel.High);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user