update mini game sample

This commit is contained in:
何冠峰
2025-07-21 15:52:51 +08:00
parent 9f09b6c526
commit b2776b933a
5 changed files with 27 additions and 31 deletions

View File

@@ -15,7 +15,7 @@ internal class TTFSDownloadFileOperation : FSDownloadFileOperation
private readonly TiktokFileSystem _fileSystem; private readonly TiktokFileSystem _fileSystem;
private readonly DownloadFileOptions _options; private readonly DownloadFileOptions _options;
private UnityWebCacheRequestOperation _unityWebCacheRequestOp; private UnityWebCacheRequestOperation _webCacheRequestOp;
private int _requestCount = 0; private int _requestCount = 0;
private float _tryAgainTimer; private float _tryAgainTimer;
private int _failedTryAgain; private int _failedTryAgain;
@@ -36,21 +36,23 @@ internal class TTFSDownloadFileOperation : FSDownloadFileOperation
if (_steps == ESteps.CreateRequest) if (_steps == ESteps.CreateRequest)
{ {
string url = GetRequestURL(); string url = GetRequestURL();
_unityWebCacheRequestOp = new UnityWebCacheRequestOperation(url); _webCacheRequestOp = new UnityWebCacheRequestOperation(url);
_unityWebCacheRequestOp.StartOperation(); _webCacheRequestOp.StartOperation();
AddChildOperation(_webCacheRequestOp);
_steps = ESteps.CheckRequest; _steps = ESteps.CheckRequest;
} }
// 检测下载结果 // 检测下载结果
if (_steps == ESteps.CheckRequest) if (_steps == ESteps.CheckRequest)
{ {
Progress = _unityWebCacheRequestOp.Progress; _webCacheRequestOp.UpdateOperation();
DownloadProgress = _unityWebCacheRequestOp.DownloadProgress; Progress = _webCacheRequestOp.Progress;
DownloadedBytes = (long)_unityWebCacheRequestOp.DownloadedBytes; DownloadProgress = _webCacheRequestOp.DownloadProgress;
if (_unityWebCacheRequestOp.IsDone == false) DownloadedBytes = (long)_webCacheRequestOp.DownloadedBytes;
if (_webCacheRequestOp.IsDone == false)
return; return;
if (_unityWebCacheRequestOp.Status == EOperationStatus.Succeed) if (_webCacheRequestOp.Status == EOperationStatus.Succeed)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
@@ -65,13 +67,13 @@ internal class TTFSDownloadFileOperation : FSDownloadFileOperation
if (_failedTryAgain > 0) if (_failedTryAgain > 0)
{ {
_steps = ESteps.TryAgain; _steps = ESteps.TryAgain;
YooLogger.Warning($"Failed download : {_unityWebCacheRequestOp.URL} Try again !"); YooLogger.Warning($"Failed download : {_webCacheRequestOp.URL} Try again !");
} }
else else
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _unityWebCacheRequestOp.Error; Error = _webCacheRequestOp.Error;
YooLogger.Error(Error); YooLogger.Error(Error);
} }
} }

View File

@@ -54,9 +54,9 @@ internal class TTFSLoadBundleOperation : FSLoadBundleOperation
} }
_loadWebAssetBundleOp.UpdateOperation(); _loadWebAssetBundleOp.UpdateOperation();
Progress = _loadWebAssetBundleOp.Progress;
DownloadProgress = _loadWebAssetBundleOp.DownloadProgress; DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
DownloadedBytes = (long)_loadWebAssetBundleOp.DownloadedBytes; DownloadedBytes = (long)_loadWebAssetBundleOp.DownloadedBytes;
Progress = DownloadProgress;
if (_loadWebAssetBundleOp.IsDone == false) if (_loadWebAssetBundleOp.IsDone == false)
return; return;

View File

