update file system
统一所有PlayMode的初始化行为
This commit is contained in:
+7
-8
@@ -106,19 +106,13 @@ namespace YooAsset
|
||||
}
|
||||
public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var operation = new DBFSInitializeInEditorPlayModeOperation(this);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
#else
|
||||
var operation = new DBFSInitializeOperation(this);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
#endif
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
||||
{
|
||||
var operation = new DBFSLoadPackageManifestOperation(this);
|
||||
var operation = new DBFSLoadPackageManifestOperation(this, packageVersion);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
@@ -311,7 +305,12 @@ namespace YooAsset
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
|
||||
return PathUtility.Combine(FileRoot, fileName);
|
||||
}
|
||||
|
||||
public string GetStreamingAssetsPackageRoot()
|
||||
{
|
||||
string rootPath = PathUtility.Combine(Application.dataPath, "StreamingAssets", YooAssetSettingsData.Setting.DefaultYooFolderName);
|
||||
return PathUtility.Combine(rootPath, PackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录文件信息
|
||||
/// </summary>
|
||||
|
||||
+7
-3
@@ -24,7 +24,7 @@ namespace YooAsset
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
|
||||
if (rootDirectory.Exists == false)
|
||||
{
|
||||
Debug.LogWarning($"Can not found buildin root folder : {rootPath}");
|
||||
Debug.LogWarning($"Can not found StreamingAssets root directory : {rootPath}");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -32,10 +32,14 @@ namespace YooAsset
|
||||
DirectoryInfo[] subDirectories = rootDirectory.GetDirectories();
|
||||
foreach (var subDirectory in subDirectories)
|
||||
{
|
||||
CreateBuildinManifest(subDirectory.Name, subDirectory.FullName);
|
||||
CreateBuildinCatalogFile(subDirectory.Name, subDirectory.FullName);
|
||||
}
|
||||
}
|
||||
private void CreateBuildinManifest(string packageName, string pacakgeDirectory)
|
||||
|
||||
/// <summary>
|
||||
/// 生成包裹的内置资源目录文件
|
||||
/// </summary>
|
||||
public static void CreateBuildinCatalogFile(string packageName, string pacakgeDirectory)
|
||||
{
|
||||
// 获取资源清单版本
|
||||
string packageVersion;
|
||||
|
||||
+7
-106
@@ -56,6 +56,13 @@ namespace YooAsset
|
||||
{
|
||||
if (_loadCatalogFileOp == null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 兼容性初始化
|
||||
// 说明:内置文件系统在编辑器下运行时需要动态生成
|
||||
string packageRoot = _fileSystem.GetStreamingAssetsPackageRoot();
|
||||
DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.PackageName, packageRoot);
|
||||
#endif
|
||||
|
||||
_loadCatalogFileOp = new LoadBuildinCatalogFileOperation(_fileSystem);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _loadCatalogFileOp);
|
||||
}
|
||||
@@ -77,110 +84,4 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在编辑器下离线模式的兼容性初始化
|
||||
/// </summary>
|
||||
internal sealed class DBFSInitializeInEditorPlayModeOperation : FSInitializeFileSystemOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
InitUnpackFileSystem,
|
||||
LoadPackageManifest,
|
||||
RecordFiles,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private FSInitializeFileSystemOperation _initUnpackFIleSystemOp;
|
||||
private DBFSLoadPackageManifestOperation _loadPackageManifestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal DBFSInitializeInEditorPlayModeOperation(DefaultBuildinFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.InitUnpackFileSystem;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.InitUnpackFileSystem)
|
||||
{
|
||||
if (_initUnpackFIleSystemOp == null)
|
||||
_initUnpackFIleSystemOp = _fileSystem.InitializeUpackFileSystem();
|
||||
|
||||
Progress = _initUnpackFIleSystemOp.Progress;
|
||||
if (_initUnpackFIleSystemOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_initUnpackFIleSystemOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadPackageManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _initUnpackFIleSystemOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadPackageManifest)
|
||||
{
|
||||
if (_loadPackageManifestOp == null)
|
||||
{
|
||||
_loadPackageManifestOp = new DBFSLoadPackageManifestOperation(_fileSystem);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _loadPackageManifestOp);
|
||||
}
|
||||
|
||||
if (_loadPackageManifestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.RecordFiles;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _loadPackageManifestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.RecordFiles)
|
||||
{
|
||||
PackageManifest manifest = _loadPackageManifestOp.Manifest;
|
||||
string pacakgeDirectory = _fileSystem.FileRoot;
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(pacakgeDirectory);
|
||||
FileInfo[] fileInfos = rootDirectory.GetFiles();
|
||||
foreach (var fileInfo in fileInfos)
|
||||
{
|
||||
if (fileInfo.Extension == ".meta" || fileInfo.Extension == ".version" ||
|
||||
fileInfo.Extension == ".hash" || fileInfo.Extension == ".bytes")
|
||||
continue;
|
||||
|
||||
string fileName = fileInfo.Name;
|
||||
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle value))
|
||||
{
|
||||
var fileWrapper = new DefaultBuildinFileSystem.FileWrapper(fileName);
|
||||
_fileSystem.RecordFile(value.BundleGUID, fileWrapper);
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Failed to mapping buildin bundle file : {fileName}");
|
||||
}
|
||||
}
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-31
@@ -6,61 +6,37 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestBuildinPackageVersion,
|
||||
RequestBuildinPackageHash,
|
||||
LoadBuildinPackageManifest,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private RequestBuildinPackageVersionOperation _requestBuildinPackageVersionOp;
|
||||
private readonly string _packageVersion;
|
||||
private RequestBuildinPackageHashOperation _requestBuildinPackageHashOp;
|
||||
private LoadBuildinPackageManifestOperation _loadBuildinPackageManifestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
public DBFSLoadPackageManifestOperation(DefaultBuildinFileSystem fileSystem)
|
||||
public DBFSLoadPackageManifestOperation(DefaultBuildinFileSystem fileSystem, string packageVersion)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_packageVersion = packageVersion;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_steps = ESteps.RequestBuildinPackageVersion;
|
||||
_steps = ESteps.RequestBuildinPackageHash;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestBuildinPackageVersion)
|
||||
{
|
||||
if (_requestBuildinPackageVersionOp == null)
|
||||
{
|
||||
_requestBuildinPackageVersionOp = new RequestBuildinPackageVersionOperation(_fileSystem);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _requestBuildinPackageVersionOp);
|
||||
}
|
||||
|
||||
if (_requestBuildinPackageVersionOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_requestBuildinPackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.RequestBuildinPackageHash;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _requestBuildinPackageVersionOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.RequestBuildinPackageHash)
|
||||
{
|
||||
if (_requestBuildinPackageHashOp == null)
|
||||
{
|
||||
string packageVersion = _requestBuildinPackageVersionOp.PackageVersion;
|
||||
_requestBuildinPackageHashOp = new RequestBuildinPackageHashOperation(_fileSystem, packageVersion);
|
||||
_requestBuildinPackageHashOp = new RequestBuildinPackageHashOperation(_fileSystem, _packageVersion);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _requestBuildinPackageHashOp);
|
||||
}
|
||||
|
||||
@@ -83,9 +59,8 @@ namespace YooAsset
|
||||
{
|
||||
if (_loadBuildinPackageManifestOp == null)
|
||||
{
|
||||
string packageVersion = _requestBuildinPackageVersionOp.PackageVersion;
|
||||
string packageHash = _requestBuildinPackageHashOp.PackageHash;
|
||||
_loadBuildinPackageManifestOp = new LoadBuildinPackageManifestOperation(_fileSystem, packageVersion, packageHash);
|
||||
_loadBuildinPackageManifestOp = new LoadBuildinPackageManifestOperation(_fileSystem, _packageVersion, packageHash);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _loadBuildinPackageManifestOp);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user