update file system

This commit is contained in:
何冠峰
2025-07-21 15:52:07 +08:00
parent 01f6103b48
commit 9f09b6c526
9 changed files with 54 additions and 96 deletions

View File

@@ -17,7 +17,7 @@ namespace YooAsset
private readonly DefaultBuildinFileSystem _fileSystem; private readonly DefaultBuildinFileSystem _fileSystem;
private CopyBuildinPackageManifestOperation _copyBuildinPackageManifestOp; private CopyBuildinPackageManifestOperation _copyBuildinPackageManifestOp;
private FSInitializeFileSystemOperation _initUnpackFIleSystemOp; private FSInitializeFileSystemOperation _initUnpackFIleSystemOp;
private LoadBuildinCatalogFileOperation _loadCatalogFileOp; private LoadBuildinCatalogFileOperation _loadBuildinCatalogFileOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal DBFSInitializeOperation(DefaultBuildinFileSystem fileSystem) internal DBFSInitializeOperation(DefaultBuildinFileSystem fileSystem)
@@ -103,34 +103,18 @@ namespace YooAsset
if (_steps == ESteps.LoadCatalogFile) if (_steps == ESteps.LoadCatalogFile)
{ {
if (_loadCatalogFileOp == null) if (_loadBuildinCatalogFileOp == null)
{ {
#if UNITY_EDITOR _loadBuildinCatalogFileOp = new LoadBuildinCatalogFileOperation(_fileSystem);
/* _loadBuildinCatalogFileOp.StartOperation();
// 兼容性初始化 AddChildOperation(_loadBuildinCatalogFileOp);
// 说明:内置文件系统在编辑器下运行时需要动态生成
string packageRoot = _fileSystem.FileRoot;
bool result = DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.ManifestServices, _fileSystem.PackageName, packageRoot);
if (result == false)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Create package catalog file failed ! See the detail error in console !";
return;
}
*/
#endif
_loadCatalogFileOp = new LoadBuildinCatalogFileOperation(_fileSystem);
_loadCatalogFileOp.StartOperation();
AddChildOperation(_loadCatalogFileOp);
} }
_loadCatalogFileOp.UpdateOperation(); _loadBuildinCatalogFileOp.UpdateOperation();
if (_loadCatalogFileOp.IsDone == false) if (_loadBuildinCatalogFileOp.IsDone == false)
return; return;
if (_loadCatalogFileOp.Status == EOperationStatus.Succeed) if (_loadBuildinCatalogFileOp.Status == EOperationStatus.Succeed)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
@@ -139,7 +123,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _loadCatalogFileOp.Error; Error = _loadBuildinCatalogFileOp.Error;
} }
} }
} }

View File