@@ -15,7 +15,7 @@ internal class WXFSDownloadFileOperation : FSDownloadFileOperation
private readonly WechatFileSystem _fileSystem; private readonly WechatFileSystem _fileSystem;
private readonly DownloadFileOptions _options; private readonly DownloadFileOptions _options;
private UnityWebCacheRequestOperation _unityWebCacheRequestOp; private UnityWebCacheRequestOperation _webCacheRequestOp;
private int _requestCount = 0; private int _requestCount = 0;
private float _tryAgainTimer; private float _tryAgainTimer;
private int _failedTryAgain; private int _failedTryAgain;
@@ -36,24 +36,24 @@ internal class WXFSDownloadFileOperation : FSDownloadFileOperation
if (_steps == ESteps.CreateRequest) if (_steps == ESteps.CreateRequest)
{ {
string url = GetRequestURL(); string url = GetRequestURL();
_unityWebCacheRequestOp = new UnityWebCacheRequestOperation(url); _webCacheRequestOp = new UnityWebCacheRequestOperation(url);
_unityWebCacheRequestOp.SetRequestHeader("wechatminigame-preload", "1"); _webCacheRequestOp.SetRequestHeader("wechatminigame-preload", "1");
_unityWebCacheRequestOp.StartOperation(); _webCacheRequestOp.StartOperation();
AddChildOperation(_unityWebCacheRequestOp); AddChildOperation(_webCacheRequestOp);
_steps = ESteps.CheckRequest; _steps = ESteps.CheckRequest;
} }
// 检测下载结果 // 检测下载结果
if (_steps == ESteps.CheckRequest) if (_steps == ESteps.CheckRequest)
{ {
_unityWebCacheRequestOp.UpdateOperation(); _webCacheRequestOp.UpdateOperation();
Progress = _unityWebCacheRequestOp.Progress; Progress = _webCacheRequestOp.Progress;
DownloadProgress = _unityWebCacheRequestOp.DownloadProgress; DownloadProgress = _webCacheRequestOp.DownloadProgress;
DownloadedBytes = (long)_unityWebCacheRequestOp.DownloadedBytes; DownloadedBytes = (long)_webCacheRequestOp.DownloadedBytes;
if (_unityWebCacheRequestOp.IsDone == false) if (_webCacheRequestOp.IsDone == false)
return; return;
if (_unityWebCacheRequestOp.Status == EOperationStatus.Succeed) if (_webCacheRequestOp.Status == EOperationStatus.Succeed)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
@@ -69,13 +69,13 @@ internal class WXFSDownloadFileOperation : FSDownloadFileOperation
if (_failedTryAgain > 0) if (_failedTryAgain > 0)
{ {
_steps = ESteps.TryAgain; _steps = ESteps.TryAgain;
YooLogger.Warning($"Failed download : {_unityWebCacheRequestOp.URL} Try again !"); YooLogger.Warning($"Failed download : {_webCacheRequestOp.URL} Try again !");
} }
else else
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _unityWebCacheRequestOp.Error; Error = _webCacheRequestOp.Error;
YooLogger.Error(Error); YooLogger.Error(Error);
} }
} }

View File

@@ -53,9 +53,9 @@ internal class WXFSLoadBundleOperation : FSLoadBundleOperation
} }
_loadWebAssetBundleOp.UpdateOperation(); _loadWebAssetBundleOp.UpdateOperation();
Progress = _loadWebAssetBundleOp.Progress;
DownloadProgress = _loadWebAssetBundleOp.DownloadProgress; DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
DownloadedBytes = (long)_loadWebAssetBundleOp.DownloadedBytes; DownloadedBytes = (long)_loadWebAssetBundleOp.DownloadedBytes;
Progress = DownloadProgress;
if (_loadWebAssetBundleOp.IsDone == false) if (_loadWebAssetBundleOp.IsDone == false)
return; return;

View File

@@ -96,12 +96,6 @@ namespace YooAsset
} }
} }
} }
internal override void InternalAbort()
{
_steps = ESteps.Done;
if (_unityWechatAssetBundleRequestOp != null)
_unityWechatAssetBundleRequestOp.AbortOperation();
}
/// <summary> /// <summary>
/// 获取网络请求地址 /// 获取网络请求地址