mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-28 19:48:47 +00:00
Compare commits
21 Commits
2.3.12
...
bfd476d59c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfd476d59c | ||
|
|
7dd08e9634 | ||
|
|
b2776b933a | ||
|
|
9f09b6c526 | ||
|
|
01f6103b48 | ||
|
|
053b4a00d7 | ||
|
|
db159428c6 | ||
|
|
ac7ee16017 | ||
|
|
c2fb7c3cbb | ||
|
|
e70b0d37cd | ||
|
|
53db012fc8 | ||
|
|
b3622167da | ||
|
|
dd6fab46f9 | ||
|
|
f0796dccc9 | ||
|
|
f383c59327 | ||
|
|
e34b9270d2 | ||
|
|
b90ab01fe9 | ||
|
|
236468b4a8 | ||
|
|
6f5fcd55b1 | ||
|
|
4b8f2e3acc | ||
|
|
090e4f4b15 |
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
// 内部友元
|
// 内部友元
|
||||||
[assembly: InternalsVisibleTo("YooAsset.Editor")]
|
[assembly: InternalsVisibleTo("YooAsset.Editor")]
|
||||||
|
[assembly: InternalsVisibleTo("YooAsset.Test")]
|
||||||
[assembly: InternalsVisibleTo("YooAsset.Test.Editor")]
|
[assembly: InternalsVisibleTo("YooAsset.Test.Editor")]
|
||||||
|
|
||||||
// 外部友元
|
// 外部友元
|
||||||
|
|||||||
@@ -94,4 +94,25 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public long FileSize;
|
public long FileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 导入文件的信息
|
||||||
|
/// </summary>
|
||||||
|
public struct ImportFileInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 本地文件路径
|
||||||
|
/// </summary>
|
||||||
|
public string FilePath;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源包名称
|
||||||
|
/// </summary>
|
||||||
|
public string BundleName;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源包GUID
|
||||||
|
/// </summary>
|
||||||
|
public string BundleGUID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,32 @@
|
|||||||
using UnityEngine;
|
using UnityEngine.Networking;
|
||||||
using UnityEngine.Networking;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
internal class DownloadWebNormalAssetBundleOperation : DownloadAssetBundleOperation
|
internal class UnityAssetBundleRequestOperation : UnityWebRequestOperation
|
||||||
{
|
{
|
||||||
private readonly bool _disableUnityWebCache;
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
Download,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private UnityWebRequestAsyncOperation _requestOperation;
|
||||||
private DownloadHandlerAssetBundle _downloadhandler;
|
private DownloadHandlerAssetBundle _downloadhandler;
|
||||||
|
private readonly PackageBundle _packageBundle;
|
||||||
|
private readonly bool _disableUnityWebCache;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal DownloadWebNormalAssetBundleOperation(bool disableUnityWebCache, PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
|
/// <summary>
|
||||||
|
/// 请求结果
|
||||||
|
/// </summary>
|
||||||
|
public AssetBundle Result { private set; get; }
|
||||||
|
|
||||||
|
internal UnityAssetBundleRequestOperation(PackageBundle packageBundle, bool disableUnityWebCache, string url) : base(url)
|
||||||
{
|
{
|
||||||
|
_packageBundle = packageBundle;
|
||||||
_disableUnityWebCache = disableUnityWebCache;
|
_disableUnityWebCache = disableUnityWebCache;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
@@ -22,34 +38,20 @@ namespace YooAsset
|
|||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
if (_steps == ESteps.CreateRequest)
|
if (_steps == ESteps.CreateRequest)
|
||||||
{
|
{
|
||||||
// 获取请求地址
|
|
||||||
_requestURL = GetRequestURL();
|
|
||||||
|
|
||||||
// 重置变量
|
|
||||||
ResetRequestFiled();
|
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
CreateWebRequest();
|
CreateWebRequest();
|
||||||
|
_steps = ESteps.Download;
|
||||||
_steps = ESteps.CheckRequest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测下载结果
|
if (_steps == ESteps.Download)
|
||||||
if (_steps == ESteps.CheckRequest)
|
|
||||||
{
|
{
|
||||||
DownloadProgress = _webRequest.downloadProgress;
|
DownloadProgress = _webRequest.downloadProgress;
|
||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
Progress = DownloadProgress;
|
Progress = _requestOperation.progress;
|
||||||
if (_webRequest.isDone == false)
|
if (_requestOperation.isDone == false)
|
||||||
{
|
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// 检查网络错误
|
|
||||||
if (CheckRequestResult())
|
if (CheckRequestResult())
|
||||||
{
|
{
|
||||||
AssetBundle assetBundle = _downloadhandler.assetBundle;
|
AssetBundle assetBundle = _downloadhandler.assetBundle;
|
||||||
@@ -57,7 +59,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = "Download handler asset bundle object is null !";
|
Error = $"URL : {_requestURL} Download handler asset bundle object is null !";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -68,37 +70,13 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.TryAgain;
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注意:最终释放请求器
|
// 注意:最终释放请求器
|
||||||
DisposeWebRequest();
|
DisposeRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新尝试下载
|
|
||||||
if (_steps == ESteps.TryAgain)
|
|
||||||
{
|
|
||||||
if (FailedTryAgain <= 0)
|
|
||||||
{
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
YooLogger.Error(Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_tryAgainTimer += Time.unscaledDeltaTime;
|
|
||||||
if (_tryAgainTimer > 1f)
|
|
||||||
{
|
|
||||||
FailedTryAgain--;
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
YooLogger.Warning(Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
internal override void InternalAbort()
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateWebRequest()
|
private void CreateWebRequest()
|
||||||
@@ -107,22 +85,13 @@ namespace YooAsset
|
|||||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||||
_webRequest.downloadHandler = _downloadhandler;
|
_webRequest.downloadHandler = _downloadhandler;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
_webRequest.SendWebRequest();
|
_requestOperation = _webRequest.SendWebRequest();
|
||||||
}
|
|
||||||
private void DisposeWebRequest()
|
|
||||||
{
|
|
||||||
if (_webRequest != null)
|
|
||||||
{
|
|
||||||
//注意:引擎底层会自动调用Abort方法
|
|
||||||
_webRequest.Dispose();
|
|
||||||
_webRequest = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
private DownloadHandlerAssetBundle CreateWebDownloadHandler()
|
private DownloadHandlerAssetBundle CreateWebDownloadHandler()
|
||||||
{
|
{
|
||||||
if (_disableUnityWebCache)
|
if (_disableUnityWebCache)
|
||||||
{
|
{
|
||||||
var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, Bundle.UnityCRC);
|
var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, _packageBundle.UnityCRC);
|
||||||
#if UNITY_2020_3_OR_NEWER
|
#if UNITY_2020_3_OR_NEWER
|
||||||
downloadhandler.autoLoadAssetBundle = false;
|
downloadhandler.autoLoadAssetBundle = false;
|
||||||
#endif
|
#endif
|
||||||
@@ -132,8 +101,8 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
// 注意:优先从浏览器缓存里获取文件
|
// 注意:优先从浏览器缓存里获取文件
|
||||||
// The file hash defining the version of the asset bundle.
|
// The file hash defining the version of the asset bundle.
|
||||||
Hash128 fileHash = Hash128.Parse(Bundle.FileHash);
|
Hash128 fileHash = Hash128.Parse(_packageBundle.FileHash);
|
||||||
var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, fileHash, Bundle.UnityCRC);
|
var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, fileHash, _packageBundle.UnityCRC);
|
||||||
#if UNITY_2020_3_OR_NEWER
|
#if UNITY_2020_3_OR_NEWER
|
||||||
downloadhandler.autoLoadAssetBundle = false;
|
downloadhandler.autoLoadAssetBundle = false;
|
||||||
#endif
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 8088863fc7dfbd441bc897380cd7b97f
|
guid: e01cc308d7179a34281087fafe455b42
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
using UnityEngine.Networking;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class UnityWebCacheRequestOperation : UnityWebRequestOperation
|
||||||
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
Download,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private UnityWebRequestAsyncOperation _requestOperation;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
|
internal UnityWebCacheRequestOperation(string url) : base(url)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.CreateRequest)
|
||||||
|
{
|
||||||
|
CreateWebRequest();
|
||||||
|
_steps = ESteps.Download;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.Download)
|
||||||
|
{
|
||||||
|
DownloadProgress = _webRequest.downloadProgress;
|
||||||
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
|
Progress = _requestOperation.progress;
|
||||||
|
if (_requestOperation.isDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (CheckRequestResult())
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注意:最终释放请求器
|
||||||
|
DisposeRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置请求头信息
|
||||||
|
/// </summary>
|
||||||
|
public void SetRequestHeader(string name, string value)
|
||||||
|
{
|
||||||
|
_webRequest.SetRequestHeader(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateWebRequest()
|
||||||
|
{
|
||||||
|
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||||
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
|
_requestOperation = _webRequest.SendWebRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 94254ab8e4496214884c11a891c131c6
|
guid: 375d88bcf5b9a6146adaf98ceb5369f8
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -5,7 +5,23 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
internal class UnityWebDataRequestOperation : UnityWebRequestOperation
|
internal class UnityWebDataRequestOperation : UnityWebRequestOperation
|
||||||
{
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
Download,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
private UnityWebRequestAsyncOperation _requestOperation;
|
private UnityWebRequestAsyncOperation _requestOperation;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 响应的超时时间(单位:秒),在经过Timeout的秒数后尝试中止。
|
||||||
|
/// 注意:当Timeout设置为0时,不会应用超时。
|
||||||
|
/// 注意:设置的超时值可能应用于Android上的每个URL重定向,这可能会导致响应时间增加。
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _timeout;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 请求结果
|
/// 请求结果
|
||||||
@@ -13,8 +29,9 @@ namespace YooAsset
|
|||||||
public byte[] Result { private set; get; }
|
public byte[] Result { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
internal UnityWebDataRequestOperation(string url, int timeout = 60) : base(url, timeout)
|
internal UnityWebDataRequestOperation(string url, int timeout) : base(url)
|
||||||
{
|
{
|
||||||
|
_timeout = timeout;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
@@ -27,28 +44,34 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.CreateRequest)
|
if (_steps == ESteps.CreateRequest)
|
||||||
{
|
{
|
||||||
_latestDownloadBytes = 0;
|
|
||||||
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
|
||||||
|
|
||||||
CreateWebRequest();
|
CreateWebRequest();
|
||||||
_steps = ESteps.Download;
|
_steps = ESteps.Download;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.Download)
|
if (_steps == ESteps.Download)
|
||||||
{
|
{
|
||||||
|
DownloadProgress = _webRequest.downloadProgress;
|
||||||
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
Progress = _requestOperation.progress;
|
Progress = _requestOperation.progress;
|
||||||
if (_requestOperation.isDone == false)
|
if (_requestOperation.isDone == false)
|
||||||
{
|
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (CheckRequestResult())
|
if (CheckRequestResult())
|
||||||
|
{
|
||||||
|
var fileData = _webRequest.downloadHandler.data;
|
||||||
|
if (fileData == null || fileData.Length == 0)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Result = _webRequest.downloadHandler.data;
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"URL : {_requestURL} Download handler data is null or empty !";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Result = fileData;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
@@ -59,16 +82,12 @@ namespace YooAsset
|
|||||||
DisposeRequest();
|
DisposeRequest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
internal override void InternalAbort()
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
DisposeRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateWebRequest()
|
private void CreateWebRequest()
|
||||||
{
|
{
|
||||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
|
||||||
DownloadHandlerBuffer handler = new DownloadHandlerBuffer();
|
DownloadHandlerBuffer handler = new DownloadHandlerBuffer();
|
||||||
|
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||||
|
_webRequest.timeout = _timeout;
|
||||||
_webRequest.downloadHandler = handler;
|
_webRequest.downloadHandler = handler;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
_requestOperation = _webRequest.SendWebRequest();
|
_requestOperation = _webRequest.SendWebRequest();
|
||||||
|
|||||||
@@ -5,12 +5,30 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
internal class UnityWebFileRequestOperation : UnityWebRequestOperation
|
internal class UnityWebFileRequestOperation : UnityWebRequestOperation
|
||||||
{
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
Download,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
private UnityWebRequestAsyncOperation _requestOperation;
|
private UnityWebRequestAsyncOperation _requestOperation;
|
||||||
private readonly string _fileSavePath;
|
private readonly string _fileSavePath;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal UnityWebFileRequestOperation(string url, string fileSavePath, int timeout = 60) : base(url, timeout)
|
/// <summary>
|
||||||
|
/// 响应的超时时间(单位:秒),在经过Timeout的秒数后尝试中止。
|
||||||
|
/// 注意:当Timeout设置为0时,不会应用超时。
|
||||||
|
/// 注意:设置的超时值可能应用于Android上的每个URL重定向,这可能会导致响应时间增加。
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _timeout;
|
||||||
|
|
||||||
|
|
||||||
|
internal UnityWebFileRequestOperation(string url, string fileSavePath, int timeout) : base(url)
|
||||||
{
|
{
|
||||||
_fileSavePath = fileSavePath;
|
_fileSavePath = fileSavePath;
|
||||||
|
_timeout = timeout;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
@@ -23,21 +41,17 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.CreateRequest)
|
if (_steps == ESteps.CreateRequest)
|
||||||
{
|
{
|
||||||
_latestDownloadBytes = 0;
|
|
||||||
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
|
||||||
|
|
||||||
CreateWebRequest();
|
CreateWebRequest();
|
||||||
_steps = ESteps.Download;
|
_steps = ESteps.Download;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.Download)
|
if (_steps == ESteps.Download)
|
||||||
{
|
{
|
||||||
|
DownloadProgress = _webRequest.downloadProgress;
|
||||||
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
Progress = _requestOperation.progress;
|
Progress = _requestOperation.progress;
|
||||||
if (_requestOperation.isDone == false)
|
if (_requestOperation.isDone == false)
|
||||||
{
|
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (CheckRequestResult())
|
if (CheckRequestResult())
|
||||||
{
|
{
|
||||||
@@ -54,17 +68,13 @@ namespace YooAsset
|
|||||||
DisposeRequest();
|
DisposeRequest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
internal override void InternalAbort()
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
DisposeRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateWebRequest()
|
private void CreateWebRequest()
|
||||||
{
|
{
|
||||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
|
||||||
DownloadHandlerFile handler = new DownloadHandlerFile(_fileSavePath);
|
DownloadHandlerFile handler = new DownloadHandlerFile(_fileSavePath);
|
||||||
handler.removeFileOnAbort = true;
|
handler.removeFileOnAbort = true;
|
||||||
|
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||||
|
_webRequest.timeout = _timeout;
|
||||||
_webRequest.downloadHandler = handler;
|
_webRequest.downloadHandler = handler;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
_requestOperation = _webRequest.SendWebRequest();
|
_requestOperation = _webRequest.SendWebRequest();
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using UnityEngine.Networking;
|
using UnityEngine.Networking;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@@ -8,33 +6,50 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
internal abstract class UnityWebRequestOperation : AsyncOperationBase
|
internal abstract class UnityWebRequestOperation : AsyncOperationBase
|
||||||
{
|
{
|
||||||
protected enum ESteps
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
CreateRequest,
|
|
||||||
Download,
|
|
||||||
Done,
|
|
||||||
}
|
|
||||||
|
|
||||||
protected UnityWebRequest _webRequest;
|
protected UnityWebRequest _webRequest;
|
||||||
protected readonly string _requestURL;
|
protected readonly string _requestURL;
|
||||||
protected ESteps _steps = ESteps.None;
|
|
||||||
|
|
||||||
// 超时相关
|
|
||||||
protected readonly float _timeout;
|
|
||||||
protected ulong _latestDownloadBytes;
|
|
||||||
protected float _latestDownloadRealtime;
|
|
||||||
private bool _isAbort = false;
|
private bool _isAbort = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// HTTP返回码
|
||||||
|
/// </summary>
|
||||||
|
public long HttpCode { private set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前下载的字节数
|
||||||
|
/// </summary>
|
||||||
|
public long DownloadedBytes { protected set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前下载进度(0f - 1f)
|
||||||
|
/// </summary>
|
||||||
|
public float DownloadProgress { protected set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 请求的URL地址
|
||||||
|
/// </summary>
|
||||||
public string URL
|
public string URL
|
||||||
{
|
{
|
||||||
get { return _requestURL; }
|
get { return _requestURL; }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal UnityWebRequestOperation(string url, int timeout)
|
internal UnityWebRequestOperation(string url)
|
||||||
{
|
{
|
||||||
_requestURL = url;
|
_requestURL = url;
|
||||||
_timeout = timeout;
|
}
|
||||||
|
internal override void InternalAbort()
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
// 1. 编辑器下停止运行游戏的时候主动终止下载任务
|
||||||
|
// 2. 真机上销毁包裹的时候主动终止下载任务
|
||||||
|
if (_isAbort == false)
|
||||||
|
{
|
||||||
|
if (_webRequest != null)
|
||||||
|
{
|
||||||
|
_webRequest.Abort();
|
||||||
|
_isAbort = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -44,39 +59,19 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (_webRequest != null)
|
if (_webRequest != null)
|
||||||
{
|
{
|
||||||
|
//注意:引擎底层会自动调用Abort方法
|
||||||
_webRequest.Dispose();
|
_webRequest.Dispose();
|
||||||
_webRequest = null;
|
_webRequest = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 检测超时
|
|
||||||
/// </summary>
|
|
||||||
protected void CheckRequestTimeout()
|
|
||||||
{
|
|
||||||
// 注意:在连续时间段内无新增下载数据及判定为超时
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 检测请求结果
|
/// 检测请求结果
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected bool CheckRequestResult()
|
protected bool CheckRequestResult()
|
||||||
{
|
{
|
||||||
|
HttpCode = _webRequest.responseCode;
|
||||||
|
|
||||||
#if UNITY_2020_3_OR_NEWER
|
#if UNITY_2020_3_OR_NEWER
|
||||||
if (_webRequest.result != UnityWebRequest.Result.Success)
|
if (_webRequest.result != UnityWebRequest.Result.Success)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,23 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
internal class UnityWebTextRequestOperation : UnityWebRequestOperation
|
internal class UnityWebTextRequestOperation : UnityWebRequestOperation
|
||||||
{
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
Download,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
private UnityWebRequestAsyncOperation _requestOperation;
|
private UnityWebRequestAsyncOperation _requestOperation;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 响应的超时时间(单位:秒),在经过Timeout的秒数后尝试中止。
|
||||||
|
/// 注意:当Timeout设置为0时,不会应用超时。
|
||||||
|
/// 注意:设置的超时值可能应用于Android上的每个URL重定向,这可能会导致响应时间增加。
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _timeout;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 请求结果
|
/// 请求结果
|
||||||
@@ -13,8 +29,9 @@ namespace YooAsset
|
|||||||
public string Result { private set; get; }
|
public string Result { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
internal UnityWebTextRequestOperation(string url, int timeout = 60) : base(url, timeout)
|
internal UnityWebTextRequestOperation(string url, int timeout) : base(url)
|
||||||
{
|
{
|
||||||
|
_timeout = timeout;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
@@ -27,28 +44,34 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.CreateRequest)
|
if (_steps == ESteps.CreateRequest)
|
||||||
{
|
{
|
||||||
_latestDownloadBytes = 0;
|
|
||||||
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
|
||||||
|
|
||||||
CreateWebRequest();
|
CreateWebRequest();
|
||||||
_steps = ESteps.Download;
|
_steps = ESteps.Download;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_steps == ESteps.Download)
|
if (_steps == ESteps.Download)
|
||||||
{
|
{
|
||||||
|
DownloadProgress = _webRequest.downloadProgress;
|
||||||
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
Progress = _requestOperation.progress;
|
Progress = _requestOperation.progress;
|
||||||
if (_requestOperation.isDone == false)
|
if (_requestOperation.isDone == false)
|
||||||
{
|
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (CheckRequestResult())
|
if (CheckRequestResult())
|
||||||
|
{
|
||||||
|
var fileText = _webRequest.downloadHandler.text;
|
||||||
|
if (string.IsNullOrEmpty(fileText))
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Result = _webRequest.downloadHandler.text;
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"URL : {_requestURL} Download handler text is null or empty !";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Result = fileText;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
@@ -59,16 +82,12 @@ namespace YooAsset
|
|||||||
DisposeRequest();
|
DisposeRequest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
internal override void InternalAbort()
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
DisposeRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateWebRequest()
|
private void CreateWebRequest()
|
||||||
{
|
{
|
||||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
|
||||||
DownloadHandlerBuffer handler = new DownloadHandlerBuffer();
|
DownloadHandlerBuffer handler = new DownloadHandlerBuffer();
|
||||||
|
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||||
|
_webRequest.timeout = _timeout;
|
||||||
_webRequest.downloadHandler = handler;
|
_webRequest.downloadHandler = handler;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
_requestOperation = _webRequest.SendWebRequest();
|
_requestOperation = _webRequest.SendWebRequest();
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
||||||
{
|
{
|
||||||
// 注意:业务层的解压下载器会依赖内置文件系统的下载方法
|
// 注意:业务层的解压器会依赖该方法
|
||||||
options.ImportFilePath = GetBuildinFileLoadPath(bundle);
|
options.ImportFilePath = GetBuildinFileLoadPath(bundle);
|
||||||
return _unpackFileSystem.DownloadFileAsync(bundle, options);
|
return _unpackFileSystem.DownloadFileAsync(bundle, options);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,13 +49,13 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 生成包裹的内置资源目录文件
|
/// 生成包裹的内置资源目录文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static bool CreateBuildinCatalogFile(IManifestServices services, string packageName, string pacakgeDirectory)
|
public static bool CreateBuildinCatalogFile(IManifestServices services, string packageName, string packageDirectory)
|
||||||
{
|
{
|
||||||
// 获取资源清单版本
|
// 获取资源清单版本
|
||||||
string packageVersion;
|
string packageVersion;
|
||||||
{
|
{
|
||||||
string versionFileName = YooAssetSettingsData.GetPackageVersionFileName(packageName);
|
string versionFileName = YooAssetSettingsData.GetPackageVersionFileName(packageName);
|
||||||
string versionFilePath = $"{pacakgeDirectory}/{versionFileName}";
|
string versionFilePath = $"{packageDirectory}/{versionFileName}";
|
||||||
if (File.Exists(versionFilePath) == false)
|
if (File.Exists(versionFilePath) == false)
|
||||||
{
|
{
|
||||||
Debug.LogError($"Can not found package version file : {versionFilePath}");
|
Debug.LogError($"Can not found package version file : {versionFilePath}");
|
||||||
@@ -69,7 +69,7 @@ namespace YooAsset
|
|||||||
PackageManifest packageManifest;
|
PackageManifest packageManifest;
|
||||||
{
|
{
|
||||||
string manifestFileName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion);
|
string manifestFileName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion);
|
||||||
string manifestFilePath = $"{pacakgeDirectory}/{manifestFileName}";
|
string manifestFilePath = $"{packageDirectory}/{manifestFileName}";
|
||||||
if (File.Exists(manifestFilePath) == false)
|
if (File.Exists(manifestFilePath) == false)
|
||||||
{
|
{
|
||||||
Debug.LogError($"Can not found package manifest file : {manifestFilePath}");
|
Debug.LogError($"Can not found package manifest file : {manifestFilePath}");
|
||||||
@@ -110,7 +110,7 @@ namespace YooAsset
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 记录所有内置资源文件
|
// 记录所有内置资源文件
|
||||||
DirectoryInfo rootDirectory = new DirectoryInfo(pacakgeDirectory);
|
DirectoryInfo rootDirectory = new DirectoryInfo(packageDirectory);
|
||||||
FileInfo[] fileInfos = rootDirectory.GetFiles();
|
FileInfo[] fileInfos = rootDirectory.GetFiles();
|
||||||
foreach (var fileInfo in fileInfos)
|
foreach (var fileInfo in fileInfos)
|
||||||
{
|
{
|
||||||
@@ -135,13 +135,13 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 创建输出文件
|
// 创建输出文件
|
||||||
string jsonFilePath = $"{pacakgeDirectory}/{DefaultBuildinFileSystemDefine.BuildinCatalogJsonFileName}";
|
string jsonFilePath = $"{packageDirectory}/{DefaultBuildinFileSystemDefine.BuildinCatalogJsonFileName}";
|
||||||
if (File.Exists(jsonFilePath))
|
if (File.Exists(jsonFilePath))
|
||||||
File.Delete(jsonFilePath);
|
File.Delete(jsonFilePath);
|
||||||
CatalogTools.SerializeToJson(jsonFilePath, buildinFileCatalog);
|
CatalogTools.SerializeToJson(jsonFilePath, buildinFileCatalog);
|
||||||
|
|
||||||
// 创建输出文件
|
// 创建输出文件
|
||||||
string binaryFilePath = $"{pacakgeDirectory}/{DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName}";
|
string binaryFilePath = $"{packageDirectory}/{DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName}";
|
||||||
if (File.Exists(binaryFilePath))
|
if (File.Exists(binaryFilePath))
|
||||||
File.Delete(binaryFilePath);
|
File.Delete(binaryFilePath);
|
||||||
CatalogTools.SerializeToBinary(binaryFilePath, buildinFileCatalog);
|
CatalogTools.SerializeToBinary(binaryFilePath, buildinFileCatalog);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace YooAsset
|
|||||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||||
private CopyBuildinPackageManifestOperation _copyBuildinPackageManifestOp;
|
private CopyBuildinPackageManifestOperation _copyBuildinPackageManifestOp;
|
||||||
private FSInitializeFileSystemOperation _initUnpackFIleSystemOp;
|
private FSInitializeFileSystemOperation _initUnpackFIleSystemOp;
|
||||||
private LoadBuildinCatalogFileOperation _loadCatalogFileOp;
|
private LoadBuildinCatalogFileOperation _loadBuildinCatalogFileOp;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal DBFSInitializeOperation(DefaultBuildinFileSystem fileSystem)
|
internal DBFSInitializeOperation(DefaultBuildinFileSystem fileSystem)
|
||||||
@@ -103,34 +103,18 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.LoadCatalogFile)
|
if (_steps == ESteps.LoadCatalogFile)
|
||||||
{
|
{
|
||||||
if (_loadCatalogFileOp == null)
|
if (_loadBuildinCatalogFileOp == null)
|
||||||
{
|
{
|
||||||
#if UNITY_EDITOR
|
_loadBuildinCatalogFileOp = new LoadBuildinCatalogFileOperation(_fileSystem);
|
||||||
/*
|
_loadBuildinCatalogFileOp.StartOperation();
|
||||||
// 兼容性初始化
|
AddChildOperation(_loadBuildinCatalogFileOp);
|
||||||
// 说明:内置文件系统在编辑器下运行时需要动态生成
|
|
||||||
string packageRoot = _fileSystem.FileRoot;
|
|
||||||
bool result = DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.ManifestServices, _fileSystem.PackageName, packageRoot);
|
|
||||||
if (result == false)
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = $"Create package catalog file failed ! See the detail error in console !";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_loadCatalogFileOp = new LoadBuildinCatalogFileOperation(_fileSystem);
|
|
||||||
_loadCatalogFileOp.StartOperation();
|
|
||||||
AddChildOperation(_loadCatalogFileOp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_loadCatalogFileOp.UpdateOperation();
|
_loadBuildinCatalogFileOp.UpdateOperation();
|
||||||
if (_loadCatalogFileOp.IsDone == false)
|
if (_loadBuildinCatalogFileOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_loadCatalogFileOp.Status == EOperationStatus.Succeed)
|
if (_loadBuildinCatalogFileOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
@@ -139,7 +123,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _loadCatalogFileOp.Error;
|
Error = _loadBuildinCatalogFileOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,14 +104,8 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_assetBundle != null)
|
if (_assetBundle == null)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
|
||||||
Result = new AssetBundleResult(_fileSystem, _bundle, _assetBundle, _managedStream);
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_bundle.Encrypted)
|
if (_bundle.Encrypted)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
@@ -127,6 +121,13 @@ namespace YooAsset
|
|||||||
YooLogger.Error(Error);
|
YooLogger.Error(Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Result = new AssetBundleResult(_fileSystem, _bundle, _assetBundle, _managedStream);
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
internal override void InternalWaitForAsyncComplete()
|
internal override void InternalWaitForAsyncComplete()
|
||||||
{
|
{
|
||||||
@@ -176,13 +177,15 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.LoadBuildinRawBundle)
|
if (_steps == ESteps.LoadBuildinRawBundle)
|
||||||
{
|
{
|
||||||
|
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
|
||||||
|
|
||||||
#if UNITY_ANDROID
|
#if UNITY_ANDROID
|
||||||
//TODO : 安卓平台内置文件属于APK压缩包内的文件。
|
//TODO : 安卓平台内置文件属于APK压缩包内的文件。
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Result = new RawBundleResult(_fileSystem, _bundle);
|
Status = EOperationStatus.Failed;
|
||||||
Status = EOperationStatus.Succeed;
|
Error = $"Can not load android buildin raw bundle file : {filePath}";
|
||||||
|
YooLogger.Error(Error);
|
||||||
#else
|
#else
|
||||||
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
|
|
||||||
if (File.Exists(filePath))
|
if (File.Exists(filePath))
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ namespace YooAsset
|
|||||||
|
|
||||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||||
private RequestBuildinPackageVersionOperation _requestBuildinPackageVersionOp;
|
private RequestBuildinPackageVersionOperation _requestBuildinPackageVersionOp;
|
||||||
private UnityWebFileRequestOperation _hashFileRequestOp;
|
private UnityWebFileRequestOperation _hashWebFileRequestOp;
|
||||||
private UnityWebFileRequestOperation _manifestFileRequestOp;
|
private UnityWebFileRequestOperation _manifestWebFileRequestOp;
|
||||||
private string _buildinPackageVersion;
|
private string _buildinPackageVersion;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
@@ -78,21 +78,21 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.UnpackHashFile)
|
if (_steps == ESteps.UnpackHashFile)
|
||||||
{
|
{
|
||||||
if (_hashFileRequestOp == null)
|
if (_hashWebFileRequestOp == null)
|
||||||
{
|
{
|
||||||
string sourcePath = _fileSystem.GetBuildinPackageHashFilePath(_buildinPackageVersion);
|
string sourcePath = _fileSystem.GetBuildinPackageHashFilePath(_buildinPackageVersion);
|
||||||
string destPath = GetCopyPackageHashDestPath(_buildinPackageVersion);
|
string destPath = GetCopyPackageHashDestPath(_buildinPackageVersion);
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
||||||
_hashFileRequestOp = new UnityWebFileRequestOperation(url, destPath);
|
_hashWebFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60);
|
||||||
_hashFileRequestOp.StartOperation();
|
_hashWebFileRequestOp.StartOperation();
|
||||||
AddChildOperation(_hashFileRequestOp);
|
AddChildOperation(_hashWebFileRequestOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
_hashFileRequestOp.UpdateOperation();
|
_hashWebFileRequestOp.UpdateOperation();
|
||||||
if (_hashFileRequestOp.IsDone == false)
|
if (_hashWebFileRequestOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_hashFileRequestOp.Status == EOperationStatus.Succeed)
|
if (_hashWebFileRequestOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
_steps = ESteps.CheckManifestFile;
|
_steps = ESteps.CheckManifestFile;
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _hashFileRequestOp.Error;
|
Error = _hashWebFileRequestOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,21 +119,21 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.UnpackManifestFile)
|
if (_steps == ESteps.UnpackManifestFile)
|
||||||
{
|
{
|
||||||
if (_manifestFileRequestOp == null)
|
if (_manifestWebFileRequestOp == null)
|
||||||
{
|
{
|
||||||
string sourcePath = _fileSystem.GetBuildinPackageManifestFilePath(_buildinPackageVersion);
|
string sourcePath = _fileSystem.GetBuildinPackageManifestFilePath(_buildinPackageVersion);
|
||||||
string destPath = GetCopyPackageManifestDestPath(_buildinPackageVersion);
|
string destPath = GetCopyPackageManifestDestPath(_buildinPackageVersion);
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
||||||
_manifestFileRequestOp = new UnityWebFileRequestOperation(url, destPath);
|
_manifestWebFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60);
|
||||||
_manifestFileRequestOp.StartOperation();
|
_manifestWebFileRequestOp.StartOperation();
|
||||||
AddChildOperation(_manifestFileRequestOp);
|
AddChildOperation(_manifestWebFileRequestOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
_manifestFileRequestOp.UpdateOperation();
|
_manifestWebFileRequestOp.UpdateOperation();
|
||||||
if (_manifestFileRequestOp.IsDone == false)
|
if (_manifestWebFileRequestOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_manifestFileRequestOp.Status == EOperationStatus.Succeed)
|
if (_manifestWebFileRequestOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
@@ -142,7 +142,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _manifestFileRequestOp.Error;
|
Error = _manifestWebFileRequestOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
string filePath = _fileSystem.GetCatalogBinaryFileLoadPath();
|
string filePath = _fileSystem.GetCatalogBinaryFileLoadPath();
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||||
_webDataRequestOp = new UnityWebDataRequestOperation(url);
|
_webDataRequestOp = new UnityWebDataRequestOperation(url, 60);
|
||||||
_webDataRequestOp.StartOperation();
|
_webDataRequestOp.StartOperation();
|
||||||
AddChildOperation(_webDataRequestOp);
|
AddChildOperation(_webDataRequestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
string filePath = _fileSystem.GetBuildinPackageManifestFilePath(_packageVersion);
|
string filePath = _fileSystem.GetBuildinPackageManifestFilePath(_packageVersion);
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||||
_webDataRequestOp = new UnityWebDataRequestOperation(url);
|
_webDataRequestOp = new UnityWebDataRequestOperation(url, 60);
|
||||||
_webDataRequestOp.StartOperation();
|
_webDataRequestOp.StartOperation();
|
||||||
AddChildOperation(_webDataRequestOp);
|
AddChildOperation(_webDataRequestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
string filePath = _fileSystem.GetBuildinPackageHashFilePath(_packageVersion);
|
string filePath = _fileSystem.GetBuildinPackageHashFilePath(_packageVersion);
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||||
_webTextRequestOp = new UnityWebTextRequestOperation(url);
|
_webTextRequestOp = new UnityWebTextRequestOperation(url, 60);
|
||||||
_webTextRequestOp.StartOperation();
|
_webTextRequestOp.StartOperation();
|
||||||
AddChildOperation(_webTextRequestOp);
|
AddChildOperation(_webTextRequestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
string filePath = _fileSystem.GetBuildinPackageVersionFilePath();
|
string filePath = _fileSystem.GetBuildinPackageVersionFilePath();
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||||
_webTextRequestOp = new UnityWebTextRequestOperation(url);
|
_webTextRequestOp = new UnityWebTextRequestOperation(url, 60);
|
||||||
_webTextRequestOp.StartOperation();
|
_webTextRequestOp.StartOperation();
|
||||||
AddChildOperation(_webTextRequestOp);
|
AddChildOperation(_webTextRequestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,12 +166,23 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
||||||
{
|
{
|
||||||
var downloader = DownloadCenter.DownloadFileAsync(bundle, options);
|
// 获取下载地址
|
||||||
downloader.Reference(); //增加下载器的引用计数
|
if (string.IsNullOrEmpty(options.ImportFilePath))
|
||||||
|
{
|
||||||
|
// 注意:如果是解压文件系统类,这里会返回本地内置文件的下载路径
|
||||||
|
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
|
||||||
|
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
||||||
|
options.SetURL(mainURL, fallbackURL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 注意:把本地导入文件路径转换为下载器请求地址
|
||||||
|
string mainURL = DownloadSystemHelper.ConvertToWWWPath(options.ImportFilePath);
|
||||||
|
options.SetURL(mainURL, mainURL);
|
||||||
|
}
|
||||||
|
|
||||||
// 注意:将下载器进行包裹,可以避免父类任务终止的时候,连带子任务里的下载器也一起被终止!
|
var downloader = new DownloadPackageBundleOperation(this, bundle, options);
|
||||||
var wrapper = new DownloadFileWrapper(downloader);
|
return downloader;
|
||||||
return wrapper;
|
|
||||||
}
|
}
|
||||||
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -55,10 +55,9 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.DownloadFile)
|
if (_steps == ESteps.DownloadFile)
|
||||||
{
|
{
|
||||||
// 注意:边玩边下下载器引用计数没有Release
|
|
||||||
if (_downloadFileOp == null)
|
if (_downloadFileOp == null)
|
||||||
{
|
{
|
||||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
|
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||||
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options);
|
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options);
|
||||||
_downloadFileOp.StartOperation();
|
_downloadFileOp.StartOperation();
|
||||||
AddChildOperation(_downloadFileOp);
|
AddChildOperation(_downloadFileOp);
|
||||||
@@ -303,10 +302,9 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.DownloadFile)
|
if (_steps == ESteps.DownloadFile)
|
||||||
{
|
{
|
||||||
// 注意:边玩边下下载器引用计数没有Release
|
|
||||||
if (_downloadFileOp == null)
|
if (_downloadFileOp == null)
|
||||||
{
|
{
|
||||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
|
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||||
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options);
|
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options);
|
||||||
_downloadFileOp.StartOperation();
|
_downloadFileOp.StartOperation();
|
||||||
AddChildOperation(_downloadFileOp);
|
AddChildOperation(_downloadFileOp);
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ namespace YooAsset
|
|||||||
internal class DownloadCenterOperation : AsyncOperationBase
|
internal class DownloadCenterOperation : AsyncOperationBase
|
||||||
{
|
{
|
||||||
private readonly DefaultCacheFileSystem _fileSystem;
|
private readonly DefaultCacheFileSystem _fileSystem;
|
||||||
protected readonly Dictionary<string, DefaultDownloadFileOperation> _downloaders = new Dictionary<string, DefaultDownloadFileOperation>(1000);
|
protected readonly Dictionary<string, UnityDownloadFileOperation> _downloaders = new Dictionary<string, UnityDownloadFileOperation>(1000);
|
||||||
protected readonly List<string> _removeDownloadList = new List<string>(1000);
|
protected readonly List<string> _removeList = new List<string>(1000);
|
||||||
|
|
||||||
public DownloadCenterOperation(DefaultCacheFileSystem fileSystem)
|
public DownloadCenterOperation(DefaultCacheFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
@@ -19,29 +19,28 @@ namespace YooAsset
|
|||||||
internal override void InternalUpdate()
|
internal override void InternalUpdate()
|
||||||
{
|
{
|
||||||
// 获取可移除的下载器集合
|
// 获取可移除的下载器集合
|
||||||
_removeDownloadList.Clear();
|
_removeList.Clear();
|
||||||
foreach (var valuePair in _downloaders)
|
foreach (var valuePair in _downloaders)
|
||||||
{
|
{
|
||||||
var downloader = valuePair.Value;
|
var downloader = valuePair.Value;
|
||||||
downloader.UpdateOperation();
|
downloader.UpdateOperation();
|
||||||
|
if (downloader.IsDone)
|
||||||
|
{
|
||||||
|
_removeList.Add(valuePair.Key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// 注意:主动终止引用计数为零的下载任务
|
// 注意:主动终止引用计数为零的下载任务
|
||||||
if (downloader.RefCount <= 0)
|
if (downloader.RefCount <= 0)
|
||||||
{
|
{
|
||||||
_removeDownloadList.Add(valuePair.Key);
|
_removeList.Add(valuePair.Key);
|
||||||
downloader.AbortOperation();
|
downloader.AbortOperation();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downloader.IsDone)
|
|
||||||
{
|
|
||||||
_removeDownloadList.Add(valuePair.Key);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 移除下载器
|
// 移除下载器
|
||||||
foreach (var key in _removeDownloadList)
|
foreach (var key in _removeList)
|
||||||
{
|
{
|
||||||
_downloaders.Remove(key);
|
_downloaders.Remove(key);
|
||||||
}
|
}
|
||||||
@@ -74,34 +73,21 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建下载任务
|
/// 创建下载任务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
public UnityDownloadFileOperation DownloadFileAsync(PackageBundle bundle, string url)
|
||||||
{
|
{
|
||||||
// 查询旧的下载器
|
// 查询旧的下载器
|
||||||
if (_downloaders.TryGetValue(bundle.BundleGUID, out var oldDownloader))
|
if (_downloaders.TryGetValue(bundle.BundleGUID, out var oldDownloader))
|
||||||
{
|
{
|
||||||
|
oldDownloader.Reference();
|
||||||
return oldDownloader;
|
return oldDownloader;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取下载地址
|
|
||||||
if (string.IsNullOrEmpty(options.ImportFilePath))
|
|
||||||
{
|
|
||||||
// 注意:如果是解压文件系统类,这里会返回本地内置文件的下载路径
|
|
||||||
options.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(bundle.FileName);
|
|
||||||
options.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 注意:把本地导入文件路径转换为下载器请求地址
|
|
||||||
options.MainURL = DownloadSystemHelper.ConvertToWWWPath(options.ImportFilePath);
|
|
||||||
options.FallbackURL = options.MainURL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建新的下载器
|
// 创建新的下载器
|
||||||
DefaultDownloadFileOperation newDownloader;
|
UnityDownloadFileOperation newDownloader;
|
||||||
bool isRequestLocalFile = DownloadSystemHelper.IsRequestLocalFile(options.MainURL);
|
bool isRequestLocalFile = DownloadSystemHelper.IsRequestLocalFile(url);
|
||||||
if (isRequestLocalFile)
|
if (isRequestLocalFile)
|
||||||
{
|
{
|
||||||
newDownloader = new DownloadLocalFileOperation(_fileSystem, bundle, options);
|
newDownloader = new UnityDownloadLocalFileOperation(_fileSystem, bundle, url);
|
||||||
AddChildOperation(newDownloader);
|
AddChildOperation(newDownloader);
|
||||||
_downloaders.Add(bundle.BundleGUID, newDownloader);
|
_downloaders.Add(bundle.BundleGUID, newDownloader);
|
||||||
}
|
}
|
||||||
@@ -109,17 +95,19 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (bundle.FileSize >= _fileSystem.ResumeDownloadMinimumSize)
|
if (bundle.FileSize >= _fileSystem.ResumeDownloadMinimumSize)
|
||||||
{
|
{
|
||||||
newDownloader = new DownloadResumeFileOperation(_fileSystem, bundle, options);
|
newDownloader = new UnityDownloadResumeFileOperation(_fileSystem, bundle, url);
|
||||||
AddChildOperation(newDownloader);
|
AddChildOperation(newDownloader);
|
||||||
_downloaders.Add(bundle.BundleGUID, newDownloader);
|
_downloaders.Add(bundle.BundleGUID, newDownloader);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
newDownloader = new DownloadNormalFileOperation(_fileSystem, bundle, options);
|
newDownloader = new UnityDownloadNormalFileOperation(_fileSystem, bundle, url);
|
||||||
AddChildOperation(newDownloader);
|
AddChildOperation(newDownloader);
|
||||||
_downloaders.Add(bundle.BundleGUID, newDownloader);
|
_downloaders.Add(bundle.BundleGUID, newDownloader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newDownloader.Reference();
|
||||||
return newDownloader;
|
return newDownloader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Networking;
|
|
||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 支持Unity2018版本的断点续传下载器
|
|
||||||
/// </summary>
|
|
||||||
internal class DownloadHandlerFileRange : DownloadHandlerScript
|
|
||||||
{
|
|
||||||
private string _fileSavePath;
|
|
||||||
private long _fileTotalSize;
|
|
||||||
private UnityWebRequest _webRequest;
|
|
||||||
private FileStream _fileStream;
|
|
||||||
|
|
||||||
private long _localFileSize = 0;
|
|
||||||
private long _curFileSize = 0;
|
|
||||||
|
|
||||||
|
|
||||||
public DownloadHandlerFileRange(string fileSavePath, long fileTotalSize, UnityWebRequest webRequest) : base(new byte[1024 * 1024])
|
|
||||||
{
|
|
||||||
_fileSavePath = fileSavePath;
|
|
||||||
_fileTotalSize = fileTotalSize;
|
|
||||||
_webRequest = webRequest;
|
|
||||||
|
|
||||||
if (File.Exists(fileSavePath))
|
|
||||||
{
|
|
||||||
FileInfo fileInfo = new FileInfo(fileSavePath);
|
|
||||||
_localFileSize = fileInfo.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
_fileStream = new FileStream(_fileSavePath, FileMode.Append, FileAccess.Write);
|
|
||||||
_curFileSize = _localFileSize;
|
|
||||||
}
|
|
||||||
protected override bool ReceiveData(byte[] data, int dataLength)
|
|
||||||
{
|
|
||||||
if (data == null || dataLength == 0 || _webRequest.responseCode >= 400)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (_fileStream == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
_fileStream.Write(data, 0, dataLength);
|
|
||||||
_curFileSize += dataLength;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// UnityWebRequest.downloadHandler.data
|
|
||||||
/// </summary>
|
|
||||||
protected override byte[] GetData()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// UnityWebRequest.downloadHandler.text
|
|
||||||
/// </summary>
|
|
||||||
protected override string GetText()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// UnityWebRequest.downloadProgress
|
|
||||||
/// </summary>
|
|
||||||
protected override float GetProgress()
|
|
||||||
{
|
|
||||||
return _fileTotalSize == 0 ? 0 : ((float)_curFileSize) / _fileTotalSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 释放下载句柄
|
|
||||||
/// </summary>
|
|
||||||
public void Cleanup()
|
|
||||||
{
|
|
||||||
if (_fileStream != null)
|
|
||||||
{
|
|
||||||
_fileStream.Flush();
|
|
||||||
_fileStream.Dispose();
|
|
||||||
_fileStream = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,194 +0,0 @@
|
|||||||
using System.IO;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Networking;
|
|
||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
internal sealed class DownloadNormalFileOperation : DefaultDownloadFileOperation
|
|
||||||
{
|
|
||||||
private readonly DefaultCacheFileSystem _fileSystem;
|
|
||||||
private VerifyTempFileOperation _verifyOperation;
|
|
||||||
private string _tempFilePath;
|
|
||||||
private ESteps _steps = ESteps.None;
|
|
||||||
|
|
||||||
internal DownloadNormalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
|
|
||||||
{
|
|
||||||
_fileSystem = fileSystem;
|
|
||||||
}
|
|
||||||
internal override void InternalStart()
|
|
||||||
{
|
|
||||||
_tempFilePath = _fileSystem.GetTempFilePath(Bundle);
|
|
||||||
_steps = ESteps.CheckExists;
|
|
||||||
}
|
|
||||||
internal override void InternalUpdate()
|
|
||||||
{
|
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 检测文件是否存在
|
|
||||||
if (_steps == ESteps.CheckExists)
|
|
||||||
{
|
|
||||||
if (_fileSystem.Exists(Bundle))
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
if (_steps == ESteps.CreateRequest)
|
|
||||||
{
|
|
||||||
FileUtility.CreateFileDirectory(_tempFilePath);
|
|
||||||
|
|
||||||
// 删除临时文件
|
|
||||||
if (File.Exists(_tempFilePath))
|
|
||||||
File.Delete(_tempFilePath);
|
|
||||||
|
|
||||||
// 获取请求地址
|
|
||||||
_requestURL = GetRequestURL();
|
|
||||||
|
|
||||||
// 重置请求
|
|
||||||
ResetRequestFiled();
|
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
CreateWebRequest();
|
|
||||||
|
|
||||||
_steps = ESteps.CheckRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检测下载结果
|
|
||||||
if (_steps == ESteps.CheckRequest)
|
|
||||||
{
|
|
||||||
DownloadProgress = _webRequest.downloadProgress;
|
|
||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
|
||||||
Progress = DownloadProgress;
|
|
||||||
if (_webRequest.isDone == false)
|
|
||||||
{
|
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查网络错误
|
|
||||||
if (CheckRequestResult())
|
|
||||||
_steps = ESteps.VerifyTempFile;
|
|
||||||
else
|
|
||||||
_steps = ESteps.TryAgain;
|
|
||||||
|
|
||||||
// 注意:最终释放请求器
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证下载文件
|
|
||||||
if (_steps == ESteps.VerifyTempFile)
|
|
||||||
{
|
|
||||||
var element = new TempFileElement(_tempFilePath, Bundle.FileCRC, Bundle.FileSize);
|
|
||||||
_verifyOperation = new VerifyTempFileOperation(element);
|
|
||||||
_verifyOperation.StartOperation();
|
|
||||||
AddChildOperation(_verifyOperation);
|
|
||||||
_steps = ESteps.CheckVerifyTempFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 等待验证完成
|
|
||||||
if (_steps == ESteps.CheckVerifyTempFile)
|
|
||||||
{
|
|
||||||
if (IsWaitForAsyncComplete)
|
|
||||||
_verifyOperation.WaitForAsyncComplete();
|
|
||||||
|
|
||||||
_verifyOperation.UpdateOperation();
|
|
||||||
if (_verifyOperation.IsDone == false)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_verifyOperation.Status == EOperationStatus.Succeed)
|
|
||||||
{
|
|
||||||
if (_fileSystem.WriteCacheBundleFile(Bundle, _tempFilePath))
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = $"{_fileSystem.GetType().FullName} failed to write file !";
|
|
||||||
YooLogger.Error(Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.TryAgain;
|
|
||||||
Error = _verifyOperation.Error;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 注意:验证完成后直接删除文件
|
|
||||||
if (File.Exists(_tempFilePath))
|
|
||||||
File.Delete(_tempFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 重新尝试下载
|
|
||||||
if (_steps == ESteps.TryAgain)
|
|
||||||
{
|
|
||||||
if (FailedTryAgain <= 0)
|
|
||||||
{
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
YooLogger.Error(Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_tryAgainTimer += Time.unscaledDeltaTime;
|
|
||||||
if (_tryAgainTimer > 1f)
|
|
||||||
{
|
|
||||||
FailedTryAgain--;
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
YooLogger.Warning(Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
internal override void InternalAbort()
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
|
||||||
internal override void InternalWaitForAsyncComplete()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (ExecuteWhileDone())
|
|
||||||
{
|
|
||||||
//TODO 尝试同步加载远端的资源文件失败
|
|
||||||
if (Status == EOperationStatus.Failed)
|
|
||||||
{
|
|
||||||
YooLogger.Error($"Try load bundle {Bundle.BundleName} from remote !");
|
|
||||||
YooLogger.Error($"The load remote bundle url : {_requestURL}");
|
|
||||||
}
|
|
||||||
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateWebRequest()
|
|
||||||
{
|
|
||||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
|
||||||
DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath);
|
|
||||||
handler.removeFileOnAbort = true;
|
|
||||||
_webRequest.downloadHandler = handler;
|
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
|
||||||
_webRequest.SendWebRequest();
|
|
||||||
}
|
|
||||||
private void DisposeWebRequest()
|
|
||||||
{
|
|
||||||
if (_webRequest != null)
|
|
||||||
{
|
|
||||||
//注意:引擎底层会自动调用Abort方法
|
|
||||||
_webRequest.Dispose();
|
|
||||||
_webRequest = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class DownloadPackageBundleOperation : FSDownloadFileOperation
|
||||||
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CheckExists,
|
||||||
|
CreateRequest,
|
||||||
|
CheckRequest,
|
||||||
|
TryAgain,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 下载参数
|
||||||
|
protected readonly DefaultCacheFileSystem _fileSystem;
|
||||||
|
protected readonly DownloadFileOptions _options;
|
||||||
|
private UnityDownloadFileOperation _unityDownloadFileOp;
|
||||||
|
|
||||||
|
protected int _requestCount = 0;
|
||||||
|
protected float _tryAgainTimer;
|
||||||
|
protected int _failedTryAgain;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
|
internal DownloadPackageBundleOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle)
|
||||||
|
{
|
||||||
|
_fileSystem = fileSystem;
|
||||||
|
_options = options;
|
||||||
|
_failedTryAgain = options.FailedTryAgain;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.CheckExists;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 检测文件是否存在
|
||||||
|
if (_steps == ESteps.CheckExists)
|
||||||
|
{
|
||||||
|
if (_fileSystem.Exists(Bundle))
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建下载器
|
||||||
|
if (_steps == ESteps.CreateRequest)
|
||||||
|
{
|
||||||
|
if (_options.IsValid() == false)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = "Download file options is invalid !";
|
||||||
|
Debug.Log(Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string url = GetRequestURL();
|
||||||
|
_unityDownloadFileOp = _fileSystem.DownloadCenter.DownloadFileAsync(Bundle, url);
|
||||||
|
_steps = ESteps.CheckRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测下载结果
|
||||||
|
if (_steps == ESteps.CheckRequest)
|
||||||
|
{
|
||||||
|
if (IsWaitForAsyncComplete)
|
||||||
|
_unityDownloadFileOp.WaitForAsyncComplete();
|
||||||
|
|
||||||
|
// 因为并发数量限制,下载器可能被挂起!
|
||||||
|
if (_unityDownloadFileOp.Status == EOperationStatus.None)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_unityDownloadFileOp.UpdateOperation();
|
||||||
|
Progress = _unityDownloadFileOp.Progress;
|
||||||
|
DownloadedBytes = _unityDownloadFileOp.DownloadedBytes;
|
||||||
|
DownloadProgress = _unityDownloadFileOp.DownloadProgress;
|
||||||
|
if (_unityDownloadFileOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_unityDownloadFileOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (IsWaitForAsyncComplete == false && _failedTryAgain > 0)
|
||||||
|
{
|
||||||
|
_steps = ESteps.TryAgain;
|
||||||
|
YooLogger.Warning($"Failed download : {_unityDownloadFileOp.URL} Try again !");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _unityDownloadFileOp.Error;
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重新尝试下载
|
||||||
|
if (_steps == ESteps.TryAgain)
|
||||||
|
{
|
||||||
|
_tryAgainTimer += Time.unscaledDeltaTime;
|
||||||
|
if (_tryAgainTimer > 1f)
|
||||||
|
{
|
||||||
|
_tryAgainTimer = 0f;
|
||||||
|
_failedTryAgain--;
|
||||||
|
Progress = 0f;
|
||||||
|
DownloadProgress = 0f;
|
||||||
|
DownloadedBytes = 0;
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal override void InternalWaitForAsyncComplete()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (ExecuteWhileDone())
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal override void InternalAbort()
|
||||||
|
{
|
||||||
|
// 注意:取消下载任务的时候引用计数减一
|
||||||
|
if (_steps != ESteps.Done)
|
||||||
|
{
|
||||||
|
if (_unityDownloadFileOp != null)
|
||||||
|
{
|
||||||
|
_unityDownloadFileOp.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取网络请求地址
|
||||||
|
/// </summary>
|
||||||
|
protected string GetRequestURL()
|
||||||
|
{
|
||||||
|
// 轮流返回请求地址
|
||||||
|
_requestCount++;
|
||||||
|
if (_requestCount % 2 == 0)
|
||||||
|
return _options.FallbackURL;
|
||||||
|
else
|
||||||
|
return _options.MainURL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal abstract class UnityDownloadFileOperation : UnityWebRequestOperation
|
||||||
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
Download,
|
||||||
|
CopyLocalFile,
|
||||||
|
VerifyFile,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
protected readonly DefaultCacheFileSystem _fileSystem;
|
||||||
|
protected readonly PackageBundle _bundle;
|
||||||
|
protected readonly string _tempFilePath;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 引用计数
|
||||||
|
/// </summary>
|
||||||
|
public int RefCount { private set; get; }
|
||||||
|
|
||||||
|
internal UnityDownloadFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string url) : base(url)
|
||||||
|
{
|
||||||
|
_fileSystem = fileSystem;
|
||||||
|
_bundle = bundle;
|
||||||
|
_tempFilePath = _fileSystem.GetTempFilePath(bundle);
|
||||||
|
}
|
||||||
|
internal override string InternalGetDesc()
|
||||||
|
{
|
||||||
|
return $"RefCount : {RefCount}";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 减少引用计数
|
||||||
|
/// </summary>
|
||||||
|
public void Release()
|
||||||
|
{
|
||||||
|
RefCount--;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 增加引用计数
|
||||||
|
/// </summary>
|
||||||
|
public void Reference()
|
||||||
|
{
|
||||||
|
RefCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 40bb5e9391f413c42ae70e48ca90c4b7
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -4,140 +4,110 @@ using UnityEngine.Networking;
|
|||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
internal class DownloadLocalFileOperation : DefaultDownloadFileOperation
|
internal class UnityDownloadLocalFileOperation : UnityDownloadFileOperation
|
||||||
{
|
{
|
||||||
private readonly DefaultCacheFileSystem _fileSystem;
|
|
||||||
private VerifyTempFileOperation _verifyOperation;
|
private VerifyTempFileOperation _verifyOperation;
|
||||||
private string _tempFilePath;
|
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal DownloadLocalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
|
internal UnityDownloadLocalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string url)
|
||||||
|
: base(fileSystem, bundle, url)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
_tempFilePath = _fileSystem.GetTempFilePath(Bundle);
|
if (_fileSystem.CopyLocalFileServices != null)
|
||||||
_steps = ESteps.CheckExists;
|
_steps = ESteps.CopyLocalFile;
|
||||||
|
else
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
}
|
}
|
||||||
internal override void InternalUpdate()
|
internal override void InternalUpdate()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 检测文件是否存在
|
|
||||||
if (_steps == ESteps.CheckExists)
|
|
||||||
{
|
|
||||||
if (_fileSystem.Exists(Bundle))
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (_fileSystem.CopyLocalFileServices != null)
|
|
||||||
_steps = ESteps.CopyBuildinBundle;
|
|
||||||
else
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建下载器
|
// 创建下载器
|
||||||
if (_steps == ESteps.CreateRequest)
|
if (_steps == ESteps.CreateRequest)
|
||||||
{
|
{
|
||||||
FileUtility.CreateFileDirectory(_tempFilePath);
|
FileUtility.CreateFileDirectory(_tempFilePath);
|
||||||
|
|
||||||
// 删除临时文件
|
|
||||||
if (File.Exists(_tempFilePath))
|
if (File.Exists(_tempFilePath))
|
||||||
File.Delete(_tempFilePath);
|
File.Delete(_tempFilePath);
|
||||||
|
|
||||||
// 获取请求地址
|
|
||||||
_requestURL = GetRequestURL();
|
|
||||||
|
|
||||||
// 重置请求
|
|
||||||
ResetRequestFiled();
|
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
CreateWebRequest();
|
CreateWebRequest();
|
||||||
|
_steps = ESteps.Download;
|
||||||
_steps = ESteps.CheckRequest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测下载结果
|
// 检测下载结果
|
||||||
if (_steps == ESteps.CheckRequest)
|
if (_steps == ESteps.Download)
|
||||||
{
|
{
|
||||||
DownloadProgress = _webRequest.downloadProgress;
|
DownloadProgress = _webRequest.downloadProgress;
|
||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
Progress = DownloadProgress;
|
Progress = DownloadProgress;
|
||||||
if (_webRequest.isDone == false)
|
if (_webRequest.isDone == false)
|
||||||
{
|
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// 检查网络错误
|
// 检查网络错误
|
||||||
if (CheckRequestResult())
|
if (CheckRequestResult())
|
||||||
_steps = ESteps.VerifyTempFile;
|
{
|
||||||
|
_steps = ESteps.VerifyFile;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
_steps = ESteps.TryAgain;
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
// 注意:最终释放请求器
|
// 注意:最终释放请求器
|
||||||
DisposeWebRequest();
|
DisposeRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝内置文件
|
// 拷贝内置文件
|
||||||
if (_steps == ESteps.CopyBuildinBundle)
|
if (_steps == ESteps.CopyLocalFile)
|
||||||
{
|
{
|
||||||
FileUtility.CreateFileDirectory(_tempFilePath);
|
FileUtility.CreateFileDirectory(_tempFilePath);
|
||||||
|
|
||||||
// 删除临时文件
|
|
||||||
if (File.Exists(_tempFilePath))
|
if (File.Exists(_tempFilePath))
|
||||||
File.Delete(_tempFilePath);
|
File.Delete(_tempFilePath);
|
||||||
|
|
||||||
// 获取请求地址
|
|
||||||
_requestURL = GetRequestURL();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//TODO 团结引擎,在某些机型(红米),拷贝包内文件会小概率失败!需要借助其它方式来拷贝包内文件。
|
//TODO 团结引擎,在某些机型(红米),拷贝包内文件会小概率失败!需要借助其它方式来拷贝包内文件。
|
||||||
var localFileInfo = new LocalFileInfo();
|
var localFileInfo = new LocalFileInfo();
|
||||||
localFileInfo.PackageName = _fileSystem.PackageName;
|
localFileInfo.PackageName = _fileSystem.PackageName;
|
||||||
localFileInfo.BundleName = Bundle.BundleName;
|
localFileInfo.BundleName = _bundle.BundleName;
|
||||||
localFileInfo.SourceFileURL = _requestURL;
|
localFileInfo.SourceFileURL = _requestURL;
|
||||||
_fileSystem.CopyLocalFileServices.CopyFile(localFileInfo, _tempFilePath);
|
_fileSystem.CopyLocalFileServices.CopyFile(localFileInfo, _tempFilePath);
|
||||||
if (File.Exists(_tempFilePath))
|
if (File.Exists(_tempFilePath))
|
||||||
{
|
{
|
||||||
DownloadProgress = 1f;
|
DownloadProgress = 1f;
|
||||||
DownloadedBytes = Bundle.FileSize;
|
DownloadedBytes = _bundle.FileSize;
|
||||||
Progress = DownloadProgress;
|
Progress = DownloadProgress;
|
||||||
_steps = ESteps.VerifyTempFile;
|
_steps = ESteps.VerifyFile;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
Error = $"Failed copy local file : {_requestURL}";
|
Error = $"Failed copy local file : {_requestURL}";
|
||||||
_steps = ESteps.TryAgain;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (System.Exception ex)
|
catch (System.Exception ex)
|
||||||
{
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
Error = $"Failed copy local file : {ex.Message}";
|
Error = $"Failed copy local file : {ex.Message}";
|
||||||
_steps = ESteps.TryAgain;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证下载文件
|
// 验证下载文件
|
||||||
if (_steps == ESteps.VerifyTempFile)
|
if (_steps == ESteps.VerifyFile)
|
||||||
{
|
{
|
||||||
var element = new TempFileElement(_tempFilePath, Bundle.FileCRC, Bundle.FileSize);
|
if (_verifyOperation == null)
|
||||||
|
{
|
||||||
|
var element = new TempFileElement(_tempFilePath, _bundle.FileCRC, _bundle.FileSize);
|
||||||
_verifyOperation = new VerifyTempFileOperation(element);
|
_verifyOperation = new VerifyTempFileOperation(element);
|
||||||
_verifyOperation.StartOperation();
|
_verifyOperation.StartOperation();
|
||||||
AddChildOperation(_verifyOperation);
|
AddChildOperation(_verifyOperation);
|
||||||
_steps = ESteps.CheckVerifyTempFile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 等待验证完成
|
|
||||||
if (_steps == ESteps.CheckVerifyTempFile)
|
|
||||||
{
|
|
||||||
if (IsWaitForAsyncComplete)
|
if (IsWaitForAsyncComplete)
|
||||||
_verifyOperation.WaitForAsyncComplete();
|
_verifyOperation.WaitForAsyncComplete();
|
||||||
|
|
||||||
@@ -147,7 +117,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_verifyOperation.Status == EOperationStatus.Succeed)
|
if (_verifyOperation.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
if (_fileSystem.WriteCacheBundleFile(Bundle, _tempFilePath))
|
if (_fileSystem.WriteCacheBundleFile(_bundle, _tempFilePath))
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
@@ -157,12 +127,12 @@ namespace YooAsset
|
|||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = $"{_fileSystem.GetType().FullName} failed to write file !";
|
Error = $"{_fileSystem.GetType().FullName} failed to write file !";
|
||||||
YooLogger.Error(Error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.TryAgain;
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
Error = _verifyOperation.Error;
|
Error = _verifyOperation.Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,20 +140,6 @@ namespace YooAsset
|
|||||||
if (File.Exists(_tempFilePath))
|
if (File.Exists(_tempFilePath))
|
||||||
File.Delete(_tempFilePath);
|
File.Delete(_tempFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新尝试下载
|
|
||||||
if (_steps == ESteps.TryAgain)
|
|
||||||
{
|
|
||||||
//TODO 拷贝本地文件失败后不再尝试!
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
YooLogger.Error(Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
internal override void InternalAbort()
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
}
|
||||||
internal override void InternalWaitForAsyncComplete()
|
internal override void InternalWaitForAsyncComplete()
|
||||||
{
|
{
|
||||||
@@ -201,21 +157,12 @@ namespace YooAsset
|
|||||||
|
|
||||||
private void CreateWebRequest()
|
private void CreateWebRequest()
|
||||||
{
|
{
|
||||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
|
||||||
DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath);
|
DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath);
|
||||||
handler.removeFileOnAbort = true;
|
handler.removeFileOnAbort = true;
|
||||||
|
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||||
_webRequest.downloadHandler = handler;
|
_webRequest.downloadHandler = handler;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
_webRequest.SendWebRequest();
|
_webRequest.SendWebRequest();
|
||||||
}
|
}
|
||||||
private void DisposeWebRequest()
|
|
||||||
{
|
|
||||||
if (_webRequest != null)
|
|
||||||
{
|
|
||||||
//注意:引擎底层会自动调用Abort方法
|
|
||||||
_webRequest.Dispose();
|
|
||||||
_webRequest = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
using System.IO;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal sealed class UnityDownloadNormalFileOperation : UnityDownloadFileOperation
|
||||||
|
{
|
||||||
|
private VerifyTempFileOperation _verifyOperation;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
internal UnityDownloadNormalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string url)
|
||||||
|
: base(fileSystem, bundle, url)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 创建下载器
|
||||||
|
if (_steps == ESteps.CreateRequest)
|
||||||
|
{
|
||||||
|
FileUtility.CreateFileDirectory(_tempFilePath);
|
||||||
|
if (File.Exists(_tempFilePath))
|
||||||
|
File.Delete(_tempFilePath);
|
||||||
|
|
||||||
|
CreateWebRequest();
|
||||||
|
_steps = ESteps.Download;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测下载结果
|
||||||
|
if (_steps == ESteps.Download)
|
||||||
|
{
|
||||||
|
DownloadProgress = _webRequest.downloadProgress;
|
||||||
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
|
Progress = DownloadProgress;
|
||||||
|
if (_webRequest.isDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 检查网络错误
|
||||||
|
if (CheckRequestResult())
|
||||||
|
{
|
||||||
|
_steps = ESteps.VerifyFile;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注意:最终释放请求器
|
||||||
|
DisposeRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证下载文件
|
||||||
|
if (_steps == ESteps.VerifyFile)
|
||||||
|
{
|
||||||
|
if (_verifyOperation == null)
|
||||||
|
{
|
||||||
|
var element = new TempFileElement(_tempFilePath, _bundle.FileCRC, _bundle.FileSize);
|
||||||
|
_verifyOperation = new VerifyTempFileOperation(element);
|
||||||
|
_verifyOperation.StartOperation();
|
||||||
|
AddChildOperation(_verifyOperation);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsWaitForAsyncComplete)
|
||||||
|
_verifyOperation.WaitForAsyncComplete();
|
||||||
|
|
||||||
|
_verifyOperation.UpdateOperation();
|
||||||
|
if (_verifyOperation.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_verifyOperation.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
if (_fileSystem.WriteCacheBundleFile(_bundle, _tempFilePath))
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"{_fileSystem.GetType().FullName} failed to write file ! {_tempFilePath}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _verifyOperation.Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注意:验证完成后直接删除文件
|
||||||
|
if (File.Exists(_tempFilePath))
|
||||||
|
File.Delete(_tempFilePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal override void InternalWaitForAsyncComplete()
|
||||||
|
{
|
||||||
|
if (_steps != ESteps.Done)
|
||||||
|
{
|
||||||
|
YooLogger.Error($"Try load bundle {_bundle.BundleName} from remote : {_requestURL} !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateWebRequest()
|
||||||
|
{
|
||||||
|
DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath);
|
||||||
|
handler.removeFileOnAbort = true;
|
||||||
|
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||||
|
_webRequest.downloadHandler = handler;
|
||||||
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
|
_webRequest.SendWebRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,63 +4,38 @@ using UnityEngine.Networking;
|
|||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
internal sealed class DownloadResumeFileOperation : DefaultDownloadFileOperation
|
internal sealed class UnityDownloadResumeFileOperation : UnityDownloadFileOperation
|
||||||
{
|
{
|
||||||
private readonly DefaultCacheFileSystem _fileSystem;
|
|
||||||
private DownloadHandlerFileRange _downloadHandle;
|
|
||||||
private VerifyTempFileOperation _verifyOperation;
|
private VerifyTempFileOperation _verifyOperation;
|
||||||
private long _fileOriginLength = 0;
|
private long _fileOriginLength = 0;
|
||||||
private string _tempFilePath;
|
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal DownloadResumeFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
|
internal UnityDownloadResumeFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string url)
|
||||||
|
: base(fileSystem, bundle, url)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
_tempFilePath = _fileSystem.GetTempFilePath(Bundle);
|
_steps = ESteps.CreateRequest;
|
||||||
_steps = ESteps.CheckExists;
|
|
||||||
}
|
}
|
||||||
internal override void InternalUpdate()
|
internal override void InternalUpdate()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 检测文件是否存在
|
|
||||||
if (_steps == ESteps.CheckExists)
|
|
||||||
{
|
|
||||||
if (_fileSystem.Exists(Bundle))
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建下载器
|
// 创建下载器
|
||||||
if (_steps == ESteps.CreateRequest)
|
if (_steps == ESteps.CreateRequest)
|
||||||
{
|
{
|
||||||
FileUtility.CreateFileDirectory(_tempFilePath);
|
FileUtility.CreateFileDirectory(_tempFilePath);
|
||||||
|
|
||||||
// 获取请求地址
|
|
||||||
_requestURL = GetRequestURL();
|
|
||||||
|
|
||||||
// 重置变量
|
|
||||||
ResetRequestFiled();
|
|
||||||
|
|
||||||
// 获取下载起始位置
|
// 获取下载起始位置
|
||||||
_fileOriginLength = 0;
|
_fileOriginLength = 0;
|
||||||
long fileBeginLength = -1;
|
long fileBeginLength = -1;
|
||||||
if (File.Exists(_tempFilePath))
|
if (File.Exists(_tempFilePath))
|
||||||
{
|
{
|
||||||
FileInfo fileInfo = new FileInfo(_tempFilePath);
|
FileInfo fileInfo = new FileInfo(_tempFilePath);
|
||||||
if (fileInfo.Length >= Bundle.FileSize)
|
if (fileInfo.Length >= _bundle.FileSize)
|
||||||
{
|
{
|
||||||
// 删除临时文件
|
|
||||||
File.Delete(_tempFilePath);
|
File.Delete(_tempFilePath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -71,49 +46,48 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
CreateWebRequest(fileBeginLength);
|
CreateWebRequest(fileBeginLength);
|
||||||
|
_steps = ESteps.Download;
|
||||||
_steps = ESteps.CheckRequest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测下载结果
|
// 检测下载结果
|
||||||
if (_steps == ESteps.CheckRequest)
|
if (_steps == ESteps.Download)
|
||||||
{
|
{
|
||||||
DownloadProgress = _webRequest.downloadProgress;
|
DownloadProgress = _webRequest.downloadProgress;
|
||||||
DownloadedBytes = _fileOriginLength + (long)_webRequest.downloadedBytes;
|
DownloadedBytes = _fileOriginLength + (long)_webRequest.downloadedBytes;
|
||||||
|
Progress = DownloadProgress;
|
||||||
if (_webRequest.isDone == false)
|
if (_webRequest.isDone == false)
|
||||||
{
|
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// 检查网络错误
|
// 检查网络错误
|
||||||
if (CheckRequestResult())
|
if (CheckRequestResult())
|
||||||
_steps = ESteps.VerifyTempFile;
|
{
|
||||||
|
_steps = ESteps.VerifyFile;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
_steps = ESteps.TryAgain;
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
// 在遇到特殊错误的时候删除文件
|
// 在遇到特殊错误的时候删除文件
|
||||||
ClearTempFileWhenError();
|
ClearTempFileWhenError();
|
||||||
|
|
||||||
// 注意:最终释放请求器
|
// 注意:最终释放请求器
|
||||||
DisposeWebRequest();
|
DisposeRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证下载文件
|
// 验证下载文件
|
||||||
if (_steps == ESteps.VerifyTempFile)
|
if (_steps == ESteps.VerifyFile)
|
||||||
{
|
{
|
||||||
var element = new TempFileElement(_tempFilePath, Bundle.FileCRC, Bundle.FileSize);
|
if (_verifyOperation == null)
|
||||||
|
{
|
||||||
|
var element = new TempFileElement(_tempFilePath, _bundle.FileCRC, _bundle.FileSize);
|
||||||
_verifyOperation = new VerifyTempFileOperation(element);
|
_verifyOperation = new VerifyTempFileOperation(element);
|
||||||
_verifyOperation.StartOperation();
|
_verifyOperation.StartOperation();
|
||||||
AddChildOperation(_verifyOperation);
|
AddChildOperation(_verifyOperation);
|
||||||
_steps = ESteps.CheckVerifyTempFile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 等待验证完成
|
|
||||||
if (_steps == ESteps.CheckVerifyTempFile)
|
|
||||||
{
|
|
||||||
if (IsWaitForAsyncComplete)
|
if (IsWaitForAsyncComplete)
|
||||||
_verifyOperation.WaitForAsyncComplete();
|
_verifyOperation.WaitForAsyncComplete();
|
||||||
|
|
||||||
@@ -123,104 +97,38 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_verifyOperation.Status == EOperationStatus.Succeed)
|
if (_verifyOperation.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
if (_fileSystem.WriteCacheBundleFile(Bundle, _tempFilePath))
|
if (_fileSystem.WriteCacheBundleFile(_bundle, _tempFilePath))
|
||||||
{
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
_steps = ESteps.Done;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Error = $"{_fileSystem.GetType().FullName} failed to write file !";
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
_steps = ESteps.Done;
|
Error = $"{_fileSystem.GetType().FullName} failed to write file !";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
Error = _verifyOperation.Error;
|
Error = _verifyOperation.Error;
|
||||||
_steps = ESteps.TryAgain;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注意:验证完成后直接删除文件
|
// 注意:验证完成后直接删除文件
|
||||||
if (File.Exists(_tempFilePath))
|
if (File.Exists(_tempFilePath))
|
||||||
File.Delete(_tempFilePath);
|
File.Delete(_tempFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新尝试下载
|
|
||||||
if (_steps == ESteps.TryAgain)
|
|
||||||
{
|
|
||||||
if (FailedTryAgain <= 0)
|
|
||||||
{
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
YooLogger.Error(Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_tryAgainTimer += Time.unscaledDeltaTime;
|
|
||||||
if (_tryAgainTimer > 1f)
|
|
||||||
{
|
|
||||||
FailedTryAgain--;
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
YooLogger.Warning(Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
internal override void InternalAbort()
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
}
|
||||||
internal override void InternalWaitForAsyncComplete()
|
internal override void InternalWaitForAsyncComplete()
|
||||||
{
|
{
|
||||||
while (true)
|
if (_steps != ESteps.Done)
|
||||||
{
|
{
|
||||||
if (ExecuteWhileDone())
|
YooLogger.Error($"Try load bundle {_bundle.BundleName} from remote : {_requestURL} !");
|
||||||
{
|
|
||||||
//TODO 尝试同步加载远端的资源文件失败
|
|
||||||
if (Status == EOperationStatus.Failed)
|
|
||||||
{
|
|
||||||
YooLogger.Error($"Try load bundle {Bundle.BundleName} from remote !");
|
|
||||||
YooLogger.Error($"The load remote bundle url : {_requestURL}");
|
|
||||||
}
|
|
||||||
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateWebRequest(long beginLength)
|
|
||||||
{
|
|
||||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
|
||||||
#if UNITY_2019_4_OR_NEWER
|
|
||||||
var handler = new DownloadHandlerFile(_tempFilePath, true);
|
|
||||||
handler.removeFileOnAbort = false;
|
|
||||||
#else
|
|
||||||
var handler = new DownloadHandlerFileRange(FileSavePath, Bundle.FileSize, _webRequest);
|
|
||||||
_downloadHandle = handler;
|
|
||||||
#endif
|
|
||||||
_webRequest.downloadHandler = handler;
|
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
|
||||||
if (beginLength > 0)
|
|
||||||
_webRequest.SetRequestHeader("Range", $"bytes={beginLength}-");
|
|
||||||
_webRequest.SendWebRequest();
|
|
||||||
}
|
|
||||||
private void DisposeWebRequest()
|
|
||||||
{
|
|
||||||
if (_downloadHandle != null)
|
|
||||||
{
|
|
||||||
_downloadHandle.Cleanup();
|
|
||||||
_downloadHandle = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_webRequest != null)
|
|
||||||
{
|
|
||||||
//注意:引擎底层会自动调用Abort方法
|
|
||||||
_webRequest.Dispose();
|
|
||||||
_webRequest = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ClearTempFileWhenError()
|
private void ClearTempFileWhenError()
|
||||||
{
|
{
|
||||||
if (_fileSystem.ResumeDownloadResponseCodes == null)
|
if (_fileSystem.ResumeDownloadResponseCodes == null)
|
||||||
@@ -233,5 +141,16 @@ namespace YooAsset
|
|||||||
File.Delete(_tempFilePath);
|
File.Delete(_tempFilePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void CreateWebRequest(long fileBeginLength)
|
||||||
|
{
|
||||||
|
var handler = new DownloadHandlerFile(_tempFilePath, true);
|
||||||
|
handler.removeFileOnAbort = false;
|
||||||
|
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||||
|
_webRequest.downloadHandler = handler;
|
||||||
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
|
if (fileBeginLength > 0)
|
||||||
|
_webRequest.SetRequestHeader("Range", $"bytes={fileBeginLength}-");
|
||||||
|
_webRequest.SendWebRequest();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,13 +6,13 @@ namespace YooAsset
|
|||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
DownloadAssetBundle,
|
LoadWebAssetBundle,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly DefaultWebRemoteFileSystem _fileSystem;
|
private readonly DefaultWebRemoteFileSystem _fileSystem;
|
||||||
private readonly PackageBundle _bundle;
|
private readonly PackageBundle _bundle;
|
||||||
private DownloadAssetBundleOperation _downloadAssetBundleOp;
|
private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
@@ -23,50 +23,51 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
_steps = ESteps.DownloadAssetBundle;
|
_steps = ESteps.LoadWebAssetBundle;
|
||||||
}
|
}
|
||||||
internal override void InternalUpdate()
|
internal override void InternalUpdate()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_steps == ESteps.DownloadAssetBundle)
|
if (_steps == ESteps.LoadWebAssetBundle)
|
||||||
{
|
{
|
||||||
if (_downloadAssetBundleOp == null)
|
if (_loadWebAssetBundleOp == null)
|
||||||
{
|
{
|
||||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
|
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
|
||||||
options.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
|
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
||||||
options.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||||
|
options.SetURL(mainURL, fallbackURL);
|
||||||
|
|
||||||
if (_bundle.Encrypted)
|
if (_bundle.Encrypted)
|
||||||
{
|
{
|
||||||
_downloadAssetBundleOp = new DownloadWebEncryptAssetBundleOperation(true, _fileSystem.DecryptionServices, _bundle, options);
|
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices);
|
||||||
_downloadAssetBundleOp.StartOperation();
|
_loadWebAssetBundleOp.StartOperation();
|
||||||
AddChildOperation(_downloadAssetBundleOp);
|
AddChildOperation(_loadWebAssetBundleOp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_downloadAssetBundleOp = new DownloadWebNormalAssetBundleOperation(_fileSystem.DisableUnityWebCache, _bundle, options);
|
_loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(_bundle, options, _fileSystem.DisableUnityWebCache);
|
||||||
_downloadAssetBundleOp.StartOperation();
|
_loadWebAssetBundleOp.StartOperation();
|
||||||
AddChildOperation(_downloadAssetBundleOp);
|
AddChildOperation(_loadWebAssetBundleOp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_downloadAssetBundleOp.UpdateOperation();
|
_loadWebAssetBundleOp.UpdateOperation();
|
||||||
DownloadProgress = _downloadAssetBundleOp.DownloadProgress;
|
DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
|
||||||
DownloadedBytes = _downloadAssetBundleOp.DownloadedBytes;
|
DownloadedBytes = _loadWebAssetBundleOp.DownloadedBytes;
|
||||||
Progress = _downloadAssetBundleOp.Progress;
|
Progress = _loadWebAssetBundleOp.Progress;
|
||||||
if (_downloadAssetBundleOp.IsDone == false)
|
if (_loadWebAssetBundleOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_downloadAssetBundleOp.Status == EOperationStatus.Succeed)
|
if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
var assetBundle = _downloadAssetBundleOp.Result;
|
var assetBundle = _loadWebAssetBundleOp.Result;
|
||||||
if (assetBundle == null)
|
if (assetBundle == null)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = $"{nameof(DownloadAssetBundleOperation)} loaded asset bundle is null !";
|
Error = $"{nameof(DWRFSLoadAssetBundleOperation)} loaded asset bundle is null !";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -79,7 +80,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _downloadAssetBundleOp.Error;
|
Error = _loadWebAssetBundleOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ namespace YooAsset
|
|||||||
if (_loadWebPackageManifestOp == null)
|
if (_loadWebPackageManifestOp == null)
|
||||||
{
|
{
|
||||||
string packageHash = _requestWebPackageHashOp.PackageHash;
|
string packageHash = _requestWebPackageHashOp.PackageHash;
|
||||||
_loadWebPackageManifestOp = new LoadWebRemotePackageManifestOperation(_fileSystem, _packageVersion, packageHash);
|
_loadWebPackageManifestOp = new LoadWebRemotePackageManifestOperation(_fileSystem, _packageVersion, packageHash, _timeout);
|
||||||
_loadWebPackageManifestOp.StartOperation();
|
_loadWebPackageManifestOp.StartOperation();
|
||||||
AddChildOperation(_loadWebPackageManifestOp);
|
AddChildOperation(_loadWebPackageManifestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace YooAsset
|
|||||||
private readonly DefaultWebRemoteFileSystem _fileSystem;
|
private readonly DefaultWebRemoteFileSystem _fileSystem;
|
||||||
private readonly string _packageVersion;
|
private readonly string _packageVersion;
|
||||||
private readonly string _packageHash;
|
private readonly string _packageHash;
|
||||||
|
private readonly int _timeout;
|
||||||
private UnityWebDataRequestOperation _webDataRequestOp;
|
private UnityWebDataRequestOperation _webDataRequestOp;
|
||||||
private DeserializeManifestOperation _deserializer;
|
private DeserializeManifestOperation _deserializer;
|
||||||
private int _requestCount = 0;
|
private int _requestCount = 0;
|
||||||
@@ -26,11 +27,12 @@ namespace YooAsset
|
|||||||
public PackageManifest Manifest { private set; get; }
|
public PackageManifest Manifest { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
internal LoadWebRemotePackageManifestOperation(DefaultWebRemoteFileSystem fileSystem, string packageVersion, string packageHash)
|
internal LoadWebRemotePackageManifestOperation(DefaultWebRemoteFileSystem fileSystem, string packageVersion, string packageHash, int timeout)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_packageVersion = packageVersion;
|
_packageVersion = packageVersion;
|
||||||
_packageHash = packageHash;
|
_packageHash = packageHash;
|
||||||
|
_timeout = timeout;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
@@ -48,7 +50,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_fileSystem.PackageName, _packageVersion);
|
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_fileSystem.PackageName, _packageVersion);
|
||||||
string url = GetWebRequestURL(fileName);
|
string url = GetWebRequestURL(fileName);
|
||||||
_webDataRequestOp = new UnityWebDataRequestOperation(url);
|
_webDataRequestOp = new UnityWebDataRequestOperation(url, _timeout);
|
||||||
_webDataRequestOp.StartOperation();
|
_webDataRequestOp.StartOperation();
|
||||||
AddChildOperation(_webDataRequestOp);
|
AddChildOperation(_webDataRequestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,23 +32,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (_loadCatalogFileOp == null)
|
if (_loadCatalogFileOp == null)
|
||||||
{
|
{
|
||||||
#if UNITY_EDITOR
|
_loadCatalogFileOp = new LoadWebServerCatalogFileOperation(_fileSystem, 60);
|
||||||
/*
|
|
||||||
// 兼容性初始化
|
|
||||||
// 说明:内置文件系统在编辑器下运行时需要动态生成
|
|
||||||
string packageRoot = _fileSystem.FileRoot;
|
|
||||||
bool result = DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.ManifestServices, _fileSystem.PackageName, packageRoot);
|
|
||||||
if (result == false)
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = $"Create package catalog file failed ! See the detail error in console !";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_loadCatalogFileOp = new LoadWebServerCatalogFileOperation(_fileSystem);
|
|
||||||
_loadCatalogFileOp.StartOperation();
|
_loadCatalogFileOp.StartOperation();
|
||||||
AddChildOperation(_loadCatalogFileOp);
|
AddChildOperation(_loadCatalogFileOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ namespace YooAsset
|
|||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
DownloadAssetBundle,
|
LoadWebAssetBundle,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly DefaultWebServerFileSystem _fileSystem;
|
private readonly DefaultWebServerFileSystem _fileSystem;
|
||||||
private readonly PackageBundle _bundle;
|
private readonly PackageBundle _bundle;
|
||||||
private DownloadAssetBundleOperation _downloadAssetBundleOp;
|
private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
@@ -23,51 +23,51 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
_steps = ESteps.DownloadAssetBundle;
|
_steps = ESteps.LoadWebAssetBundle;
|
||||||
}
|
}
|
||||||
internal override void InternalUpdate()
|
internal override void InternalUpdate()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_steps == ESteps.DownloadAssetBundle)
|
if (_steps == ESteps.LoadWebAssetBundle)
|
||||||
{
|
{
|
||||||
if (_downloadAssetBundleOp == null)
|
if (_loadWebAssetBundleOp == null)
|
||||||
{
|
{
|
||||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
|
|
||||||
string fileLoadPath = _fileSystem.GetWebFileLoadPath(_bundle);
|
string fileLoadPath = _fileSystem.GetWebFileLoadPath(_bundle);
|
||||||
options.MainURL = DownloadSystemHelper.ConvertToWWWPath(fileLoadPath);
|
string mainURL = DownloadSystemHelper.ConvertToWWWPath(fileLoadPath);
|
||||||
options.FallbackURL = options.MainURL;
|
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||||
|
options.SetURL(mainURL, mainURL);
|
||||||
|
|
||||||
if (_bundle.Encrypted)
|
if (_bundle.Encrypted)
|
||||||
{
|
{
|
||||||
_downloadAssetBundleOp = new DownloadWebEncryptAssetBundleOperation(true, _fileSystem.DecryptionServices, _bundle, options);
|
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices);
|
||||||
_downloadAssetBundleOp.StartOperation();
|
_loadWebAssetBundleOp.StartOperation();
|
||||||
AddChildOperation(_downloadAssetBundleOp);
|
AddChildOperation(_loadWebAssetBundleOp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_downloadAssetBundleOp = new DownloadWebNormalAssetBundleOperation(_fileSystem.DisableUnityWebCache, _bundle, options);
|
_loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(_bundle, options, _fileSystem.DisableUnityWebCache);
|
||||||
_downloadAssetBundleOp.StartOperation();
|
_loadWebAssetBundleOp.StartOperation();
|
||||||
AddChildOperation(_downloadAssetBundleOp);
|
AddChildOperation(_loadWebAssetBundleOp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_downloadAssetBundleOp.UpdateOperation();
|
_loadWebAssetBundleOp.UpdateOperation();
|
||||||
DownloadProgress = _downloadAssetBundleOp.DownloadProgress;
|
DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
|
||||||
DownloadedBytes = _downloadAssetBundleOp.DownloadedBytes;
|
DownloadedBytes = _loadWebAssetBundleOp.DownloadedBytes;
|
||||||
Progress = _downloadAssetBundleOp.Progress;
|
Progress = _loadWebAssetBundleOp.Progress;
|
||||||
if (_downloadAssetBundleOp.IsDone == false)
|
if (_loadWebAssetBundleOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_downloadAssetBundleOp.Status == EOperationStatus.Succeed)
|
if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
var assetBundle = _downloadAssetBundleOp.Result;
|
var assetBundle = _loadWebAssetBundleOp.Result;
|
||||||
if (assetBundle == null)
|
if (assetBundle == null)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = $"{nameof(DownloadAssetBundleOperation)} loaded asset bundle is null !";
|
Error = $"{nameof(DWSFSLoadAssetBundleOperation)} loaded asset bundle is null !";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -80,7 +80,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _downloadAssetBundleOp.Error;
|
Error = _loadWebAssetBundleOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ namespace YooAsset
|
|||||||
if (_loadWebPackageManifestOp == null)
|
if (_loadWebPackageManifestOp == null)
|
||||||
{
|
{
|
||||||
string packageHash = _requestWebPackageHashOp.PackageHash;
|
string packageHash = _requestWebPackageHashOp.PackageHash;
|
||||||
_loadWebPackageManifestOp = new LoadWebServerPackageManifestOperation(_fileSystem, _packageVersion, packageHash);
|
_loadWebPackageManifestOp = new LoadWebServerPackageManifestOperation(_fileSystem, _packageVersion, packageHash, _timeout);
|
||||||
_loadWebPackageManifestOp.StartOperation();
|
_loadWebPackageManifestOp.StartOperation();
|
||||||
AddChildOperation(_loadWebPackageManifestOp);
|
AddChildOperation(_loadWebPackageManifestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
@@ -16,12 +13,14 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly DefaultWebServerFileSystem _fileSystem;
|
private readonly DefaultWebServerFileSystem _fileSystem;
|
||||||
|
private readonly int _timeout;
|
||||||
private UnityWebDataRequestOperation _webDataRequestOp;
|
private UnityWebDataRequestOperation _webDataRequestOp;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal LoadWebServerCatalogFileOperation(DefaultWebServerFileSystem fileSystem)
|
internal LoadWebServerCatalogFileOperation(DefaultWebServerFileSystem fileSystem, int timeout)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
|
_timeout = timeout;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
@@ -38,7 +37,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
string filePath = _fileSystem.GetCatalogBinaryFileLoadPath();
|
string filePath = _fileSystem.GetCatalogBinaryFileLoadPath();
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||||
_webDataRequestOp = new UnityWebDataRequestOperation(url);
|
_webDataRequestOp = new UnityWebDataRequestOperation(url, _timeout);
|
||||||
_webDataRequestOp.StartOperation();
|
_webDataRequestOp.StartOperation();
|
||||||
AddChildOperation(_webDataRequestOp);
|
AddChildOperation(_webDataRequestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace YooAsset
|
|||||||
private readonly DefaultWebServerFileSystem _fileSystem;
|
private readonly DefaultWebServerFileSystem _fileSystem;
|
||||||
private readonly string _packageVersion;
|
private readonly string _packageVersion;
|
||||||
private readonly string _packageHash;
|
private readonly string _packageHash;
|
||||||
|
private readonly int _timeout;
|
||||||
private UnityWebDataRequestOperation _webDataRequestOp;
|
private UnityWebDataRequestOperation _webDataRequestOp;
|
||||||
private DeserializeManifestOperation _deserializer;
|
private DeserializeManifestOperation _deserializer;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
@@ -25,11 +26,12 @@ namespace YooAsset
|
|||||||
public PackageManifest Manifest { private set; get; }
|
public PackageManifest Manifest { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
internal LoadWebServerPackageManifestOperation(DefaultWebServerFileSystem fileSystem, string packageVersion, string packageHash)
|
internal LoadWebServerPackageManifestOperation(DefaultWebServerFileSystem fileSystem, string packageVersion, string packageHash, int timeout)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_packageVersion = packageVersion;
|
_packageVersion = packageVersion;
|
||||||
_packageHash = packageHash;
|
_packageHash = packageHash;
|
||||||
|
_timeout = timeout;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
@@ -46,7 +48,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
string filePath = _fileSystem.GetWebPackageManifestFilePath(_packageVersion);
|
string filePath = _fileSystem.GetWebPackageManifestFilePath(_packageVersion);
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||||
_webDataRequestOp = new UnityWebDataRequestOperation(url);
|
_webDataRequestOp = new UnityWebDataRequestOperation(url, _timeout);
|
||||||
_webDataRequestOp.StartOperation();
|
_webDataRequestOp.StartOperation();
|
||||||
AddChildOperation(_webDataRequestOp);
|
AddChildOperation(_webDataRequestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,30 +8,44 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly int FailedTryAgain;
|
public readonly int FailedTryAgain;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 超时时间
|
|
||||||
/// </summary>
|
|
||||||
public readonly int Timeout;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 主资源地址
|
/// 主资源地址
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string MainURL { set; get; }
|
public string MainURL { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 备用资源地址
|
/// 备用资源地址
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string FallbackURL { set; get; }
|
public string FallbackURL { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 拷贝的本地文件路径
|
/// 拷贝的本地文件路径
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ImportFilePath { set; get; }
|
public string ImportFilePath { set; get; }
|
||||||
|
|
||||||
public DownloadFileOptions(int failedTryAgain, int timeout)
|
public DownloadFileOptions(int failedTryAgain)
|
||||||
{
|
{
|
||||||
FailedTryAgain = failedTryAgain;
|
FailedTryAgain = failedTryAgain;
|
||||||
Timeout = timeout;
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置下载地址
|
||||||
|
/// </summary>
|
||||||
|
public void SetURL(string mainURL, string fallbackURL)
|
||||||
|
{
|
||||||
|
MainURL = mainURL;
|
||||||
|
FallbackURL = fallbackURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否有效
|
||||||
|
/// </summary>
|
||||||
|
public bool IsValid()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(MainURL) || string.IsNullOrEmpty(FallbackURL))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,16 +53,6 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
public PackageBundle Bundle { private set; get; }
|
public PackageBundle Bundle { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 引用计数
|
|
||||||
/// </summary>
|
|
||||||
public int RefCount { private set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// HTTP返回码
|
|
||||||
/// </summary>
|
|
||||||
public long HttpCode { protected set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前下载的字节数
|
/// 当前下载的字节数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -63,31 +67,8 @@ namespace YooAsset
|
|||||||
public FSDownloadFileOperation(PackageBundle bundle)
|
public FSDownloadFileOperation(PackageBundle bundle)
|
||||||
{
|
{
|
||||||
Bundle = bundle;
|
Bundle = bundle;
|
||||||
RefCount = 0;
|
|
||||||
HttpCode = 0;
|
|
||||||
DownloadedBytes = 0;
|
DownloadedBytes = 0;
|
||||||
DownloadProgress = 0;
|
DownloadProgress = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override string InternalGetDesc()
|
|
||||||
{
|
|
||||||
return $"RefCount : {RefCount}";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 减少引用计数
|
|
||||||
/// </summary>
|
|
||||||
public virtual void Release()
|
|
||||||
{
|
|
||||||
RefCount--;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 增加引用计数
|
|
||||||
/// </summary>
|
|
||||||
public virtual void Reference()
|
|
||||||
{
|
|
||||||
RefCount++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,131 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Networking;
|
|
||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
internal abstract class DefaultDownloadFileOperation : FSDownloadFileOperation
|
|
||||||
{
|
|
||||||
protected enum ESteps
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
CheckExists,
|
|
||||||
CreateRequest,
|
|
||||||
CheckRequest,
|
|
||||||
CopyBuildinBundle,
|
|
||||||
VerifyTempFile,
|
|
||||||
CheckVerifyTempFile,
|
|
||||||
TryAgain,
|
|
||||||
Done,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 下载参数
|
|
||||||
protected readonly DownloadFileOptions Options;
|
|
||||||
|
|
||||||
// 请求相关
|
|
||||||
protected UnityWebRequest _webRequest;
|
|
||||||
protected string _requestURL;
|
|
||||||
protected int _requestCount = 0;
|
|
||||||
|
|
||||||
// 超时相关
|
|
||||||
protected bool _isAbort = false;
|
|
||||||
protected long _latestDownloadBytes;
|
|
||||||
protected float _latestDownloadRealtime;
|
|
||||||
protected float _tryAgainTimer;
|
|
||||||
|
|
||||||
// 失败相关
|
|
||||||
protected int FailedTryAgain;
|
|
||||||
|
|
||||||
|
|
||||||
internal DefaultDownloadFileOperation(PackageBundle bundle, DownloadFileOptions options) : base(bundle)
|
|
||||||
{
|
|
||||||
Options = options;
|
|
||||||
FailedTryAgain = options.FailedTryAgain;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取网络请求地址
|
|
||||||
/// </summary>
|
|
||||||
protected string GetRequestURL()
|
|
||||||
{
|
|
||||||
// 轮流返回请求地址
|
|
||||||
_requestCount++;
|
|
||||||
if (_requestCount % 2 == 0)
|
|
||||||
return Options.FallbackURL;
|
|
||||||
else
|
|
||||||
return Options.MainURL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 重置请求字段
|
|
||||||
/// </summary>
|
|
||||||
protected void ResetRequestFiled()
|
|
||||||
{
|
|
||||||
// 重置变量
|
|
||||||
_isAbort = false;
|
|
||||||
_latestDownloadBytes = 0;
|
|
||||||
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
|
||||||
DownloadProgress = 0f;
|
|
||||||
DownloadedBytes = 0;
|
|
||||||
|
|
||||||
// 重置计时器
|
|
||||||
if (_tryAgainTimer > 0f)
|
|
||||||
YooLogger.Warning($"Try again download : {_requestURL}");
|
|
||||||
_tryAgainTimer = 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 检测请求超时
|
|
||||||
/// </summary>
|
|
||||||
protected void CheckRequestTimeout()
|
|
||||||
{
|
|
||||||
// 注意:在连续时间段内无新增下载数据及判定为超时
|
|
||||||
if (_isAbort == false)
|
|
||||||
{
|
|
||||||
if (_latestDownloadBytes != DownloadedBytes)
|
|
||||||
{
|
|
||||||
_latestDownloadBytes = DownloadedBytes;
|
|
||||||
_latestDownloadRealtime = UnityEngine.Time.realtimeSinceStartup;
|
|
||||||
}
|
|
||||||
|
|
||||||
float offset = UnityEngine.Time.realtimeSinceStartup - _latestDownloadRealtime;
|
|
||||||
if (offset > Options.Timeout)
|
|
||||||
{
|
|
||||||
YooLogger.Warning($"Download request timeout : {_requestURL}");
|
|
||||||
if (_webRequest != null)
|
|
||||||
_webRequest.Abort();
|
|
||||||
_isAbort = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 检测请求结果
|
|
||||||
/// </summary>
|
|
||||||
protected bool CheckRequestResult()
|
|
||||||
{
|
|
||||||
HttpCode = _webRequest.responseCode;
|
|
||||||
|
|
||||||
#if UNITY_2020_3_OR_NEWER
|
|
||||||
if (_webRequest.result != UnityWebRequest.Result.Success)
|
|
||||||
{
|
|
||||||
Error = _webRequest.error;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (_webRequest.isNetworkError || _webRequest.isHttpError)
|
|
||||||
{
|
|
||||||
Error = _webRequest.error;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
internal abstract class DownloadAssetBundleOperation : DefaultDownloadFileOperation
|
|
||||||
{
|
|
||||||
internal DownloadAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public AssetBundle Result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
internal class DownloadFileWrapper : FSDownloadFileOperation
|
|
||||||
{
|
|
||||||
private enum ESteps
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
Download,
|
|
||||||
Done,
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly FSDownloadFileOperation _downloadFileOp;
|
|
||||||
private ESteps _steps = ESteps.None;
|
|
||||||
|
|
||||||
internal DownloadFileWrapper(FSDownloadFileOperation downloadFileOp) : base(downloadFileOp.Bundle)
|
|
||||||
{
|
|
||||||
_downloadFileOp = downloadFileOp;
|
|
||||||
}
|
|
||||||
internal override void InternalStart()
|
|
||||||
{
|
|
||||||
_steps = ESteps.Download;
|
|
||||||
}
|
|
||||||
internal override void InternalUpdate()
|
|
||||||
{
|
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_steps == ESteps.Download)
|
|
||||||
{
|
|
||||||
if (IsWaitForAsyncComplete)
|
|
||||||
_downloadFileOp.WaitForAsyncComplete();
|
|
||||||
|
|
||||||
if (_downloadFileOp.Status == EOperationStatus.None)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_downloadFileOp.UpdateOperation();
|
|
||||||
Progress = _downloadFileOp.Progress;
|
|
||||||
DownloadedBytes = _downloadFileOp.DownloadedBytes;
|
|
||||||
DownloadProgress = _downloadFileOp.DownloadProgress;
|
|
||||||
if (_downloadFileOp.IsDone == false)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = _downloadFileOp.Status;
|
|
||||||
Error = _downloadFileOp.Error;
|
|
||||||
HttpCode = _downloadFileOp.HttpCode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
internal override void InternalWaitForAsyncComplete()
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (ExecuteWhileDone())
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Release()
|
|
||||||
{
|
|
||||||
_downloadFileOp.Release();
|
|
||||||
}
|
|
||||||
public override void Reference()
|
|
||||||
{
|
|
||||||
_downloadFileOp.Reference();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,157 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Networking;
|
|
||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
internal class DownloadWebEncryptAssetBundleOperation : DownloadAssetBundleOperation
|
|
||||||
{
|
|
||||||
private readonly bool _checkTimeout;
|
|
||||||
private readonly IWebDecryptionServices _decryptionServices;
|
|
||||||
private DownloadHandlerBuffer _downloadhandler;
|
|
||||||
private ESteps _steps = ESteps.None;
|
|
||||||
|
|
||||||
internal DownloadWebEncryptAssetBundleOperation(bool checkTimeout, IWebDecryptionServices decryptionServices, PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
|
|
||||||
{
|
|
||||||
_checkTimeout = checkTimeout;
|
|
||||||
_decryptionServices = decryptionServices;
|
|
||||||
}
|
|
||||||
internal override void InternalStart()
|
|
||||||
{
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
}
|
|
||||||
internal override void InternalUpdate()
|
|
||||||
{
|
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
if (_steps == ESteps.CreateRequest)
|
|
||||||
{
|
|
||||||
// 获取请求地址
|
|
||||||
_requestURL = GetRequestURL();
|
|
||||||
|
|
||||||
// 重置变量
|
|
||||||
ResetRequestFiled();
|
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
CreateWebRequest();
|
|
||||||
|
|
||||||
_steps = ESteps.CheckRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检测下载结果
|
|
||||||
if (_steps == ESteps.CheckRequest)
|
|
||||||
{
|
|
||||||
DownloadProgress = _webRequest.downloadProgress;
|
|
||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
|
||||||
Progress = DownloadProgress;
|
|
||||||
if (_webRequest.isDone == false)
|
|
||||||
{
|
|
||||||
if (_checkTimeout)
|
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查网络错误
|
|
||||||
if (CheckRequestResult())
|
|
||||||
{
|
|
||||||
if (_decryptionServices == null)
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = $"The {nameof(IWebDecryptionServices)} is null !";
|
|
||||||
YooLogger.Error(Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var fileData = _downloadhandler.data;
|
|
||||||
if (fileData == null || fileData.Length == 0)
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = $"The download handler data is null or empty !";
|
|
||||||
YooLogger.Error(Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AssetBundle assetBundle = LoadEncryptedAssetBundle(fileData);
|
|
||||||
if (assetBundle == null)
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = "Download handler asset bundle object is null !";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Result = assetBundle;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.TryAgain;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 注意:最终释放请求器
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 重新尝试下载
|
|
||||||
if (_steps == ESteps.TryAgain)
|
|
||||||
{
|
|
||||||
if (FailedTryAgain <= 0)
|
|
||||||
{
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
YooLogger.Error(Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_tryAgainTimer += Time.unscaledDeltaTime;
|
|
||||||
if (_tryAgainTimer > 1f)
|
|
||||||
{
|
|
||||||
FailedTryAgain--;
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
YooLogger.Warning(Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
internal override void InternalAbort()
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateWebRequest()
|
|
||||||
{
|
|
||||||
_downloadhandler = new DownloadHandlerBuffer();
|
|
||||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
|
||||||
_webRequest.downloadHandler = _downloadhandler;
|
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
|
||||||
_webRequest.SendWebRequest();
|
|
||||||
}
|
|
||||||
private void DisposeWebRequest()
|
|
||||||
{
|
|
||||||
if (_webRequest != null)
|
|
||||||
{
|
|
||||||
//注意:引擎底层会自动调用Abort方法
|
|
||||||
_webRequest.Dispose();
|
|
||||||
_webRequest = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 加载加密资源文件
|
|
||||||
/// </summary>
|
|
||||||
private AssetBundle LoadEncryptedAssetBundle(byte[] fileData)
|
|
||||||
{
|
|
||||||
var fileInfo = new WebDecryptFileInfo();
|
|
||||||
fileInfo.BundleName = Bundle.BundleName;
|
|
||||||
fileInfo.FileLoadCRC = Bundle.UnityCRC;
|
|
||||||
fileInfo.FileData = fileData;
|
|
||||||
var decryptResult = _decryptionServices.LoadAssetBundle(fileInfo);
|
|
||||||
return decryptResult.Result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal abstract class LoadWebAssetBundleOperation : AsyncOperationBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// AssetBundle对象
|
||||||
|
/// </summary>
|
||||||
|
public AssetBundle Result;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 下载进度
|
||||||
|
/// </summary>
|
||||||
|
public float DownloadProgress { protected set; get; } = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 下载大小
|
||||||
|
/// </summary>
|
||||||
|
public long DownloadedBytes { protected set; get; } = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class LoadWebEncryptAssetBundleOperation : LoadWebAssetBundleOperation
|
||||||
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
CheckRequest,
|
||||||
|
TryAgain,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly PackageBundle _bundle;
|
||||||
|
private readonly DownloadFileOptions _options;
|
||||||
|
private readonly IWebDecryptionServices _decryptionServices;
|
||||||
|
private UnityWebDataRequestOperation _unityWebDataRequestOp;
|
||||||
|
|
||||||
|
protected int _requestCount = 0;
|
||||||
|
protected float _tryAgainTimer;
|
||||||
|
protected int _failedTryAgain;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
internal LoadWebEncryptAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options, IWebDecryptionServices decryptionServices)
|
||||||
|
{
|
||||||
|
_bundle = bundle;
|
||||||
|
_options = options;
|
||||||
|
_decryptionServices = decryptionServices;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 创建下载器
|
||||||
|
if (_steps == ESteps.CreateRequest)
|
||||||
|
{
|
||||||
|
if (_decryptionServices == null)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"The {nameof(IWebDecryptionServices)} is null !";
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string url = GetRequestURL();
|
||||||
|
_unityWebDataRequestOp = new UnityWebDataRequestOperation(url, 0);
|
||||||
|
_unityWebDataRequestOp.StartOperation();
|
||||||
|
AddChildOperation(_unityWebDataRequestOp);
|
||||||
|
_steps = ESteps.CheckRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测下载结果
|
||||||
|
if (_steps == ESteps.CheckRequest)
|
||||||
|
{
|
||||||
|
_unityWebDataRequestOp.UpdateOperation();
|
||||||
|
Progress = _unityWebDataRequestOp.Progress;
|
||||||
|
DownloadProgress = _unityWebDataRequestOp.DownloadProgress;
|
||||||
|
DownloadedBytes = _unityWebDataRequestOp.DownloadedBytes;
|
||||||
|
if (_unityWebDataRequestOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 检查网络错误
|
||||||
|
if (_unityWebDataRequestOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
AssetBundle assetBundle = LoadEncryptedAssetBundle(_unityWebDataRequestOp.Result);
|
||||||
|
if (assetBundle == null)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = "Failed load encrypted AssetBundle !";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
Result = assetBundle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_failedTryAgain > 0)
|
||||||
|
{
|
||||||
|
_steps = ESteps.TryAgain;
|
||||||
|
YooLogger.Warning($"Failed download : {_unityWebDataRequestOp.URL} Try again !");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _unityWebDataRequestOp.Error;
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重新尝试下载
|
||||||
|
if (_steps == ESteps.TryAgain)
|
||||||
|
{
|
||||||
|
_tryAgainTimer += Time.unscaledDeltaTime;
|
||||||
|
if (_tryAgainTimer > 1f)
|
||||||
|
{
|
||||||
|
_tryAgainTimer = 0f;
|
||||||
|
_failedTryAgain--;
|
||||||
|
Progress = 0f;
|
||||||
|
DownloadProgress = 0f;
|
||||||
|
DownloadedBytes = 0;
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载加密资源文件
|
||||||
|
/// </summary>
|
||||||
|
private AssetBundle LoadEncryptedAssetBundle(byte[] fileData)
|
||||||
|
{
|
||||||
|
var fileInfo = new WebDecryptFileInfo();
|
||||||
|
fileInfo.BundleName = _bundle.BundleName;
|
||||||
|
fileInfo.FileLoadCRC = _bundle.UnityCRC;
|
||||||
|
fileInfo.FileData = fileData;
|
||||||
|
var decryptResult = _decryptionServices.LoadAssetBundle(fileInfo);
|
||||||
|
return decryptResult.Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取网络请求地址
|
||||||
|
/// </summary>
|
||||||
|
protected string GetRequestURL()
|
||||||
|
{
|
||||||
|
// 轮流返回请求地址
|
||||||
|
_requestCount++;
|
||||||
|
if (_requestCount % 2 == 0)
|
||||||
|
return _options.FallbackURL;
|
||||||
|
else
|
||||||
|
return _options.MainURL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class LoadWebNormalAssetBundleOperation : LoadWebAssetBundleOperation
|
||||||
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
CheckRequest,
|
||||||
|
TryAgain,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly PackageBundle _bundle;
|
||||||
|
private readonly DownloadFileOptions _options;
|
||||||
|
private readonly bool _disableUnityWebCache;
|
||||||
|
private UnityAssetBundleRequestOperation _unityAssetBundleRequestOp;
|
||||||
|
|
||||||
|
protected int _requestCount = 0;
|
||||||
|
protected float _tryAgainTimer;
|
||||||
|
protected int _failedTryAgain;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
|
internal LoadWebNormalAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options, bool disableUnityWebCache)
|
||||||
|
{
|
||||||
|
_bundle = bundle;
|
||||||
|
_options = options;
|
||||||
|
_disableUnityWebCache = disableUnityWebCache;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 创建下载器
|
||||||
|
if (_steps == ESteps.CreateRequest)
|
||||||
|
{
|
||||||
|
string url = GetRequestURL();
|
||||||
|
_unityAssetBundleRequestOp = new UnityAssetBundleRequestOperation(_bundle, _disableUnityWebCache, url);
|
||||||
|
_unityAssetBundleRequestOp.StartOperation();
|
||||||
|
AddChildOperation(_unityAssetBundleRequestOp);
|
||||||
|
_steps = ESteps.CheckRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测下载结果
|
||||||
|
if (_steps == ESteps.CheckRequest)
|
||||||
|
{
|
||||||
|
_unityAssetBundleRequestOp.UpdateOperation();
|
||||||
|
Progress = _unityAssetBundleRequestOp.Progress;
|
||||||
|
DownloadedBytes = _unityAssetBundleRequestOp.DownloadedBytes;
|
||||||
|
DownloadProgress = _unityAssetBundleRequestOp.DownloadProgress;
|
||||||
|
if (_unityAssetBundleRequestOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_unityAssetBundleRequestOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
Result = _unityAssetBundleRequestOp.Result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_failedTryAgain > 0)
|
||||||
|
{
|
||||||
|
_steps = ESteps.TryAgain;
|
||||||
|
YooLogger.Warning($"Failed download : {_unityAssetBundleRequestOp.URL} Try again !");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _unityAssetBundleRequestOp.Error;
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重新尝试下载
|
||||||
|
if (_steps == ESteps.TryAgain)
|
||||||
|
{
|
||||||
|
_tryAgainTimer += Time.unscaledDeltaTime;
|
||||||
|
if (_tryAgainTimer > 1f)
|
||||||
|
{
|
||||||
|
_tryAgainTimer = 0f;
|
||||||
|
_failedTryAgain--;
|
||||||
|
Progress = 0f;
|
||||||
|
DownloadProgress = 0f;
|
||||||
|
DownloadedBytes = 0;
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取网络请求地址
|
||||||
|
/// </summary>
|
||||||
|
protected string GetRequestURL()
|
||||||
|
{
|
||||||
|
// 轮流返回请求地址
|
||||||
|
_requestCount++;
|
||||||
|
if (_requestCount % 2 == 0)
|
||||||
|
return _options.FallbackURL;
|
||||||
|
else
|
||||||
|
return _options.MainURL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ using System.Reflection;
|
|||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
public static class PakcageInvokeBuilder
|
public static class PackageInvokeBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 调用Editro类来执行构建资源包任务
|
/// 调用Editro类来执行构建资源包任务
|
||||||
@@ -32,7 +32,7 @@ namespace YooAsset
|
|||||||
#else
|
#else
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
public static class PakcageInvokeBuilder
|
public static class PackageInvokeBuilder
|
||||||
{
|
{
|
||||||
public static PackageInvokeBuildResult InvokeBuilder(PackageInvokeBuildParam buildParam)
|
public static PackageInvokeBuildResult InvokeBuilder(PackageInvokeBuildParam buildParam)
|
||||||
{
|
{
|
||||||
@@ -60,7 +60,7 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 尝试卸载指定资源的资源包(包括依赖资源)
|
/// 尝试卸载指定资源的资源包(包括依赖资源)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void TryUnloadUnusedAsset(AssetInfo assetInfo)
|
public void TryUnloadUnusedAsset(AssetInfo assetInfo, int loopCount)
|
||||||
{
|
{
|
||||||
if (assetInfo.IsInvalid)
|
if (assetInfo.IsInvalid)
|
||||||
{
|
{
|
||||||
@@ -68,6 +68,10 @@ namespace YooAsset
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (loopCount > 0)
|
||||||
|
{
|
||||||
|
loopCount--;
|
||||||
|
|
||||||
// 卸载主资源包加载器
|
// 卸载主资源包加载器
|
||||||
string mainBundleName = _bundleQuery.GetMainBundleName(assetInfo);
|
string mainBundleName = _bundleQuery.GetMainBundleName(assetInfo);
|
||||||
var mainLoader = TryGetBundleFileLoader(mainBundleName);
|
var mainLoader = TryGetBundleFileLoader(mainBundleName);
|
||||||
@@ -98,6 +102,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载场景对象
|
/// 加载场景对象
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建下载器
|
/// 创建下载器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FSDownloadFileOperation CreateDownloader(int failedTryAgain, int timeout)
|
public FSDownloadFileOperation CreateDownloader(int failedTryAgain)
|
||||||
{
|
{
|
||||||
DownloadFileOptions options = new DownloadFileOptions(failedTryAgain, timeout);
|
DownloadFileOptions options = new DownloadFileOptions(failedTryAgain);
|
||||||
options.ImportFilePath = _importFilePath;
|
options.ImportFilePath = _importFilePath;
|
||||||
return _fileSystem.DownloadFileAsync(Bundle, options);
|
return _fileSystem.DownloadFileAsync(Bundle, options);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,15 +34,16 @@ namespace YooAsset
|
|||||||
ClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options);
|
ClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options);
|
||||||
|
|
||||||
// 下载相关
|
// 下载相关
|
||||||
ResourceDownloaderOperation CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout);
|
ResourceDownloaderOperation CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain);
|
||||||
ResourceDownloaderOperation CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout);
|
ResourceDownloaderOperation CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain);
|
||||||
ResourceDownloaderOperation CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout);
|
ResourceDownloaderOperation CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain);
|
||||||
|
|
||||||
// 解压相关
|
// 解压相关
|
||||||
ResourceUnpackerOperation CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout);
|
ResourceUnpackerOperation CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain);
|
||||||
ResourceUnpackerOperation CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout);
|
ResourceUnpackerOperation CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain);
|
||||||
|
|
||||||
// 导入相关
|
// 导入相关
|
||||||
ResourceImporterOperation CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout);
|
ResourceImporterOperation CreateResourceImporterByFilePaths(string[] filePaths, int importingMaxNumber, int failedTryAgain);
|
||||||
|
ResourceImporterOperation CreateResourceImporterByFileInfos(ImportFileInfo[] fileInfos, int importingMaxNumber, int failedTryAgain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,6 @@ namespace YooAsset
|
|||||||
private readonly string _packageName;
|
private readonly string _packageName;
|
||||||
private readonly int _downloadingMaxNumber;
|
private readonly int _downloadingMaxNumber;
|
||||||
private readonly int _failedTryAgain;
|
private readonly int _failedTryAgain;
|
||||||
private readonly int _timeout;
|
|
||||||
private readonly List<BundleInfo> _bundleInfoList;
|
private readonly List<BundleInfo> _bundleInfoList;
|
||||||
private readonly List<FSDownloadFileOperation> _downloaders = new List<FSDownloadFileOperation>(MAX_LOADER_COUNT);
|
private readonly List<FSDownloadFileOperation> _downloaders = new List<FSDownloadFileOperation>(MAX_LOADER_COUNT);
|
||||||
private readonly List<FSDownloadFileOperation> _removeList = new List<FSDownloadFileOperation>(MAX_LOADER_COUNT);
|
private readonly List<FSDownloadFileOperation> _removeList = new List<FSDownloadFileOperation>(MAX_LOADER_COUNT);
|
||||||
@@ -102,13 +101,12 @@ namespace YooAsset
|
|||||||
public DownloadFileBegin DownloadFileBeginCallback { set; get; }
|
public DownloadFileBegin DownloadFileBeginCallback { set; get; }
|
||||||
|
|
||||||
|
|
||||||
internal DownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
internal DownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
_packageName = packageName;
|
_packageName = packageName;
|
||||||
_bundleInfoList = downloadList;
|
_bundleInfoList = downloadList;
|
||||||
_downloadingMaxNumber = UnityEngine.Mathf.Clamp(downloadingMaxNumber, 1, MAX_LOADER_COUNT); ;
|
_downloadingMaxNumber = UnityEngine.Mathf.Clamp(downloadingMaxNumber, 1, MAX_LOADER_COUNT); ;
|
||||||
_failedTryAgain = failedTryAgain;
|
_failedTryAgain = failedTryAgain;
|
||||||
_timeout = timeout;
|
|
||||||
|
|
||||||
// 设置包裹名称 (fix #210)
|
// 设置包裹名称 (fix #210)
|
||||||
SetPackageName(packageName);
|
SetPackageName(packageName);
|
||||||
@@ -203,7 +201,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
int index = _bundleInfoList.Count - 1;
|
int index = _bundleInfoList.Count - 1;
|
||||||
var bundleInfo = _bundleInfoList[index];
|
var bundleInfo = _bundleInfoList[index];
|
||||||
var downloader = bundleInfo.CreateDownloader(_failedTryAgain, _timeout);
|
var downloader = bundleInfo.CreateDownloader(_failedTryAgain);
|
||||||
downloader.StartOperation();
|
downloader.StartOperation();
|
||||||
this.AddChildOperation(downloader);
|
this.AddChildOperation(downloader);
|
||||||
|
|
||||||
@@ -366,7 +364,7 @@ namespace YooAsset
|
|||||||
|
|
||||||
foreach (var downloader in _downloaders)
|
foreach (var downloader in _downloaders)
|
||||||
{
|
{
|
||||||
downloader.Release();
|
downloader.AbortOperation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -374,52 +372,52 @@ namespace YooAsset
|
|||||||
|
|
||||||
public sealed class ResourceDownloaderOperation : DownloaderOperation
|
public sealed class ResourceDownloaderOperation : DownloaderOperation
|
||||||
{
|
{
|
||||||
internal ResourceDownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
internal ResourceDownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
|
||||||
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建空的下载器
|
/// 创建空的下载器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static ResourceDownloaderOperation CreateEmptyDownloader(string packageName, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
internal static ResourceDownloaderOperation CreateEmptyDownloader(string packageName, int downloadingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||||
var operation = new ResourceDownloaderOperation(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(packageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public sealed class ResourceUnpackerOperation : DownloaderOperation
|
public sealed class ResourceUnpackerOperation : DownloaderOperation
|
||||||
{
|
{
|
||||||
internal ResourceUnpackerOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
internal ResourceUnpackerOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
|
||||||
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建空的解压器
|
/// 创建空的解压器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static ResourceUnpackerOperation CreateEmptyUnpacker(string packageName, int upackingMaxNumber, int failedTryAgain, int timeout)
|
internal static ResourceUnpackerOperation CreateEmptyUnpacker(string packageName, int upackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||||
var operation = new ResourceUnpackerOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue);
|
var operation = new ResourceUnpackerOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public sealed class ResourceImporterOperation : DownloaderOperation
|
public sealed class ResourceImporterOperation : DownloaderOperation
|
||||||
{
|
{
|
||||||
internal ResourceImporterOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
internal ResourceImporterOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
|
||||||
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建空的导入器
|
/// 创建空的导入器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static ResourceImporterOperation CreateEmptyImporter(string packageName, int upackingMaxNumber, int failedTryAgain, int timeout)
|
internal static ResourceImporterOperation CreateEmptyImporter(string packageName, int upackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||||
var operation = new ResourceImporterOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue);
|
var operation = new ResourceImporterOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,11 +107,11 @@ namespace YooAsset
|
|||||||
if (Status != EOperationStatus.Succeed)
|
if (Status != EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BundleInfo> downloadList = _impl.GetDownloadListByAll(_manifest);
|
List<BundleInfo> downloadList = _impl.GetDownloadListByAll(_manifest);
|
||||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,11 +127,11 @@ namespace YooAsset
|
|||||||
if (Status != EOperationStatus.Succeed)
|
if (Status != EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, new string[] { tag });
|
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, new string[] { tag });
|
||||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,11 +147,11 @@ namespace YooAsset
|
|||||||
if (Status != EOperationStatus.Succeed)
|
if (Status != EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, tags);
|
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, tags);
|
||||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ namespace YooAsset
|
|||||||
if (Status != EOperationStatus.Succeed)
|
if (Status != EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<AssetInfo> assetInfos = new List<AssetInfo>();
|
List<AssetInfo> assetInfos = new List<AssetInfo>();
|
||||||
@@ -175,7 +175,7 @@ namespace YooAsset
|
|||||||
assetInfos.Add(assetInfo);
|
assetInfos.Add(assetInfo);
|
||||||
|
|
||||||
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload);
|
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload);
|
||||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ namespace YooAsset
|
|||||||
if (Status != EOperationStatus.Succeed)
|
if (Status != EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
|
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
|
||||||
@@ -202,7 +202,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload);
|
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload);
|
||||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace YooAsset
|
|||||||
buildParam.InvokeAssmeblyName = "YooAsset.Editor";
|
buildParam.InvokeAssmeblyName = "YooAsset.Editor";
|
||||||
buildParam.InvokeClassFullName = "YooAsset.Editor.AssetBundleSimulateBuilder";
|
buildParam.InvokeClassFullName = "YooAsset.Editor.AssetBundleSimulateBuilder";
|
||||||
buildParam.InvokeMethodName = "SimulateBuild";
|
buildParam.InvokeMethodName = "SimulateBuild";
|
||||||
return PakcageInvokeBuilder.InvokeBuilder(buildParam);
|
return PackageInvokeBuilder.InvokeBuilder(buildParam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,44 +104,50 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 下载相关
|
// 下载相关
|
||||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList = GetDownloadListByAll(ActiveManifest);
|
List<BundleInfo> downloadList = GetDownloadListByAll(ActiveManifest);
|
||||||
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList = GetDownloadListByTags(ActiveManifest, tags);
|
List<BundleInfo> downloadList = GetDownloadListByTags(ActiveManifest, tags);
|
||||||
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList = GetDownloadListByPaths(ActiveManifest, assetInfos, recursiveDownload);
|
List<BundleInfo> downloadList = GetDownloadListByPaths(ActiveManifest, assetInfos, recursiveDownload);
|
||||||
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解压相关
|
// 解压相关
|
||||||
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
|
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> unpcakList = GetUnpackListByAll(ActiveManifest);
|
List<BundleInfo> unpcakList = GetUnpackListByAll(ActiveManifest);
|
||||||
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
|
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> unpcakList = GetUnpackListByTags(ActiveManifest, tags);
|
List<BundleInfo> unpcakList = GetUnpackListByTags(ActiveManifest, tags);
|
||||||
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导入相关
|
// 导入相关
|
||||||
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
|
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> importerList = GetImporterListByFilePaths(ActiveManifest, filePaths);
|
List<BundleInfo> importerList = GetImporterListByFilePaths(ActiveManifest, filePaths);
|
||||||
var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceImporterOperation(PackageName, importerList, importingMaxNumber, failedTryAgain);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
ResourceImporterOperation IPlayMode.CreateResourceImporterByFileInfos(ImportFileInfo[] fileInfos, int importingMaxNumber, int failedTryAgain)
|
||||||
|
{
|
||||||
|
List<BundleInfo> importerList = GetImporterListByFileInfos(ActiveManifest, fileInfos);
|
||||||
|
var operation = new ResourceImporterOperation(PackageName, importerList, importingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@@ -415,15 +421,60 @@ namespace YooAsset
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
public List<BundleInfo> GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths)
|
public List<BundleInfo> GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths)
|
||||||
|
{
|
||||||
|
if (manifest == null)
|
||||||
|
return new List<BundleInfo>();
|
||||||
|
|
||||||
|
ImportFileInfo[] fileInfos = new ImportFileInfo[filePaths.Length];
|
||||||
|
for (int i = 0; i < filePaths.Length; i++)
|
||||||
|
{
|
||||||
|
ImportFileInfo fileInfo = new ImportFileInfo();
|
||||||
|
fileInfo.FilePath = filePaths[i];
|
||||||
|
fileInfos[i] = fileInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GetImporterListByFileInfos(manifest, fileInfos);
|
||||||
|
}
|
||||||
|
public List<BundleInfo> GetImporterListByFileInfos(PackageManifest manifest, ImportFileInfo[] fileInfos)
|
||||||
{
|
{
|
||||||
if (manifest == null)
|
if (manifest == null)
|
||||||
return new List<BundleInfo>();
|
return new List<BundleInfo>();
|
||||||
|
|
||||||
List<BundleInfo> result = new List<BundleInfo>();
|
List<BundleInfo> result = new List<BundleInfo>();
|
||||||
foreach (var filePath in filePaths)
|
foreach (var fileInfo in fileInfos)
|
||||||
|
{
|
||||||
|
string filePath = fileInfo.FilePath;
|
||||||
|
if (string.IsNullOrEmpty(filePath))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
PackageBundle packageBundle = null;
|
||||||
|
if (string.IsNullOrEmpty(fileInfo.BundleName) == false)
|
||||||
|
{
|
||||||
|
if (manifest.TryGetPackageBundleByBundleName(fileInfo.BundleName, out packageBundle) == false)
|
||||||
|
{
|
||||||
|
YooLogger.Warning($"Not found package bundle, bundle name : {fileInfo.BundleName}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (string.IsNullOrEmpty(fileInfo.BundleGUID) == false)
|
||||||
|
{
|
||||||
|
if (manifest.TryGetPackageBundleByBundleGUID(fileInfo.BundleGUID, out packageBundle) == false)
|
||||||
|
{
|
||||||
|
YooLogger.Warning($"Not found package bundle, bundle guid : {fileInfo.BundleGUID}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
string fileName = System.IO.Path.GetFileName(filePath);
|
string fileName = System.IO.Path.GetFileName(filePath);
|
||||||
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle))
|
if (manifest.TryGetPackageBundleByFileName(fileName, out packageBundle) == false)
|
||||||
|
{
|
||||||
|
YooLogger.Warning($"Not found package bundle, file name : {fileName}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (packageBundle != null)
|
||||||
{
|
{
|
||||||
var fileSystem = GetBelongFileSystem(packageBundle);
|
var fileSystem = GetBelongFileSystem(packageBundle);
|
||||||
if (fileSystem == null)
|
if (fileSystem == null)
|
||||||
@@ -435,10 +486,6 @@ namespace YooAsset
|
|||||||
result.Add(bundleInfo);
|
result.Add(bundleInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
YooLogger.Warning($"Not found package bundle, importer file path : {filePath}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -361,21 +361,21 @@ namespace YooAsset
|
|||||||
/// 资源回收
|
/// 资源回收
|
||||||
/// 说明:尝试卸载指定的资源
|
/// 说明:尝试卸载指定的资源
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void TryUnloadUnusedAsset(string location)
|
public void TryUnloadUnusedAsset(string location, int loopCount = 10)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||||
_resourceManager.TryUnloadUnusedAsset(assetInfo);
|
_resourceManager.TryUnloadUnusedAsset(assetInfo, loopCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源回收
|
/// 资源回收
|
||||||
/// 说明:尝试卸载指定的资源
|
/// 说明:尝试卸载指定的资源
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void TryUnloadUnusedAsset(AssetInfo assetInfo)
|
public void TryUnloadUnusedAsset(AssetInfo assetInfo, int loopCount = 10)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
_resourceManager.TryUnloadUnusedAsset(assetInfo);
|
_resourceManager.TryUnloadUnusedAsset(assetInfo, loopCount);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -969,7 +969,7 @@ namespace YooAsset
|
|||||||
public ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _playModeImpl.CreateResourceDownloaderByAll(downloadingMaxNumber, failedTryAgain, timeout);
|
return _playModeImpl.CreateResourceDownloaderByAll(downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -982,7 +982,7 @@ namespace YooAsset
|
|||||||
public ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _playModeImpl.CreateResourceDownloaderByTags(new string[] { tag }, downloadingMaxNumber, failedTryAgain, timeout);
|
return _playModeImpl.CreateResourceDownloaderByTags(new string[] { tag }, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -995,7 +995,7 @@ namespace YooAsset
|
|||||||
public ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _playModeImpl.CreateResourceDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain, timeout);
|
return _playModeImpl.CreateResourceDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1011,11 +1011,11 @@ namespace YooAsset
|
|||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
var assetInfo = ConvertLocationToAssetInfo(location, null);
|
var assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||||
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
|
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
|
||||||
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain, timeout);
|
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
public ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
return CreateBundleDownloader(location, false, downloadingMaxNumber, failedTryAgain, timeout);
|
return CreateBundleDownloader(location, false, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1035,11 +1035,11 @@ namespace YooAsset
|
|||||||
var assetInfo = ConvertLocationToAssetInfo(location, null);
|
var assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||||
assetInfos.Add(assetInfo);
|
assetInfos.Add(assetInfo);
|
||||||
}
|
}
|
||||||
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos.ToArray(), recursiveDownload, downloadingMaxNumber, failedTryAgain, timeout);
|
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos.ToArray(), recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
return CreateBundleDownloader(locations, false, downloadingMaxNumber, failedTryAgain, timeout);
|
return CreateBundleDownloader(locations, false, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1054,11 +1054,11 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
|
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
|
||||||
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain, timeout);
|
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
return CreateBundleDownloader(assetInfo, false, downloadingMaxNumber, failedTryAgain, timeout);
|
return CreateBundleDownloader(assetInfo, false, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1072,11 +1072,11 @@ namespace YooAsset
|
|||||||
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain, timeout);
|
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
return CreateBundleDownloader(assetInfos, false, downloadingMaxNumber, failedTryAgain, timeout);
|
return CreateBundleDownloader(assetInfos, false, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -1089,7 +1089,7 @@ namespace YooAsset
|
|||||||
public ResourceUnpackerOperation CreateResourceUnpacker(int unpackingMaxNumber, int failedTryAgain)
|
public ResourceUnpackerOperation CreateResourceUnpacker(int unpackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _playModeImpl.CreateResourceUnpackerByAll(unpackingMaxNumber, failedTryAgain, int.MaxValue);
|
return _playModeImpl.CreateResourceUnpackerByAll(unpackingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1101,7 +1101,7 @@ namespace YooAsset
|
|||||||
public ResourceUnpackerOperation CreateResourceUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain)
|
public ResourceUnpackerOperation CreateResourceUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _playModeImpl.CreateResourceUnpackerByTags(new string[] { tag }, unpackingMaxNumber, failedTryAgain, int.MaxValue);
|
return _playModeImpl.CreateResourceUnpackerByTags(new string[] { tag }, unpackingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1113,7 +1113,7 @@ namespace YooAsset
|
|||||||
public ResourceUnpackerOperation CreateResourceUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain)
|
public ResourceUnpackerOperation CreateResourceUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _playModeImpl.CreateResourceUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain, int.MaxValue);
|
return _playModeImpl.CreateResourceUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -1128,7 +1128,20 @@ namespace YooAsset
|
|||||||
public ResourceImporterOperation CreateResourceImporter(string[] filePaths, int importerMaxNumber, int failedTryAgain)
|
public ResourceImporterOperation CreateResourceImporter(string[] filePaths, int importerMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _playModeImpl.CreateResourceImporterByFilePaths(filePaths, importerMaxNumber, failedTryAgain, int.MaxValue);
|
return _playModeImpl.CreateResourceImporterByFilePaths(filePaths, importerMaxNumber, failedTryAgain);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建资源导入器
|
||||||
|
/// 注意:资源信息里需要指定BundleName或BundleGUID!
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileInfos">资源信息列表</param>
|
||||||
|
/// <param name="importerMaxNumber">同时导入的最大文件数</param>
|
||||||
|
/// <param name="failedTryAgain">导入失败的重试次数</param>
|
||||||
|
public ResourceImporterOperation CreateResourceImporter(ImportFileInfo[] fileInfos, int importerMaxNumber, int failedTryAgain)
|
||||||
|
{
|
||||||
|
DebugCheckInitialize();
|
||||||
|
return _playModeImpl.CreateResourceImporterByFileInfos(fileInfos, importerMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
|
|||||||
string sourcePath = GetBuildinHashFilePath();
|
string sourcePath = GetBuildinHashFilePath();
|
||||||
string destPath = GetCacheHashFilePath();
|
string destPath = GetCacheHashFilePath();
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
||||||
_hashFileRequestOp = new UnityWebFileRequestOperation(url, destPath);
|
_hashFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60);
|
||||||
OperationSystem.StartOperation(_packageName, _hashFileRequestOp);
|
OperationSystem.StartOperation(_packageName, _hashFileRequestOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
|
|||||||
string sourcePath = GetBuildinManifestFilePath();
|
string sourcePath = GetBuildinManifestFilePath();
|
||||||
string destPath = GetCacheManifestFilePath();
|
string destPath = GetCacheManifestFilePath();
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
||||||
_manifestFileRequestOp = new UnityWebFileRequestOperation(url, destPath);
|
_manifestFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60);
|
||||||
OperationSystem.StartOperation(_packageName, _manifestFileRequestOp);
|
OperationSystem.StartOperation(_packageName, _manifestFileRequestOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class GetBuildinPackageVersionOperation : GameAsyncOperation
|
|||||||
{
|
{
|
||||||
string filePath = GetBuildinPackageVersionFilePath();
|
string filePath = GetBuildinPackageVersionFilePath();
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||||
_versionFileRequestOp = new UnityWebTextRequestOperation(url);
|
_versionFileRequestOp = new UnityWebTextRequestOperation(url, 60);
|
||||||
OperationSystem.StartOperation(_packageName, _versionFileRequestOp);
|
OperationSystem.StartOperation(_packageName, _versionFileRequestOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,10 @@ public class SpriteAtlasLoader : MonoBehaviour
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var atlas = loadHandle.AssetObject as SpriteAtlas;
|
||||||
|
_loadedAtlas.Add(atlasName, atlas);
|
||||||
_loadHandles.Add(loadHandle);
|
_loadHandles.Add(loadHandle);
|
||||||
callback.Invoke(loadHandle.AssetObject as SpriteAtlas);
|
callback.Invoke(atlas);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 8c5a1726d94498e4cbe30f5f510cc796
|
guid: d27136885efd6ab4fae1a1fea23b0010
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#if UNITY_ANDROID && GOOGLE_PLAY
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using YooAsset;
|
||||||
|
using System.Linq;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public static class GooglePlayFileSystemCreater
|
||||||
|
{
|
||||||
|
public static FileSystemParameters CreateFileSystemParameters(string packageRoot)
|
||||||
|
{
|
||||||
|
string fileSystemClass = $"{nameof(GooglePlayFileSystem)},YooAsset.MiniGame";
|
||||||
|
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
|
||||||
|
return fileSystemParams;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 兼容谷歌Play Asset Delivery的文件系统
|
||||||
|
/// </summary>
|
||||||
|
internal class GooglePlayFileSystem : DefaultBuildinFileSystem
|
||||||
|
{
|
||||||
|
public GooglePlayFileSystem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
||||||
|
{
|
||||||
|
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
|
||||||
|
{
|
||||||
|
var operation = new GPFSLoadAssetBundleOperation(this, bundle);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string error = $"{nameof(GooglePlayFileSystem)} not support load bundle type : {bundle.BundleType}";
|
||||||
|
var operation = new FSLoadBundleCompleteOperation(error);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2e26d6ba3f3c6cd48bc22d40f1857f89
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 055e7cf3bb9567f43bf15964d43c632f
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
#if UNITY_ANDROID && GOOGLE_PLAY
|
||||||
|
using System.IO;
|
||||||
|
using UnityEngine;
|
||||||
|
using YooAsset;
|
||||||
|
using Google.Play.AssetDelivery;
|
||||||
|
|
||||||
|
internal class GPFSLoadAssetBundleOperation : FSLoadBundleOperation
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
LoadAssetBundle,
|
||||||
|
CheckResult,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly GooglePlayFileSystem _fileSystem;
|
||||||
|
private readonly PackageBundle _bundle;
|
||||||
|
private PlayAssetBundleRequest _bundleRequest;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
|
internal GPFSLoadAssetBundleOperation(GooglePlayFileSystem fileSystem, PackageBundle bundle)
|
||||||
|
{
|
||||||
|
_fileSystem = fileSystem;
|
||||||
|
_bundle = bundle;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
DownloadProgress = 1f;
|
||||||
|
DownloadedBytes = _bundle.FileSize;
|
||||||
|
_steps = ESteps.LoadAssetBundle;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.LoadAssetBundle)
|
||||||
|
{
|
||||||
|
if (_bundle.Encrypted)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"The {nameof(GooglePlayFileSystem)} not support bundle encrypted !";
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_bundleRequest = PlayAssetDelivery.RetrieveAssetBundleAsync(_bundle.FileName);
|
||||||
|
_steps = ESteps.CheckResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.CheckResult)
|
||||||
|
{
|
||||||
|
if (_bundleRequest.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_bundleRequest.Error != AssetDeliveryErrorCode.NoError)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"Failed to load delivery asset bundle file : {_bundle.BundleName} Error : {_bundleRequest.Error}";
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
Result = new AssetBundleResult(_fileSystem, _bundle, _bundleRequest.AssetBundle, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal override void InternalWaitForAsyncComplete()
|
||||||
|
{
|
||||||
|
if (_steps != ESteps.Done)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"{nameof(GooglePlayFileSystem)} not support sync load method !";
|
||||||
|
UnityEngine.Debug.LogError(Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0aeb57dcd2a7a8841bb161f5f343a25e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,16 +1,30 @@
|
|||||||
#if UNITY_WEBGL && DOUYINMINIGAME
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
|
|
||||||
internal class TTFSDownloadFileOperation : DefaultDownloadFileOperation
|
internal class TTFSDownloadFileOperation : FSDownloadFileOperation
|
||||||
{
|
{
|
||||||
private TiktokFileSystem _fileSystem;
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
CheckRequest,
|
||||||
|
TryAgain,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly TiktokFileSystem _fileSystem;
|
||||||
|
private readonly DownloadFileOptions _options;
|
||||||
|
private UnityWebCacheRequestOperation _webCacheRequestOp;
|
||||||
|
private int _requestCount = 0;
|
||||||
|
private float _tryAgainTimer;
|
||||||
|
private int _failedTryAgain;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal TTFSDownloadFileOperation(TiktokFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
|
internal TTFSDownloadFileOperation(TiktokFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
|
_options = options;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
@@ -21,81 +35,77 @@ internal class TTFSDownloadFileOperation : DefaultDownloadFileOperation
|
|||||||
// 创建下载器
|
// 创建下载器
|
||||||
if (_steps == ESteps.CreateRequest)
|
if (_steps == ESteps.CreateRequest)
|
||||||
{
|
{
|
||||||
// 获取请求地址
|
string url = GetRequestURL();
|
||||||
_requestURL = GetRequestURL();
|
_webCacheRequestOp = new UnityWebCacheRequestOperation(url);
|
||||||
|
_webCacheRequestOp.StartOperation();
|
||||||
// 重置变量
|
AddChildOperation(_webCacheRequestOp);
|
||||||
ResetRequestFiled();
|
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
CreateWebRequest();
|
|
||||||
|
|
||||||
_steps = ESteps.CheckRequest;
|
_steps = ESteps.CheckRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测下载结果
|
// 检测下载结果
|
||||||
if (_steps == ESteps.CheckRequest)
|
if (_steps == ESteps.CheckRequest)
|
||||||
{
|
{
|
||||||
DownloadProgress = _webRequest.downloadProgress;
|
_webCacheRequestOp.UpdateOperation();
|
||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
Progress = _webCacheRequestOp.Progress;
|
||||||
Progress = DownloadProgress;
|
DownloadProgress = _webCacheRequestOp.DownloadProgress;
|
||||||
if (_webRequest.isDone == false)
|
DownloadedBytes = (long)_webCacheRequestOp.DownloadedBytes;
|
||||||
{
|
if (_webCacheRequestOp.IsDone == false)
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// 检查网络错误
|
if (_webCacheRequestOp.Status == EOperationStatus.Succeed)
|
||||||
if (CheckRequestResult())
|
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
|
|
||||||
|
//TODO 需要验证抖音插件请求器的下载进度
|
||||||
|
DownloadProgress = 1f;
|
||||||
|
DownloadedBytes = Bundle.FileSize;
|
||||||
|
Progress = 1f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (_failedTryAgain > 0)
|
||||||
{
|
{
|
||||||
_steps = ESteps.TryAgain;
|
_steps = ESteps.TryAgain;
|
||||||
|
YooLogger.Warning($"Failed download : {_webCacheRequestOp.URL} Try again !");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _webCacheRequestOp.Error;
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注意:最终释放请求器
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新尝试下载
|
// 重新尝试下载
|
||||||
if (_steps == ESteps.TryAgain)
|
if (_steps == ESteps.TryAgain)
|
||||||
{
|
{
|
||||||
if (FailedTryAgain <= 0)
|
|
||||||
{
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
YooLogger.Error(Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_tryAgainTimer += Time.unscaledDeltaTime;
|
_tryAgainTimer += Time.unscaledDeltaTime;
|
||||||
if (_tryAgainTimer > 1f)
|
if (_tryAgainTimer > 1f)
|
||||||
{
|
{
|
||||||
FailedTryAgain--;
|
_tryAgainTimer = 0f;
|
||||||
|
_failedTryAgain--;
|
||||||
|
Progress = 0f;
|
||||||
|
DownloadProgress = 0f;
|
||||||
|
DownloadedBytes = 0;
|
||||||
_steps = ESteps.CreateRequest;
|
_steps = ESteps.CreateRequest;
|
||||||
YooLogger.Warning(Error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateWebRequest()
|
/// <summary>
|
||||||
|
/// 获取网络请求地址
|
||||||
|
/// </summary>
|
||||||
|
private string GetRequestURL()
|
||||||
{
|
{
|
||||||
//TODO : 抖音小游戏没有找到预下载方法
|
// 轮流返回请求地址
|
||||||
_webRequest = UnityWebRequest.Get(_requestURL);
|
_requestCount++;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
if (_requestCount % 2 == 0)
|
||||||
_webRequest.SendWebRequest();
|
return _options.FallbackURL;
|
||||||
}
|
else
|
||||||
private void DisposeWebRequest()
|
return _options.MainURL;
|
||||||
{
|
|
||||||
if (_webRequest != null)
|
|
||||||
{
|
|
||||||
//注意:引擎底层会自动调用Abort方法
|
|
||||||
_webRequest.Dispose();
|
|
||||||
_webRequest = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
#if UNITY_WEBGL && DOUYINMINIGAME
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
|
|
||||||
internal class TTFSLoadBundleOperation : FSLoadBundleOperation
|
internal class TTFSLoadBundleOperation : FSLoadBundleOperation
|
||||||
@@ -14,7 +13,7 @@ internal class TTFSLoadBundleOperation : FSLoadBundleOperation
|
|||||||
|
|
||||||
private readonly TiktokFileSystem _fileSystem;
|
private readonly TiktokFileSystem _fileSystem;
|
||||||
private readonly PackageBundle _bundle;
|
private readonly PackageBundle _bundle;
|
||||||
private DownloadAssetBundleOperation _downloadAssetBundleOp;
|
private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal TTFSLoadBundleOperation(TiktokFileSystem fileSystem, PackageBundle bundle)
|
internal TTFSLoadBundleOperation(TiktokFileSystem fileSystem, PackageBundle bundle)
|
||||||
@@ -33,54 +32,46 @@ internal class TTFSLoadBundleOperation : FSLoadBundleOperation
|
|||||||
|
|
||||||
if (_steps == ESteps.DownloadAssetBundle)
|
if (_steps == ESteps.DownloadAssetBundle)
|
||||||
{
|
{
|
||||||
if (_downloadAssetBundleOp == null)
|
if (_loadWebAssetBundleOp == null)
|
||||||
{
|
{
|
||||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
|
string mainRUL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
|
||||||
options.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName); ;
|
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
||||||
options.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||||
|
options.SetURL(mainRUL, fallbackURL);
|
||||||
|
|
||||||
if (_bundle.Encrypted)
|
if (_bundle.Encrypted)
|
||||||
{
|
{
|
||||||
_downloadAssetBundleOp = new DownloadWebEncryptAssetBundleOperation(false, _fileSystem.DecryptionServices, _bundle, options);
|
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices);
|
||||||
_downloadAssetBundleOp.StartOperation();
|
_loadWebAssetBundleOp.StartOperation();
|
||||||
AddChildOperation(_downloadAssetBundleOp);
|
AddChildOperation(_loadWebAssetBundleOp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_downloadAssetBundleOp = new DownloadTiktokAssetBundleOperation(_bundle, options);
|
_loadWebAssetBundleOp = new LoadTiktokAssetBundleOperation(_bundle, options);
|
||||||
_downloadAssetBundleOp.StartOperation();
|
_loadWebAssetBundleOp.StartOperation();
|
||||||
AddChildOperation(_downloadAssetBundleOp);
|
AddChildOperation(_loadWebAssetBundleOp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_downloadAssetBundleOp.UpdateOperation();
|
_loadWebAssetBundleOp.UpdateOperation();
|
||||||
DownloadProgress = _downloadAssetBundleOp.DownloadProgress;
|
Progress = _loadWebAssetBundleOp.Progress;
|
||||||
DownloadedBytes = (long)_downloadAssetBundleOp.DownloadedBytes;
|
DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
|
||||||
Progress = DownloadProgress;
|
DownloadedBytes = (long)_loadWebAssetBundleOp.DownloadedBytes;
|
||||||
if (_downloadAssetBundleOp.IsDone == false)
|
if (_loadWebAssetBundleOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_downloadAssetBundleOp.Status == EOperationStatus.Succeed)
|
if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
|
||||||
var assetBundle = _downloadAssetBundleOp.Result;
|
|
||||||
if (assetBundle == null)
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = $"{nameof(DownloadAssetBundleOperation)} loaded asset bundle is null !";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
var assetBundle = _loadWebAssetBundleOp.Result;
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Result = new TTAssetBundleResult(_fileSystem, _bundle, assetBundle);
|
Result = new TTAssetBundleResult(_fileSystem, _bundle, assetBundle);
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _downloadAssetBundleOp.Error;
|
Error = _loadWebAssetBundleOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,126 +0,0 @@
|
|||||||
#if UNITY_WEBGL && DOUYINMINIGAME
|
|
||||||
using UnityEngine;
|
|
||||||
using TTSDK;
|
|
||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
internal class DownloadTiktokAssetBundleOperation : DownloadAssetBundleOperation
|
|
||||||
{
|
|
||||||
private ESteps _steps = ESteps.None;
|
|
||||||
|
|
||||||
internal DownloadTiktokAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
internal override void InternalStart()
|
|
||||||
{
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
}
|
|
||||||
internal override void InternalUpdate()
|
|
||||||
{
|
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
if (_steps == ESteps.CreateRequest)
|
|
||||||
{
|
|
||||||
// 获取请求地址
|
|
||||||
_requestURL = GetRequestURL();
|
|
||||||
|
|
||||||
// 重置变量
|
|
||||||
ResetRequestFiled();
|
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
CreateWebRequest();
|
|
||||||
|
|
||||||
_steps = ESteps.CheckRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检测下载结果
|
|
||||||
if (_steps == ESteps.CheckRequest)
|
|
||||||
{
|
|
||||||
DownloadProgress = _webRequest.downloadProgress;
|
|
||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
|
||||||
Progress = DownloadProgress;
|
|
||||||
if (_webRequest.isDone == false)
|
|
||||||
{
|
|
||||||
//TODO 需要验证抖音插件请求器的下载进度
|
|
||||||
//CheckRequestTimeout();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查网络错误
|
|
||||||
if (CheckRequestResult())
|
|
||||||
{
|
|
||||||
var downloadHanlder = (DownloadHandlerTTAssetBundle)_webRequest.downloadHandler;
|
|
||||||
AssetBundle assetBundle = downloadHanlder.assetBundle;
|
|
||||||
if (assetBundle == null)
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = "Download handler asset bundle object is null !";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Result = assetBundle;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
|
|
||||||
//TODO 需要验证抖音插件请求器的下载进度
|
|
||||||
DownloadProgress = 1f;
|
|
||||||
DownloadedBytes = Bundle.FileSize;
|
|
||||||
Progress = 1f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.TryAgain;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 注意:最终释放请求器
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 重新尝试下载
|
|
||||||
if (_steps == ESteps.TryAgain)
|
|
||||||
{
|
|
||||||
if (FailedTryAgain <= 0)
|
|
||||||
{
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
YooLogger.Error(Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_tryAgainTimer += Time.unscaledDeltaTime;
|
|
||||||
if (_tryAgainTimer > 1f)
|
|
||||||
{
|
|
||||||
FailedTryAgain--;
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
YooLogger.Warning(Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
internal override void InternalAbort()
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateWebRequest()
|
|
||||||
{
|
|
||||||
_webRequest = TTAssetBundle.GetAssetBundle(_requestURL);
|
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
|
||||||
_webRequest.SendWebRequest();
|
|
||||||
}
|
|
||||||
private void DisposeWebRequest()
|
|
||||||
{
|
|
||||||
if (_webRequest != null)
|
|
||||||
{
|
|
||||||
//注意:引擎底层会自动调用Abort方法
|
|
||||||
_webRequest.Dispose();
|
|
||||||
_webRequest = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class LoadTiktokAssetBundleOperation : LoadWebAssetBundleOperation
|
||||||
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
CheckRequest,
|
||||||
|
TryAgain,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly PackageBundle _bundle;
|
||||||
|
private readonly DownloadFileOptions _options;
|
||||||
|
private UnityTiktokAssetBundleRequestOperation _unityTiktokAssetBundleRequestOp;
|
||||||
|
|
||||||
|
private int _requestCount = 0;
|
||||||
|
private float _tryAgainTimer;
|
||||||
|
private int _failedTryAgain;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
|
internal LoadTiktokAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options)
|
||||||
|
{
|
||||||
|
_bundle = bundle;
|
||||||
|
_options = options;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 创建下载器
|
||||||
|
if (_steps == ESteps.CreateRequest)
|
||||||
|
{
|
||||||
|
string url = GetRequestURL();
|
||||||
|
_unityTiktokAssetBundleRequestOp = new UnityTiktokAssetBundleRequestOperation(_bundle, url);
|
||||||
|
_unityTiktokAssetBundleRequestOp.StartOperation();
|
||||||
|
AddChildOperation(_unityTiktokAssetBundleRequestOp);
|
||||||
|
_steps = ESteps.CheckRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测下载结果
|
||||||
|
if (_steps == ESteps.CheckRequest)
|
||||||
|
{
|
||||||
|
_unityTiktokAssetBundleRequestOp.UpdateOperation();
|
||||||
|
Progress = _unityTiktokAssetBundleRequestOp.Progress;
|
||||||
|
DownloadProgress = _unityTiktokAssetBundleRequestOp.DownloadProgress;
|
||||||
|
DownloadedBytes = (long)_unityTiktokAssetBundleRequestOp.DownloadedBytes;
|
||||||
|
if (_unityTiktokAssetBundleRequestOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_unityTiktokAssetBundleRequestOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
Result = _unityTiktokAssetBundleRequestOp.Result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_failedTryAgain > 0)
|
||||||
|
{
|
||||||
|
_steps = ESteps.TryAgain;
|
||||||
|
YooLogger.Warning($"Failed download : {_unityTiktokAssetBundleRequestOp.URL} Try again !");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _unityTiktokAssetBundleRequestOp.Error;
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重新尝试下载
|
||||||
|
if (_steps == ESteps.TryAgain)
|
||||||
|
{
|
||||||
|
_tryAgainTimer += Time.unscaledDeltaTime;
|
||||||
|
if (_tryAgainTimer > 1f)
|
||||||
|
{
|
||||||
|
_tryAgainTimer = 0f;
|
||||||
|
_failedTryAgain--;
|
||||||
|
Progress = 0f;
|
||||||
|
DownloadProgress = 0f;
|
||||||
|
DownloadedBytes = 0;
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取网络请求地址
|
||||||
|
/// </summary>
|
||||||
|
private string GetRequestURL()
|
||||||
|
{
|
||||||
|
// 轮流返回请求地址
|
||||||
|
_requestCount++;
|
||||||
|
if (_requestCount % 2 == 0)
|
||||||
|
return _options.FallbackURL;
|
||||||
|
else
|
||||||
|
return _options.MainURL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
using UnityEngine;
|
||||||
|
using TTSDK;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class UnityTiktokAssetBundleRequestOperation : UnityWebRequestOperation
|
||||||
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
Download,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly PackageBundle _packageBundle;
|
||||||
|
private UnityWebRequestAsyncOperation _requestOperation;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 请求结果
|
||||||
|
/// </summary>
|
||||||
|
public AssetBundle Result { private set; get; }
|
||||||
|
|
||||||
|
internal UnityTiktokAssetBundleRequestOperation(PackageBundle bundle, string url) : base(url)
|
||||||
|
{
|
||||||
|
_packageBundle = bundle;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.CreateRequest)
|
||||||
|
{
|
||||||
|
CreateWebRequest();
|
||||||
|
_steps = ESteps.Download;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.Download)
|
||||||
|
{
|
||||||
|
DownloadProgress = _webRequest.downloadProgress;
|
||||||
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
|
Progress = _requestOperation.progress;
|
||||||
|
if (_requestOperation.isDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (CheckRequestResult())
|
||||||
|
{
|
||||||
|
var downloadHanlder = (DownloadHandlerTTAssetBundle)_webRequest.downloadHandler;
|
||||||
|
AssetBundle assetBundle = downloadHanlder.assetBundle;
|
||||||
|
if (assetBundle == null)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"URL : {_requestURL} Download handler asset bundle object is null !";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Result = assetBundle;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
|
||||||
|
//TODO 需要验证抖音插件请求器的下载进度
|
||||||
|
DownloadProgress = 1f;
|
||||||
|
DownloadedBytes = _packageBundle.FileSize;
|
||||||
|
Progress = 1f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注意:最终释放请求器
|
||||||
|
DisposeRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateWebRequest()
|
||||||
|
{
|
||||||
|
_webRequest = TTAssetBundle.GetAssetBundle(_requestURL);
|
||||||
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
|
_requestOperation = _webRequest.SendWebRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dbac28b7a131d1043af35b3c2dbe083f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -136,8 +136,9 @@ internal class TiktokFileSystem : IFileSystem
|
|||||||
}
|
}
|
||||||
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
||||||
{
|
{
|
||||||
options.MainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
|
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
|
||||||
options.FallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
||||||
|
options.SetURL(mainURL, fallbackURL);
|
||||||
var operation = new TTFSDownloadFileOperation(this, bundle, options);
|
var operation = new TTFSDownloadFileOperation(this, bundle, options);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,30 @@
|
|||||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
using WeChatWASM;
|
|
||||||
|
|
||||||
internal class WXFSDownloadFileOperation : DefaultDownloadFileOperation
|
internal class WXFSDownloadFileOperation : FSDownloadFileOperation
|
||||||
{
|
{
|
||||||
private WechatFileSystem _fileSystem;
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
CheckRequest,
|
||||||
|
TryAgain,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly WechatFileSystem _fileSystem;
|
||||||
|
private readonly DownloadFileOptions _options;
|
||||||
|
private UnityWebCacheRequestOperation _webCacheRequestOp;
|
||||||
|
private int _requestCount = 0;
|
||||||
|
private float _tryAgainTimer;
|
||||||
|
private int _failedTryAgain;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal WXFSDownloadFileOperation(WechatFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
|
internal WXFSDownloadFileOperation(WechatFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
|
_options = options;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
@@ -22,34 +35,25 @@ internal class WXFSDownloadFileOperation : DefaultDownloadFileOperation
|
|||||||
// 创建下载器
|
// 创建下载器
|
||||||
if (_steps == ESteps.CreateRequest)
|
if (_steps == ESteps.CreateRequest)
|
||||||
{
|
{
|
||||||
// 获取请求地址
|
string url = GetRequestURL();
|
||||||
_requestURL = GetRequestURL();
|
_webCacheRequestOp = new UnityWebCacheRequestOperation(url);
|
||||||
|
_webCacheRequestOp.SetRequestHeader("wechatminigame-preload", "1");
|
||||||
// 重置变量
|
_webCacheRequestOp.StartOperation();
|
||||||
ResetRequestFiled();
|
AddChildOperation(_webCacheRequestOp);
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
CreateWebRequest();
|
|
||||||
|
|
||||||
_steps = ESteps.CheckRequest;
|
_steps = ESteps.CheckRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测下载结果
|
// 检测下载结果
|
||||||
if (_steps == ESteps.CheckRequest)
|
if (_steps == ESteps.CheckRequest)
|
||||||
{
|
{
|
||||||
DownloadProgress = _webRequest.downloadProgress;
|
_webCacheRequestOp.UpdateOperation();
|
||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
Progress = _webCacheRequestOp.Progress;
|
||||||
Progress = DownloadProgress;
|
DownloadProgress = _webCacheRequestOp.DownloadProgress;
|
||||||
if (_webRequest.isDone == false)
|
DownloadedBytes = (long)_webCacheRequestOp.DownloadedBytes;
|
||||||
{
|
if (_webCacheRequestOp.IsDone == false)
|
||||||
//TODO 由于微信小游戏插件的问题,暂时不能判定超时!
|
|
||||||
// Issue : https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/108#
|
|
||||||
//CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// 检查网络错误
|
if (_webCacheRequestOp.Status == EOperationStatus.Succeed)
|
||||||
if (CheckRequestResult())
|
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
@@ -61,50 +65,49 @@ internal class WXFSDownloadFileOperation : DefaultDownloadFileOperation
|
|||||||
Progress = 1f;
|
Progress = 1f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (_failedTryAgain > 0)
|
||||||
{
|
{
|
||||||
_steps = ESteps.TryAgain;
|
_steps = ESteps.TryAgain;
|
||||||
|
YooLogger.Warning($"Failed download : {_webCacheRequestOp.URL} Try again !");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _webCacheRequestOp.Error;
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注意:最终释放请求器
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新尝试下载
|
// 重新尝试下载
|
||||||
if (_steps == ESteps.TryAgain)
|
if (_steps == ESteps.TryAgain)
|
||||||
{
|
{
|
||||||
if (FailedTryAgain <= 0)
|
|
||||||
{
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
YooLogger.Error(Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_tryAgainTimer += Time.unscaledDeltaTime;
|
_tryAgainTimer += Time.unscaledDeltaTime;
|
||||||
if (_tryAgainTimer > 1f)
|
if (_tryAgainTimer > 1f)
|
||||||
{
|
{
|
||||||
FailedTryAgain--;
|
_tryAgainTimer = 0f;
|
||||||
|
_failedTryAgain--;
|
||||||
|
Progress = 0f;
|
||||||
|
DownloadProgress = 0f;
|
||||||
|
DownloadedBytes = 0;
|
||||||
_steps = ESteps.CreateRequest;
|
_steps = ESteps.CreateRequest;
|
||||||
YooLogger.Warning(Error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateWebRequest()
|
/// <summary>
|
||||||
|
/// 获取网络请求地址
|
||||||
|
/// </summary>
|
||||||
|
private string GetRequestURL()
|
||||||
{
|
{
|
||||||
_webRequest = UnityWebRequest.Get(_requestURL);
|
// 轮流返回请求地址
|
||||||
_webRequest.SetRequestHeader("wechatminigame-preload", "1");
|
_requestCount++;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
if (_requestCount % 2 == 0)
|
||||||
_webRequest.SendWebRequest();
|
return _options.FallbackURL;
|
||||||
}
|
else
|
||||||
private void DisposeWebRequest()
|
return _options.MainURL;
|
||||||
{
|
|
||||||
if (_webRequest != null)
|
|
||||||
{
|
|
||||||
//注意:引擎底层会自动调用Abort方法
|
|
||||||
_webRequest.Dispose();
|
|
||||||
_webRequest = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -12,7 +12,7 @@ internal class WXFSLoadBundleOperation : FSLoadBundleOperation
|
|||||||
|
|
||||||
private readonly WechatFileSystem _fileSystem;
|
private readonly WechatFileSystem _fileSystem;
|
||||||
private readonly PackageBundle _bundle;
|
private readonly PackageBundle _bundle;
|
||||||
private DownloadAssetBundleOperation _downloadAssetBundleOp;
|
private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal WXFSLoadBundleOperation(WechatFileSystem fileSystem, PackageBundle bundle)
|
internal WXFSLoadBundleOperation(WechatFileSystem fileSystem, PackageBundle bundle)
|
||||||
@@ -31,54 +31,46 @@ internal class WXFSLoadBundleOperation : FSLoadBundleOperation
|
|||||||
|
|
||||||
if (_steps == ESteps.DownloadAssetBundle)
|
if (_steps == ESteps.DownloadAssetBundle)
|
||||||
{
|
{
|
||||||
if (_downloadAssetBundleOp == null)
|
if (_loadWebAssetBundleOp == null)
|
||||||
{
|
{
|
||||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
|
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
|
||||||
options.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName); ;
|
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
||||||
options.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||||
|
options.SetURL(mainURL, fallbackURL);
|
||||||
|
|
||||||
if (_bundle.Encrypted)
|
if (_bundle.Encrypted)
|
||||||
{
|
{
|
||||||
_downloadAssetBundleOp = new DownloadWebEncryptAssetBundleOperation(false, _fileSystem.DecryptionServices, _bundle, options);
|
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices);
|
||||||
_downloadAssetBundleOp.StartOperation();
|
_loadWebAssetBundleOp.StartOperation();
|
||||||
AddChildOperation(_downloadAssetBundleOp);
|
AddChildOperation(_loadWebAssetBundleOp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_downloadAssetBundleOp = new DownloadWechatAssetBundleOperation(_bundle, options);
|
_loadWebAssetBundleOp = new LoadWechatAssetBundleOperation(_bundle, options);
|
||||||
_downloadAssetBundleOp.StartOperation();
|
_loadWebAssetBundleOp.StartOperation();
|
||||||
AddChildOperation(_downloadAssetBundleOp);
|
AddChildOperation(_loadWebAssetBundleOp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_downloadAssetBundleOp.UpdateOperation();
|
_loadWebAssetBundleOp.UpdateOperation();
|
||||||
DownloadProgress = _downloadAssetBundleOp.DownloadProgress;
|
Progress = _loadWebAssetBundleOp.Progress;
|
||||||
DownloadedBytes = (long)_downloadAssetBundleOp.DownloadedBytes;
|
DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
|
||||||
Progress = DownloadProgress;
|
DownloadedBytes = (long)_loadWebAssetBundleOp.DownloadedBytes;
|
||||||
if (_downloadAssetBundleOp.IsDone == false)
|
if (_loadWebAssetBundleOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_downloadAssetBundleOp.Status == EOperationStatus.Succeed)
|
if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
|
||||||
var assetBundle = _downloadAssetBundleOp.Result;
|
|
||||||
if (assetBundle == null)
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = $"{nameof(DownloadAssetBundleOperation)} loaded asset bundle is null !";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
var assetBundle = _loadWebAssetBundleOp.Result;
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Result = new WXAssetBundleResult(_fileSystem, _bundle, assetBundle);
|
Result = new WXAssetBundleResult(_fileSystem, _bundle, assetBundle);
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _downloadAssetBundleOp.Error;
|
Error = _loadWebAssetBundleOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,128 +0,0 @@
|
|||||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
|
||||||
using UnityEngine;
|
|
||||||
using WeChatWASM;
|
|
||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
internal class DownloadWechatAssetBundleOperation : DownloadAssetBundleOperation
|
|
||||||
{
|
|
||||||
private ESteps _steps = ESteps.None;
|
|
||||||
|
|
||||||
internal DownloadWechatAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
internal override void InternalStart()
|
|
||||||
{
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
}
|
|
||||||
internal override void InternalUpdate()
|
|
||||||
{
|
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
if (_steps == ESteps.CreateRequest)
|
|
||||||
{
|
|
||||||
// 获取请求地址
|
|
||||||
_requestURL = GetRequestURL();
|
|
||||||
|
|
||||||
// 重置变量
|
|
||||||
ResetRequestFiled();
|
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
CreateWebRequest();
|
|
||||||
|
|
||||||
_steps = ESteps.CheckRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检测下载结果
|
|
||||||
if (_steps == ESteps.CheckRequest)
|
|
||||||
{
|
|
||||||
DownloadProgress = _webRequest.downloadProgress;
|
|
||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
|
||||||
Progress = DownloadProgress;
|
|
||||||
if (_webRequest.isDone == false)
|
|
||||||
{
|
|
||||||
//TODO 由于微信小游戏插件的问题,暂时不能判定超时!
|
|
||||||
// Issue : https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/108#
|
|
||||||
//CheckRequestTimeout();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查网络错误
|
|
||||||
if (CheckRequestResult())
|
|
||||||
{
|
|
||||||
var downloadHanlder = (DownloadHandlerWXAssetBundle)_webRequest.downloadHandler;
|
|
||||||
AssetBundle assetBundle = downloadHanlder.assetBundle;
|
|
||||||
if (assetBundle == null)
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = "Download handler asset bundle object is null !";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Result = assetBundle;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
|
|
||||||
//TODO 解决微信小游戏插件问题
|
|
||||||
// Issue : https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/108#
|
|
||||||
DownloadProgress = 1f;
|
|
||||||
DownloadedBytes = Bundle.FileSize;
|
|
||||||
Progress = 1f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.TryAgain;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 注意:最终释放请求器
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 重新尝试下载
|
|
||||||
if (_steps == ESteps.TryAgain)
|
|
||||||
{
|
|
||||||
if (FailedTryAgain <= 0)
|
|
||||||
{
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
YooLogger.Error(Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_tryAgainTimer += Time.unscaledDeltaTime;
|
|
||||||
if (_tryAgainTimer > 1f)
|
|
||||||
{
|
|
||||||
FailedTryAgain--;
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
YooLogger.Warning(Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
internal override void InternalAbort()
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateWebRequest()
|
|
||||||
{
|
|
||||||
_webRequest = WXAssetBundle.GetAssetBundle(_requestURL);
|
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
|
||||||
_webRequest.SendWebRequest();
|
|
||||||
}
|
|
||||||
private void DisposeWebRequest()
|
|
||||||
{
|
|
||||||
if (_webRequest != null)
|
|
||||||
{
|
|
||||||
//注意:引擎底层会自动调用Abort方法
|
|
||||||
_webRequest.Dispose();
|
|
||||||
_webRequest = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class LoadWechatAssetBundleOperation : LoadWebAssetBundleOperation
|
||||||
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
CheckRequest,
|
||||||
|
TryAgain,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly PackageBundle _bundle;
|
||||||
|
private readonly DownloadFileOptions _options;
|
||||||
|
private UnityWechatAssetBundleRequestOperation _unityWechatAssetBundleRequestOp;
|
||||||
|
|
||||||
|
private int _requestCount = 0;
|
||||||
|
private float _tryAgainTimer;
|
||||||
|
private int _failedTryAgain;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
|
internal LoadWechatAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options)
|
||||||
|
{
|
||||||
|
_bundle = bundle;
|
||||||
|
_options = options;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 创建下载器
|
||||||
|
if (_steps == ESteps.CreateRequest)
|
||||||
|
{
|
||||||
|
string url = GetRequestURL();
|
||||||
|
_unityWechatAssetBundleRequestOp = new UnityWechatAssetBundleRequestOperation(_bundle, url);
|
||||||
|
_unityWechatAssetBundleRequestOp.StartOperation();
|
||||||
|
AddChildOperation(_unityWechatAssetBundleRequestOp);
|
||||||
|
_steps = ESteps.CheckRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测下载结果
|
||||||
|
if (_steps == ESteps.CheckRequest)
|
||||||
|
{
|
||||||
|
_unityWechatAssetBundleRequestOp.UpdateOperation();
|
||||||
|
Progress = _unityWechatAssetBundleRequestOp.Progress;
|
||||||
|
DownloadProgress = _unityWechatAssetBundleRequestOp.DownloadProgress;
|
||||||
|
DownloadedBytes = (long)_unityWechatAssetBundleRequestOp.DownloadedBytes;
|
||||||
|
if (_unityWechatAssetBundleRequestOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_unityWechatAssetBundleRequestOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
Result = _unityWechatAssetBundleRequestOp.Result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_failedTryAgain > 0)
|
||||||
|
{
|
||||||
|
_steps = ESteps.TryAgain;
|
||||||
|
YooLogger.Warning($"Failed download : {_unityWechatAssetBundleRequestOp.URL} Try again !");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _unityWechatAssetBundleRequestOp.Error;
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重新尝试下载
|
||||||
|
if (_steps == ESteps.TryAgain)
|
||||||
|
{
|
||||||
|
_tryAgainTimer += Time.unscaledDeltaTime;
|
||||||
|
if (_tryAgainTimer > 1f)
|
||||||
|
{
|
||||||
|
_tryAgainTimer = 0f;
|
||||||
|
_failedTryAgain--;
|
||||||
|
Progress = 0f;
|
||||||
|
DownloadProgress = 0f;
|
||||||
|
DownloadedBytes = 0;
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取网络请求地址
|
||||||
|
/// </summary>
|
||||||
|
protected string GetRequestURL()
|
||||||
|
{
|
||||||
|
// 轮流返回请求地址
|
||||||
|
_requestCount++;
|
||||||
|
if (_requestCount % 2 == 0)
|
||||||
|
return _options.FallbackURL;
|
||||||
|
else
|
||||||
|
return _options.MainURL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
using UnityEngine;
|
||||||
|
using WeChatWASM;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class UnityWechatAssetBundleRequestOperation : UnityWebRequestOperation
|
||||||
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
Download,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly PackageBundle _packageBundle;
|
||||||
|
private UnityWebRequestAsyncOperation _requestOperation;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 请求结果
|
||||||
|
/// </summary>
|
||||||
|
public AssetBundle Result { private set; get; }
|
||||||
|
|
||||||
|
internal UnityWechatAssetBundleRequestOperation(PackageBundle bundle, string url) : base(url)
|
||||||
|
{
|
||||||
|
_packageBundle = bundle;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.CreateRequest)
|
||||||
|
{
|
||||||
|
CreateWebRequest();
|
||||||
|
_steps = ESteps.Download;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.Download)
|
||||||
|
{
|
||||||
|
DownloadProgress = _webRequest.downloadProgress;
|
||||||
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
|
Progress = _requestOperation.progress;
|
||||||
|
if (_requestOperation.isDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (CheckRequestResult())
|
||||||
|
{
|
||||||
|
var downloadHanlder = (DownloadHandlerWXAssetBundle)_webRequest.downloadHandler;
|
||||||
|
AssetBundle assetBundle = downloadHanlder.assetBundle;
|
||||||
|
if (assetBundle == null)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"URL : {_requestURL} Download handler asset bundle object is null !";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Result = assetBundle;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
|
||||||
|
//TODO 解决微信小游戏插件问题
|
||||||
|
// Issue : https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/108#
|
||||||
|
DownloadProgress = 1f;
|
||||||
|
DownloadedBytes = _packageBundle.FileSize;
|
||||||
|
Progress = 1f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注意:最终释放请求器
|
||||||
|
DisposeRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateWebRequest()
|
||||||
|
{
|
||||||
|
_webRequest = WXAssetBundle.GetAssetBundle(_requestURL);
|
||||||
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
|
_requestOperation = _webRequest.SendWebRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8dd1f15e52120ad409285fa3e21c7d30
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -151,8 +151,9 @@ internal class WechatFileSystem : IFileSystem
|
|||||||
}
|
}
|
||||||
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
||||||
{
|
{
|
||||||
options.MainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
|
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
|
||||||
options.FallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
||||||
|
options.SetURL(mainURL, fallbackURL);
|
||||||
var operation = new WXFSDownloadFileOperation(this, bundle, options);
|
var operation = new WXFSDownloadFileOperation(this, bundle, options);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
"references": [
|
"references": [
|
||||||
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
||||||
"GUID:5efd170ecd8084500bed5692932fe14e",
|
"GUID:5efd170ecd8084500bed5692932fe14e",
|
||||||
"GUID:bb21d6197862c4c3e863390dec9859a7"
|
"GUID:bb21d6197862c4c3e863390dec9859a7",
|
||||||
|
"GUID:870f26a2ffa82429195df0861505c5d5"
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4ce11d98eccfa4b44bf2c82f7d87d105
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
using YooAsset;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 文件偏移加密方式
|
||||||
|
/// </summary>
|
||||||
|
public class TestFileOffsetEncryption : IEncryptionServices
|
||||||
|
{
|
||||||
|
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
// 说明:对TestRes3资源目录进行加密
|
||||||
|
if (fileInfo.BundleName.Contains("_testres3_"))
|
||||||
|
{
|
||||||
|
int offset = 32;
|
||||||
|
byte[] fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
|
||||||
|
var encryptedData = new byte[fileData.Length + offset];
|
||||||
|
Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length);
|
||||||
|
|
||||||
|
EncryptResult result = new EncryptResult();
|
||||||
|
result.Encrypted = true;
|
||||||
|
result.EncryptedData = encryptedData;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EncryptResult result = new EncryptResult();
|
||||||
|
result.Encrypted = false;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源文件偏移解密类
|
||||||
|
/// </summary>
|
||||||
|
public class TestFileOffsetDecryption : IDecryptionServices
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 同步方式获取解密的资源包对象
|
||||||
|
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||||
|
/// </summary>
|
||||||
|
DecryptResult IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
DecryptResult decryptResult = new DecryptResult();
|
||||||
|
decryptResult.ManagedStream = null;
|
||||||
|
decryptResult.Result = AssetBundle.LoadFromFile(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
|
||||||
|
return decryptResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异步方式获取解密的资源包对象
|
||||||
|
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||||
|
/// </summary>
|
||||||
|
DecryptResult IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
DecryptResult decryptResult = new DecryptResult();
|
||||||
|
decryptResult.ManagedStream = null;
|
||||||
|
decryptResult.CreateRequest = AssetBundle.LoadFromFileAsync(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
|
||||||
|
return decryptResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 后备方式获取解密的资源包对象
|
||||||
|
/// </summary>
|
||||||
|
DecryptResult IDecryptionServices.LoadAssetBundleFallback(DecryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
return new DecryptResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取解密的字节数据
|
||||||
|
/// </summary>
|
||||||
|
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取解密的文本数据
|
||||||
|
/// </summary>
|
||||||
|
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ulong GetFileOffset()
|
||||||
|
{
|
||||||
|
return 32;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user