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

View File

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

View File

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

View File

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

View File

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