mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-19 06:40:21 +00:00
update file system
This commit is contained in:
@@ -5,21 +5,22 @@ namespace YooAsset
|
||||
{
|
||||
internal class DCFSLoadAssetBundleOperation : FSLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckExist,
|
||||
DownloadFile,
|
||||
LoadAssetBundle,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultCacheFileSystem _fileSystem;
|
||||
private readonly PackageBundle _bundle;
|
||||
private FSDownloadFileOperation _downloadFileOp;
|
||||
private AssetBundleCreateRequest _createRequest;
|
||||
private bool _isWaitForAsyncComplete = false;
|
||||
private ESteps _steps = ESteps.None;
|
||||
protected readonly DefaultCacheFileSystem _fileSystem;
|
||||
protected readonly PackageBundle _bundle;
|
||||
protected FSDownloadFileOperation _downloadFileOp;
|
||||
protected AssetBundleCreateRequest _createRequest;
|
||||
protected bool _isWaitForAsyncComplete = false;
|
||||
protected ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal DCFSLoadAssetBundleOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle)
|
||||
@@ -29,29 +30,33 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
if (_fileSystem.NeedDownload(_bundle))
|
||||
{
|
||||
_steps = ESteps.DownloadFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _bundle.FileSize;
|
||||
_steps = ESteps.LoadAssetBundle;
|
||||
}
|
||||
_steps = ESteps.CheckExist;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckExist)
|
||||
{
|
||||
if (_fileSystem.Exists(_bundle))
|
||||
{
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _bundle.FileSize;
|
||||
_steps = ESteps.LoadAssetBundle;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.DownloadFile;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadFile)
|
||||
{
|
||||
if (_downloadFileOp == null)
|
||||
{
|
||||
int failedTryAgain = int.MaxValue;
|
||||
int timeout = 60;
|
||||
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, null, failedTryAgain, timeout);
|
||||
DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
|
||||
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, downloadParam);
|
||||
}
|
||||
|
||||
DownloadProgress = _downloadFileOp.DownloadProgress;
|
||||
@@ -67,7 +72,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloadFileOp.Error;
|
||||
Error = _downloadFileOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,14 +111,14 @@ namespace YooAsset
|
||||
if (Result != null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:当缓存文件的校验等级为Low的时候,并不能保证缓存文件的完整性。
|
||||
// 说明:在AssetBundle文件加载失败的情况下,我们需要重新验证文件的完整性!
|
||||
EFileVerifyResult result = _fileSystem.VerifyCacheFile(_bundle);
|
||||
if (result == EFileVerifyResult.Succeed)
|
||||
EFileVerifyResult verifyResult = _fileSystem.VerifyCacheFile(_bundle);
|
||||
if (verifyResult == EFileVerifyResult.Succeed)
|
||||
{
|
||||
// 注意:在安卓移动平台,华为和三星真机上有极小概率加载资源包失败。
|
||||
// 说明:大多数情况在首次安装下载资源到沙盒内,游戏过程中切换到后台再回到游戏内有很大概率触发!
|
||||
@@ -126,20 +131,20 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load assetBundle from memory : {_bundle.BundleName}";
|
||||
Error = $"Failed to load assetBundle from memory : {_bundle.BundleName}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to read assetBundle file bytes : {_bundle.BundleName}";
|
||||
Error = $"Failed to read assetBundle file bytes : {_bundle.BundleName}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
@@ -148,7 +153,7 @@ namespace YooAsset
|
||||
_steps = ESteps.Done;
|
||||
_fileSystem.DeleteCacheFile(_bundle.BundleGUID);
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Find corrupted file and delete the file : {_bundle.BundleName}";
|
||||
Error = $"Find corrupted file and delete the file : {_bundle.BundleName}";
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
@@ -193,19 +198,20 @@ namespace YooAsset
|
||||
|
||||
internal class DCFSLoadRawBundleOperation : FSLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckExist,
|
||||
DownloadFile,
|
||||
LoadRawBundle,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultCacheFileSystem _fileSystem;
|
||||
private readonly PackageBundle _bundle;
|
||||
private FSDownloadFileOperation _downloadFileOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
protected readonly DefaultCacheFileSystem _fileSystem;
|
||||
protected readonly PackageBundle _bundle;
|
||||
protected FSDownloadFileOperation _downloadFileOp;
|
||||
protected ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal DCFSLoadRawBundleOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle)
|
||||
@@ -215,29 +221,33 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
if (_fileSystem.NeedDownload(_bundle))
|
||||
{
|
||||
_steps = ESteps.DownloadFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _bundle.FileSize;
|
||||
_steps = ESteps.LoadRawBundle;
|
||||
}
|
||||
_steps = ESteps.CheckExist;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckExist)
|
||||
{
|
||||
if (_fileSystem.Exists(_bundle))
|
||||
{
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _bundle.FileSize;
|
||||
_steps = ESteps.LoadRawBundle;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.DownloadFile;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadFile)
|
||||
{
|
||||
if (_downloadFileOp == null)
|
||||
{
|
||||
int failedTryAgain = int.MaxValue;
|
||||
int timeout = 60;
|
||||
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, null, failedTryAgain, timeout);
|
||||
DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
|
||||
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, downloadParam);
|
||||
}
|
||||
|
||||
DownloadProgress = _downloadFileOp.DownloadProgress;
|
||||
@@ -253,7 +263,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _downloadFileOp.Error;
|
||||
Error = _downloadFileOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,20 +282,20 @@ namespace YooAsset
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Can not found raw bundle file : {filePath}";
|
||||
Error = $"Can not found cache raw bundle file : {filePath}";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed load raw bundle file : {_bundle.BundleName}";
|
||||
Error = $"Failed to load cache raw bundle file : {_bundle.BundleName}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user