update file system

This commit is contained in:
何冠峰
2024-07-05 19:29:34 +08:00
parent b151f968d7
commit a9e5e7fdd3
21 changed files with 350 additions and 513 deletions
@@ -7,13 +7,12 @@ namespace YooAsset
{
None,
DownloadFile,
CheckResult,
Done,
}
private readonly DefaultWebFileSystem _fileSystem;
private readonly PackageBundle _bundle;
private DWFSDownloadWebFileOperation _downloadWebFileOp;
private DownloadHandlerAssetBundleOperation _downloadhanlderAssetBundleOp;
private ESteps _steps = ESteps.None;
@@ -33,32 +32,32 @@ namespace YooAsset
if (_steps == ESteps.DownloadFile)
{
if (_downloadWebFileOp == null)
if (_downloadhanlderAssetBundleOp == null)
{
int failedTryAgain = int.MaxValue;
int timeout = 60;
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
_downloadWebFileOp = new DWFSDownloadWebFileOperation(_fileSystem, _bundle, mainURL, fallbackURL, failedTryAgain, timeout);
_downloadhanlderAssetBundleOp = new DownloadHandlerAssetBundleOperation(_fileSystem, _bundle, mainURL, fallbackURL, failedTryAgain, timeout);
}
DownloadProgress = _downloadWebFileOp.DownloadProgress;
DownloadedBytes = _downloadWebFileOp.DownloadedBytes;
Progress = _downloadWebFileOp.Progress;
if (_downloadWebFileOp.IsDone == false)
DownloadProgress = _downloadhanlderAssetBundleOp.DownloadProgress;
DownloadedBytes = _downloadhanlderAssetBundleOp.DownloadedBytes;
Progress = _downloadhanlderAssetBundleOp.Progress;
if (_downloadhanlderAssetBundleOp.IsDone == false)
return;
if (_downloadWebFileOp.Status == EOperationStatus.Succeed)
if (_downloadhanlderAssetBundleOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Result = _downloadWebFileOp.Result;
Result = _downloadhanlderAssetBundleOp.Result;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloadWebFileOp.Error;
Error = _downloadhanlderAssetBundleOp.Error;
}
}
}
@@ -77,8 +76,8 @@ namespace YooAsset
{
if (_steps == ESteps.DownloadFile)
{
if (_downloadWebFileOp != null)
_downloadWebFileOp.SetAbort();
if (_downloadhanlderAssetBundleOp != null)
_downloadhanlderAssetBundleOp.SetAbort();
}
}
}
@@ -1,22 +1,19 @@
using System.IO;
using UnityEngine;
using UnityEngine;
using UnityEngine.Networking;
namespace YooAsset
{
internal class DWFSDownloadWebFileOperation : DefaultDownloadFileOperation
internal class DownloadHandlerAssetBundleOperation : DefaultDownloadFileOperation
{
private readonly DefaultWebFileSystem _fileSystem;
private DownloadHandlerAssetBundle _downloadhandler;
private ESteps _steps = ESteps.None;
/// <summary>
/// 下载结果
/// </summary>
public AssetBundle Result { private set; get; }
internal DWFSDownloadWebFileOperation(DefaultWebFileSystem fileSystem, PackageBundle bundle, string mainURL, string fallbackURL, int failedTryAgain, int timeout)
internal DownloadHandlerAssetBundleOperation(DefaultWebFileSystem fileSystem, PackageBundle bundle,
string mainURL, string fallbackURL, int failedTryAgain, int timeout)
: base(bundle, mainURL, fallbackURL, failedTryAgain, timeout)
{
_fileSystem = fileSystem;
@@ -37,16 +34,7 @@ namespace YooAsset
_requestURL = GetRequestURL();
// 重置变量
_isAbort = false;
_latestDownloadBytes = 0;
_latestDownloadRealtime = Time.realtimeSinceStartup;
DownloadProgress = 0f;
DownloadedBytes = 0;
// 重置计时器
if (_tryAgainTimer > 0f)
YooLogger.Warning($"Try again download : {_requestURL}");
_tryAgainTimer = 0f;
ResetRequestFiled();
// 创建下载器
CreateWebRequest();
@@ -110,11 +98,21 @@ namespace YooAsset
private void CreateWebRequest()
{
_downloadhandler = CreateDownloadHandler();
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
_webRequest.downloadHandler = CreateDownloadHandler();
_webRequest.downloadHandler = _downloadhandler;
_webRequest.disposeDownloadHandlerOnDispose = true;
_webRequest.SendWebRequest();
}
private void DisposeWebRequest()
{
if (_webRequest != null)
{
//注意:引擎底层会自动调用Abort方法
_webRequest.Dispose();
_webRequest = null;
}
}
private DownloadHandlerAssetBundle CreateDownloadHandler()
{
if (_fileSystem.DisableUnityWebCache)
@@ -138,14 +136,5 @@ namespace YooAsset
return downloadhandler;
}
}
private void DisposeWebRequest()
{
if (_webRequest != null)
{
//注意:引擎底层会自动调用Abort方法
_webRequest.Dispose();
_webRequest = null;
}
}
}
}
@@ -60,7 +60,7 @@ namespace YooAsset
foreach (var wrapper in catalog.Wrappers)
{
var fileWrapper = new DefaultWebFileSystem.FileWrapper(wrapper.FileName);
_fileSystem.Record(wrapper.BundleGUID, fileWrapper);
_fileSystem.RecordFile(wrapper.BundleGUID, fileWrapper);
}
YooLogger.Log($"Package '{_fileSystem.PackageName}' catalog files count : {catalog.Wrappers.Count}");