@@ -104,27 +104,28 @@ namespace YooAsset
} }
} }
if (_assetBundle != null) if (_assetBundle == null)
{ {
_steps = ESteps.Done; if (_bundle.Encrypted)
Result = new AssetBundleResult(_fileSystem, _bundle, _assetBundle, _managedStream); {
Status = EOperationStatus.Succeed; _steps = ESteps.Done;
return; Status = EOperationStatus.Failed;
} Error = $"Failed to load encrypted buildin asset bundle file : {_bundle.BundleName}";
YooLogger.Error(Error);
if (_bundle.Encrypted) }
{ else
_steps = ESteps.Done; {
Status = EOperationStatus.Failed; _steps = ESteps.Done;
Error = $"Failed to load encrypted buildin asset bundle file : {_bundle.BundleName}"; Status = EOperationStatus.Failed;
YooLogger.Error(Error); Error = $"Failed to load buildin asset bundle file : {_bundle.BundleName}";
YooLogger.Error(Error);
}
} }
else else
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Result = new AssetBundleResult(_fileSystem, _bundle, _assetBundle, _managedStream);
Error = $"Failed to load buildin asset bundle file : {_bundle.BundleName}"; Status = EOperationStatus.Succeed;
YooLogger.Error(Error);
} }
} }
} }
@@ -176,13 +177,15 @@ namespace YooAsset
if (_steps == ESteps.LoadBuildinRawBundle) if (_steps == ESteps.LoadBuildinRawBundle)
{ {
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
#if UNITY_ANDROID #if UNITY_ANDROID
//TODO : 安卓平台内置文件属于APK压缩包内的文件。 //TODO : 安卓平台内置文件属于APK压缩包内的文件。
_steps = ESteps.Done; _steps = ESteps.Done;
Result = new RawBundleResult(_fileSystem, _bundle); Status = EOperationStatus.Failed;
Status = EOperationStatus.Succeed; Error = $"Can not load android buildin raw bundle file : {filePath}";
YooLogger.Error(Error);
#else #else
string filePath = _fileSystem.GetBuildinFileLoadPath(_bundle);
if (File.Exists(filePath)) if (File.Exists(filePath))
{ {
_steps = ESteps.Done; _steps = ESteps.Done;

View File

@@ -20,8 +20,8 @@ namespace YooAsset
private readonly DefaultBuildinFileSystem _fileSystem; private readonly DefaultBuildinFileSystem _fileSystem;
private RequestBuildinPackageVersionOperation _requestBuildinPackageVersionOp; private RequestBuildinPackageVersionOperation _requestBuildinPackageVersionOp;
private UnityWebFileRequestOperation _hashFileRequestOp; private UnityWebFileRequestOperation _hashWebFileRequestOp;
private UnityWebFileRequestOperation _manifestFileRequestOp; private UnityWebFileRequestOperation _manifestWebFileRequestOp;
private string _buildinPackageVersion; private string _buildinPackageVersion;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
@@ -78,21 +78,21 @@ namespace YooAsset
if (_steps == ESteps.UnpackHashFile) if (_steps == ESteps.UnpackHashFile)
{ {
if (_hashFileRequestOp == null) if (_hashWebFileRequestOp == null)
{ {
string sourcePath = _fileSystem.GetBuildinPackageHashFilePath(_buildinPackageVersion); string sourcePath = _fileSystem.GetBuildinPackageHashFilePath(_buildinPackageVersion);
string destPath = GetCopyPackageHashDestPath(_buildinPackageVersion); string destPath = GetCopyPackageHashDestPath(_buildinPackageVersion);
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath); string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
_hashFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60); _hashWebFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60);
_hashFileRequestOp.StartOperation(); _hashWebFileRequestOp.StartOperation();
AddChildOperation(_hashFileRequestOp); AddChildOperation(_hashWebFileRequestOp);
} }
_hashFileRequestOp.UpdateOperation(); _hashWebFileRequestOp.UpdateOperation();
if (_hashFileRequestOp.IsDone == false) if (_hashWebFileRequestOp.IsDone == false)
return; return;
if (_hashFileRequestOp.Status == EOperationStatus.Succeed) if (_hashWebFileRequestOp.Status == EOperationStatus.Succeed)
{ {
_steps = ESteps.CheckManifestFile; _steps = ESteps.CheckManifestFile;
} }
@@ -100,7 +100,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _hashFileRequestOp.Error; Error = _hashWebFileRequestOp.Error;
} }
} }
@@ -119,21 +119,21 @@ namespace YooAsset
if (_steps == ESteps.UnpackManifestFile) if (_steps == ESteps.UnpackManifestFile)
{ {
if (_manifestFileRequestOp == null) if (_manifestWebFileRequestOp == null)
{ {
string sourcePath = _fileSystem.GetBuildinPackageManifestFilePath(_buildinPackageVersion); string sourcePath = _fileSystem.GetBuildinPackageManifestFilePath(_buildinPackageVersion);
string destPath = GetCopyPackageManifestDestPath(_buildinPackageVersion); string destPath = GetCopyPackageManifestDestPath(_buildinPackageVersion);
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath); string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
_manifestFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60); _manifestWebFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60);
_manifestFileRequestOp.StartOperation(); _manifestWebFileRequestOp.StartOperation();
AddChildOperation(_manifestFileRequestOp); AddChildOperation(_manifestWebFileRequestOp);
} }
_manifestFileRequestOp.UpdateOperation(); _manifestWebFileRequestOp.UpdateOperation();
if (_manifestFileRequestOp.IsDone == false) if (_manifestWebFileRequestOp.IsDone == false)
return; return;
if (_manifestFileRequestOp.Status == EOperationStatus.Succeed) if (_manifestWebFileRequestOp.Status == EOperationStatus.Succeed)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
@@ -142,7 +142,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = _manifestFileRequestOp.Error; Error = _manifestWebFileRequestOp.Error;
} }
} }
} }

