mirror of https://github.com/tuyoogame/YooAsset
Compare commits
No commits in common. "a138701afe9fd7835294ccb94233419c11c16465" and "0c36e458f710655e1f2f2e805508a4afd1ad95c7" have entirely different histories.
a138701afe
...
0c36e458f7
|
@ -2,19 +2,21 @@
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
using UnityEngine.Networking;
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
|
using TTSDK;
|
||||||
|
using WeChatWASM;
|
||||||
|
|
||||||
internal class TTFSLoadBundleOperation : FSLoadBundleOperation
|
internal class TTFSLoadBundleOperation : FSLoadBundleOperation
|
||||||
{
|
{
|
||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
DownloadAssetBundle,
|
LoadBundleFile,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly TiktokFileSystem _fileSystem;
|
private readonly TiktokFileSystem _fileSystem;
|
||||||
private readonly PackageBundle _bundle;
|
private readonly PackageBundle _bundle;
|
||||||
private DownloadAssetBundleOperation _downloadAssetBundleOp;
|
private UnityWebRequest _webRequest;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal TTFSLoadBundleOperation(TiktokFileSystem fileSystem, PackageBundle bundle)
|
internal TTFSLoadBundleOperation(TiktokFileSystem fileSystem, PackageBundle bundle)
|
||||||
|
@ -24,47 +26,51 @@ internal class TTFSLoadBundleOperation : FSLoadBundleOperation
|
||||||
}
|
}
|
||||||
internal override void InternalOnStart()
|
internal override void InternalOnStart()
|
||||||
{
|
{
|
||||||
_steps = ESteps.DownloadAssetBundle;
|
_steps = ESteps.LoadBundleFile;
|
||||||
}
|
}
|
||||||
internal override void InternalOnUpdate()
|
internal override void InternalOnUpdate()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_steps == ESteps.DownloadAssetBundle)
|
if (_steps == ESteps.LoadBundleFile)
|
||||||
{
|
{
|
||||||
if (_downloadAssetBundleOp == null)
|
if (_webRequest == null)
|
||||||
{
|
{
|
||||||
DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
|
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
|
||||||
downloadParam.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName); ;
|
_webRequest = TTAssetBundle.GetAssetBundle(mainURL);
|
||||||
downloadParam.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
_webRequest.SendWebRequest();
|
||||||
|
|
||||||
if (_bundle.Encrypted)
|
|
||||||
{
|
|
||||||
_downloadAssetBundleOp = new DownloadWebEncryptAssetBundleOperation(_fileSystem.DecryptionServices, _bundle, downloadParam);
|
|
||||||
OperationSystem.StartOperation(_fileSystem.PackageName, _downloadAssetBundleOp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_downloadAssetBundleOp = new DownloadTiktokAssetBundleOperation(_bundle, downloadParam);
|
|
||||||
OperationSystem.StartOperation(_fileSystem.PackageName, _downloadAssetBundleOp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadProgress = _downloadAssetBundleOp.DownloadProgress;
|
DownloadProgress = _webRequest.downloadProgress;
|
||||||
DownloadedBytes = (long)_downloadAssetBundleOp.DownloadedBytes;
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
Progress = DownloadProgress;
|
Progress = DownloadProgress;
|
||||||
if (_downloadAssetBundleOp.IsDone == false)
|
if (_webRequest.isDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_downloadAssetBundleOp.Status == EOperationStatus.Succeed)
|
if (CheckRequestResult())
|
||||||
{
|
{
|
||||||
var assetBundle = _downloadAssetBundleOp.Result;
|
if (_bundle.Encrypted && _fileSystem.DecryptionServices == 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 = $"The {nameof(IWebDecryptionServices)} is null !";
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AssetBundle assetBundle;
|
||||||
|
var downloadHanlder = _webRequest.downloadHandler as DownloadHandlerTTAssetBundle;
|
||||||
|
if (_bundle.Encrypted)
|
||||||
|
assetBundle = _fileSystem.LoadEncryptedAssetBundle(_bundle, downloadHanlder.data);
|
||||||
|
else
|
||||||
|
assetBundle = downloadHanlder.assetBundle;
|
||||||
|
|
||||||
|
if (assetBundle == null)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Error = $"{nameof(DownloadHandlerTTAssetBundle)} loaded asset bundle is null !";
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -77,7 +83,6 @@ internal class TTFSLoadBundleOperation : FSLoadBundleOperation
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _downloadAssetBundleOp.Error;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,11 +98,31 @@ internal class TTFSLoadBundleOperation : FSLoadBundleOperation
|
||||||
}
|
}
|
||||||
public override void AbortDownloadOperation()
|
public override void AbortDownloadOperation()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.DownloadAssetBundle)
|
}
|
||||||
|
|
||||||
|
private bool CheckRequestResult()
|
||||||
|
{
|
||||||
|
#if UNITY_2020_3_OR_NEWER
|
||||||
|
if (_webRequest.result != UnityWebRequest.Result.Success)
|
||||||
{
|
{
|
||||||
if (_downloadAssetBundleOp != null)
|
Error = _webRequest.error;
|
||||||
_downloadAssetBundleOp.SetAbort();
|
return false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (_webRequest.isNetworkError || _webRequest.isHttpError)
|
||||||
|
{
|
||||||
|
Error = _webRequest.error;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -1,127 +0,0 @@
|
||||||
#if UNITY_WEBGL && DOUYINMINIGAME
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Networking;
|
|
||||||
using TTSDK;
|
|
||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
internal class DownloadTiktokAssetBundleOperation : DownloadAssetBundleOperation
|
|
||||||
{
|
|
||||||
private ESteps _steps = ESteps.None;
|
|
||||||
|
|
||||||
internal DownloadTiktokAssetBundleOperation(PackageBundle bundle, DownloadParam param) : base(bundle, param)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
internal override void InternalOnStart()
|
|
||||||
{
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
}
|
|
||||||
internal override void InternalOnUpdate()
|
|
||||||
{
|
|
||||||
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 InternalOnAbort()
|
|
||||||
{
|
|
||||||
_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
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: fa5e1bc536118b14ba56f53930539e38
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -42,9 +42,7 @@ internal class WXFSDownloadFileOperation : DefaultDownloadFileOperation
|
||||||
Progress = DownloadProgress;
|
Progress = DownloadProgress;
|
||||||
if (_webRequest.isDone == false)
|
if (_webRequest.isDone == false)
|
||||||
{
|
{
|
||||||
//TODO 由于微信小游戏插件的问题,暂时不能判定超时!
|
CheckRequestTimeout();
|
||||||
// Issue : https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/108#
|
|
||||||
//CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,21 @@
|
||||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
|
using WeChatWASM;
|
||||||
|
|
||||||
internal class WXFSLoadBundleOperation : FSLoadBundleOperation
|
internal class WXFSLoadBundleOperation : FSLoadBundleOperation
|
||||||
{
|
{
|
||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
DownloadAssetBundle,
|
LoadBundleFile,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly WechatFileSystem _fileSystem;
|
private readonly WechatFileSystem _fileSystem;
|
||||||
private readonly PackageBundle _bundle;
|
private readonly PackageBundle _bundle;
|
||||||
private DownloadAssetBundleOperation _downloadAssetBundleOp;
|
private UnityWebRequest _webRequest;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal WXFSLoadBundleOperation(WechatFileSystem fileSystem, PackageBundle bundle)
|
internal WXFSLoadBundleOperation(WechatFileSystem fileSystem, PackageBundle bundle)
|
||||||
|
@ -22,60 +25,69 @@ internal class WXFSLoadBundleOperation : FSLoadBundleOperation
|
||||||
}
|
}
|
||||||
internal override void InternalOnStart()
|
internal override void InternalOnStart()
|
||||||
{
|
{
|
||||||
_steps = ESteps.DownloadAssetBundle;
|
_steps = ESteps.LoadBundleFile;
|
||||||
}
|
}
|
||||||
internal override void InternalOnUpdate()
|
internal override void InternalOnUpdate()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_steps == ESteps.DownloadAssetBundle)
|
if (_steps == ESteps.LoadBundleFile)
|
||||||
{
|
{
|
||||||
if (_downloadAssetBundleOp == null)
|
if (_webRequest == null)
|
||||||
{
|
{
|
||||||
DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
|
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
|
||||||
downloadParam.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName); ;
|
_webRequest = WXAssetBundle.GetAssetBundle(mainURL);
|
||||||
downloadParam.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
_webRequest.SendWebRequest();
|
||||||
|
|
||||||
if (_bundle.Encrypted)
|
|
||||||
{
|
|
||||||
_downloadAssetBundleOp = new DownloadWebEncryptAssetBundleOperation(_fileSystem.DecryptionServices, _bundle, downloadParam);
|
|
||||||
OperationSystem.StartOperation(_fileSystem.PackageName, _downloadAssetBundleOp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_downloadAssetBundleOp = new DownloadWechatAssetBundleOperation(_bundle, downloadParam);
|
|
||||||
OperationSystem.StartOperation(_fileSystem.PackageName, _downloadAssetBundleOp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadProgress = _downloadAssetBundleOp.DownloadProgress;
|
DownloadProgress = _webRequest.downloadProgress;
|
||||||
DownloadedBytes = (long)_downloadAssetBundleOp.DownloadedBytes;
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
Progress = DownloadProgress;
|
Progress = DownloadProgress;
|
||||||
if (_downloadAssetBundleOp.IsDone == false)
|
if (_webRequest.isDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_downloadAssetBundleOp.Status == EOperationStatus.Succeed)
|
if (CheckRequestResult())
|
||||||
{
|
{
|
||||||
var assetBundle = _downloadAssetBundleOp.Result;
|
if (_bundle.Encrypted && _fileSystem.DecryptionServices == 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 = $"The {nameof(IWebDecryptionServices)} is null !";
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AssetBundle assetBundle;
|
||||||
|
var downloadHanlder = _webRequest.downloadHandler as DownloadHandlerWXAssetBundle;
|
||||||
|
if (_bundle.Encrypted)
|
||||||
|
assetBundle = _fileSystem.LoadEncryptedAssetBundle(_bundle, downloadHanlder.data);
|
||||||
|
else
|
||||||
|
assetBundle = downloadHanlder.assetBundle;
|
||||||
|
|
||||||
|
if (assetBundle == null)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Error = $"{nameof(DownloadHandlerWXAssetBundle)} loaded asset bundle is null !";
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Result = new AssetBundleResult(_fileSystem, _bundle, assetBundle, null);
|
Result = new WXAssetBundleResult(_fileSystem, _bundle, assetBundle);
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
|
|
||||||
|
//TODO 解决微信小游戏插件问题
|
||||||
|
// Issue : https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/108#
|
||||||
|
DownloadProgress = 1f;
|
||||||
|
DownloadedBytes = _bundle.FileSize;
|
||||||
|
Progress = 1f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _downloadAssetBundleOp.Error;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,11 +103,31 @@ internal class WXFSLoadBundleOperation : FSLoadBundleOperation
|
||||||
}
|
}
|
||||||
public override void AbortDownloadOperation()
|
public override void AbortDownloadOperation()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.DownloadAssetBundle)
|
}
|
||||||
|
|
||||||
|
private bool CheckRequestResult()
|
||||||
|
{
|
||||||
|
#if UNITY_2020_3_OR_NEWER
|
||||||
|
if (_webRequest.result != UnityWebRequest.Result.Success)
|
||||||
{
|
{
|
||||||
if (_downloadAssetBundleOp != null)
|
Error = _webRequest.error;
|
||||||
_downloadAssetBundleOp.SetAbort();
|
return false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (_webRequest.isNetworkError || _webRequest.isHttpError)
|
||||||
|
{
|
||||||
|
Error = _webRequest.error;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -1,129 +0,0 @@
|
||||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Networking;
|
|
||||||
using WeChatWASM;
|
|
||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
internal class DownloadWechatAssetBundleOperation : DownloadAssetBundleOperation
|
|
||||||
{
|
|
||||||
private ESteps _steps = ESteps.None;
|
|
||||||
|
|
||||||
internal DownloadWechatAssetBundleOperation(PackageBundle bundle, DownloadParam param) : base(bundle, param)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
internal override void InternalOnStart()
|
|
||||||
{
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
}
|
|
||||||
internal override void InternalOnUpdate()
|
|
||||||
{
|
|
||||||
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 InternalOnAbort()
|
|
||||||
{
|
|
||||||
_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
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: e556be3f274429e4ca6c542fff90e6ab
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
Loading…
Reference in New Issue