View File

@@ -67,7 +67,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"{nameof(LoadWebAssetBundleOperation)} loaded asset bundle is null !"; Error = $"{nameof(DWRFSLoadAssetBundleOperation)} loaded asset bundle is null !";
} }
else else
{ {

View File

@@ -32,22 +32,6 @@ namespace YooAsset
{ {
if (_loadCatalogFileOp == null) if (_loadCatalogFileOp == null)
{ {
#if UNITY_EDITOR
/*
// 兼容性初始化
// 说明:内置文件系统在编辑器下运行时需要动态生成
string packageRoot = _fileSystem.FileRoot;
bool result = DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.ManifestServices, _fileSystem.PackageName, packageRoot);
if (result == false)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Create package catalog file failed ! See the detail error in console !";
return;
}
*/
#endif
_loadCatalogFileOp = new LoadWebServerCatalogFileOperation(_fileSystem, 60); _loadCatalogFileOp = new LoadWebServerCatalogFileOperation(_fileSystem, 60);
_loadCatalogFileOp.StartOperation(); _loadCatalogFileOp.StartOperation();
AddChildOperation(_loadCatalogFileOp); AddChildOperation(_loadCatalogFileOp);

View File

@@ -67,7 +67,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"{nameof(LoadWebAssetBundleOperation)} loaded asset bundle is null !"; Error = $"{nameof(DWSFSLoadAssetBundleOperation)} loaded asset bundle is null !";
} }
else else
{ {

View File

@@ -1,7 +1,4 @@
using System; using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {

View File

@@ -13,10 +13,10 @@ namespace YooAsset
Done, Done,
} }
private UnityWebDataRequestOperation _unityWebDataRequestOp;
private readonly PackageBundle _bundle; private readonly PackageBundle _bundle;
private readonly DownloadFileOptions _options; private readonly DownloadFileOptions _options;
private readonly IWebDecryptionServices _decryptionServices; private readonly IWebDecryptionServices _decryptionServices;
private UnityWebDataRequestOperation _unityWebDataRequestOp;
protected int _requestCount = 0; protected int _requestCount = 0;
protected float _tryAgainTimer; protected float _tryAgainTimer;
@@ -53,6 +53,7 @@ namespace YooAsset
string url = GetRequestURL(); string url = GetRequestURL();
_unityWebDataRequestOp = new UnityWebDataRequestOperation(url, 0); _unityWebDataRequestOp = new UnityWebDataRequestOperation(url, 0);
_unityWebDataRequestOp.StartOperation(); _unityWebDataRequestOp.StartOperation();
AddChildOperation(_unityWebDataRequestOp);
_steps = ESteps.CheckRequest; _steps = ESteps.CheckRequest;
} }
@@ -115,12 +116,6 @@ namespace YooAsset
} }
} }
} }
internal override void InternalAbort()
{
_steps = ESteps.Done;
if (_unityWebDataRequestOp != null)
_unityWebDataRequestOp.AbortOperation();
}
/// <summary> /// <summary>
/// 加载加密资源文件 /// 加载加密资源文件

View File

@@ -45,6 +45,7 @@ namespace YooAsset
string url = GetRequestURL(); string url = GetRequestURL();
_unityAssetBundleRequestOp = new UnityAssetBundleRequestOperation(_bundle, _disableUnityWebCache, url); _unityAssetBundleRequestOp = new UnityAssetBundleRequestOperation(_bundle, _disableUnityWebCache, url);
_unityAssetBundleRequestOp.StartOperation(); _unityAssetBundleRequestOp.StartOperation();
AddChildOperation(_unityAssetBundleRequestOp);
_steps = ESteps.CheckRequest; _steps = ESteps.CheckRequest;
} }
@@ -96,12 +97,6 @@ namespace YooAsset
} }
} }
} }
internal override void InternalAbort()
{
_steps = ESteps.Done;
if (_unityAssetBundleRequestOp != null)
_unityAssetBundleRequestOp.AbortOperation();
}
/// <summary> /// <summary>
/// 获取网络请求地址 /// 获取网络请求地址