From 589eea7cf37337fcc0127633d592deee87be0981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Tue, 9 Jul 2024 23:37:20 +0800 Subject: [PATCH] update file system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 统一所有PlayMode的初始化行为 --- .../AssetBundleSimulateBuilder.cs | 7 +- .../DefaultBuildinFileSystem.cs | 15 ++- .../DefaultBuildinFileSystemBuild.cs | 10 +- .../Operation/DBFSInitializeOperation.cs | 113 ++---------------- .../DBFSLoadPackageManifestOperation.cs | 37 +----- .../DefaultEditorFileSystem.cs | 43 ++++--- .../DEFSLoadPackageManifestOperation.cs | 34 +++++- .../LoadEditorPackageHashOperation.cs | 56 +++++++++ .../LoadEditorPackageHashOperation.cs.meta | 11 ++ .../LoadEditorPackageManifestOperation.cs | 28 ++++- .../LoadEditorPackageVersionOperation.cs | 2 +- .../DefaultWebFileSystem.cs | 5 + .../Operation/DWFSInitializeOperation.cs | 7 ++ .../YooAsset/Runtime/InitializeParameters.cs | 3 +- .../Operation/InitializationOperation.cs | 52 +------- .../PlayMode/EditorSimulateBuildResult.cs | 4 +- 16 files changed, 189 insertions(+), 238 deletions(-) create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/internal/LoadEditorPackageHashOperation.cs create mode 100644 Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/internal/LoadEditorPackageHashOperation.cs.meta diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleSimulateBuilder.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleSimulateBuilder.cs index 0dd3b2a..698402e 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleSimulateBuilder.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleSimulateBuilder.cs @@ -73,12 +73,7 @@ namespace YooAsset.Editor if (buildResult.Success) { SimulateBuildResult reulst = new SimulateBuildResult(); - string versionFileName = YooAssetSettingsData.GetPackageVersionFileName(packageName); - string manifestFileName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion); - string hashFileName = YooAssetSettingsData.GetPackageHashFileName(packageName, packageVersion); - reulst.PackageVersionFilePath = $"{buildResult.OutputPackageDirectory}/{versionFileName}"; - reulst.PackageManifestFilePath = $"{buildResult.OutputPackageDirectory}/{manifestFileName}"; - reulst.PackageHashFilePath = $"{buildResult.OutputPackageDirectory}/{hashFileName}"; + reulst.PackageRootDirectory = buildResult.OutputPackageDirectory; return reulst; } else diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystem.cs index dc896f0..1dcfb6c 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystem.cs @@ -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); + } + /// /// 记录文件信息 /// diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystemBuild.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystemBuild.cs index 0e56114..9f6793f 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystemBuild.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystemBuild.cs @@ -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) + + /// + /// 生成包裹的内置资源目录文件 + /// + public static void CreateBuildinCatalogFile(string packageName, string pacakgeDirectory) { // 获取资源清单版本 string packageVersion; diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSInitializeOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSInitializeOperation.cs index 10dc76a..1ad7326 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSInitializeOperation.cs @@ -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 } } } - - /// - /// 在编辑器下离线模式的兼容性初始化 - /// - 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; - } - } - } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSLoadPackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSLoadPackageManifestOperation.cs index f33bf74..a98b6ce 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSLoadPackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSLoadPackageManifestOperation.cs @@ -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); } diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/DefaultEditorFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/DefaultEditorFileSystem.cs index f2e4a16..33cf37c 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/DefaultEditorFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/DefaultEditorFileSystem.cs @@ -1,4 +1,5 @@ - +using System; + namespace YooAsset { /// @@ -35,13 +36,6 @@ namespace YooAsset } } - #region 自定义参数 - /// - /// 自定义参数:模拟构建结果 - /// - public SimulateBuildResult BuildResult { private set; get; } = null; - #endregion - public DefaultEditorFileSystem() { @@ -54,7 +48,7 @@ namespace YooAsset } public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout) { - var operation = new DEFSLoadPackageManifestOperation(this); + var operation = new DEFSLoadPackageManifestOperation(this, packageVersion); OperationSystem.StartOperation(PackageName, operation); return operation; } @@ -92,23 +86,17 @@ namespace YooAsset public virtual void SetParameter(string name, object value) { - if (name == "SIMULATE_BUILD_RESULT") - { - BuildResult = (SimulateBuildResult)value; - } - else - { - YooLogger.Warning($"Invalid parameter : {name}"); - } + YooLogger.Warning($"Invalid parameter : {name}"); } public virtual void OnCreate(string packageName, string rootDirectory) { PackageName = packageName; if (string.IsNullOrEmpty(rootDirectory)) - rootDirectory = GetDefaultRoot(); + throw new Exception($"{nameof(DefaultEditorFileSystem)} root directory is null or empty !"); - _packageRoot = PathUtility.Combine(rootDirectory, packageName); + // 注意:基础目录即为包裹目录 + _packageRoot = rootDirectory; } public virtual void OnUpdate() { @@ -143,11 +131,22 @@ namespace YooAsset { throw new System.NotImplementedException(); } - + #region 内部方法 - protected string GetDefaultRoot() + public string GetEditorPackageVersionFilePath() { - return "Assets/"; + string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName); + return PathUtility.Combine(FileRoot, fileName); + } + public string GetEditorPackageHashFilePath(string packageVersion) + { + string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion); + return PathUtility.Combine(FileRoot, fileName); + } + public string GetEditorPackageManifestFilePath(string packageVersion) + { + string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion); + return PathUtility.Combine(FileRoot, fileName); } #endregion } diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/DEFSLoadPackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/DEFSLoadPackageManifestOperation.cs index 2dde91f..afe8a28 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/DEFSLoadPackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/DEFSLoadPackageManifestOperation.cs @@ -6,33 +6,61 @@ namespace YooAsset private enum ESteps { None, + LoadEditorPackageHash, LoadEditorPackageManifest, Done, } private readonly DefaultEditorFileSystem _fileSystem; + private readonly string _packageVersion; + private LoadEditorPackageHashOperation _loadEditorPackageHashOpe; private LoadEditorPackageManifestOperation _loadEditorPackageManifestOp; private ESteps _steps = ESteps.None; - internal DEFSLoadPackageManifestOperation(DefaultEditorFileSystem fileSystem) + internal DEFSLoadPackageManifestOperation(DefaultEditorFileSystem fileSystem, string packageVersion) { _fileSystem = fileSystem; + _packageVersion = packageVersion; } internal override void InternalOnStart() { - _steps = ESteps.LoadEditorPackageManifest; + _steps = ESteps.LoadEditorPackageHash; } internal override void InternalOnUpdate() { if (_steps == ESteps.None || _steps == ESteps.Done) return; + if (_steps == ESteps.LoadEditorPackageHash) + { + if (_loadEditorPackageHashOpe == null) + { + _loadEditorPackageHashOpe = new LoadEditorPackageHashOperation(_fileSystem, _packageVersion); + OperationSystem.StartOperation(_fileSystem.PackageName, _loadEditorPackageHashOpe); + } + + if (_loadEditorPackageHashOpe.IsDone == false) + return; + + if (_loadEditorPackageHashOpe.Status == EOperationStatus.Succeed) + { + _steps = ESteps.LoadEditorPackageManifest; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = _loadEditorPackageHashOpe.Error; + } + } + if (_steps == ESteps.LoadEditorPackageManifest) { if (_loadEditorPackageManifestOp == null) { - _loadEditorPackageManifestOp = new LoadEditorPackageManifestOperation(_fileSystem); + string packageHash = _loadEditorPackageHashOpe.PackageHash; + _loadEditorPackageManifestOp = new LoadEditorPackageManifestOperation(_fileSystem, _packageVersion, packageHash); OperationSystem.StartOperation(_fileSystem.PackageName, _loadEditorPackageManifestOp); } diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/internal/LoadEditorPackageHashOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/internal/LoadEditorPackageHashOperation.cs new file mode 100644 index 0000000..b9f75d5 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/internal/LoadEditorPackageHashOperation.cs @@ -0,0 +1,56 @@ +using System.IO; + +namespace YooAsset +{ + internal class LoadEditorPackageHashOperation : AsyncOperationBase + { + private enum ESteps + { + None, + LoadHash, + Done, + } + + private readonly DefaultEditorFileSystem _fileSystem; + private readonly string _packageVersion; + private ESteps _steps = ESteps.None; + + /// + /// 包裹哈希值 + /// + public string PackageHash { private set; get; } + + + internal LoadEditorPackageHashOperation(DefaultEditorFileSystem fileSystem, string packageVersion) + { + _fileSystem = fileSystem; + _packageVersion = packageVersion; + } + internal override void InternalOnStart() + { + _steps = ESteps.LoadHash; + } + internal override void InternalOnUpdate() + { + if (_steps == ESteps.None || _steps == ESteps.Done) + return; + + if (_steps == ESteps.LoadHash) + { + string hashFilePath = _fileSystem.GetEditorPackageHashFilePath(_packageVersion); + if (File.Exists(hashFilePath)) + { + _steps = ESteps.Done; + PackageHash = FileUtility.ReadAllText(hashFilePath); + Status = EOperationStatus.Succeed; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = $"Can not found simulation package hash file : {hashFilePath}"; + } + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/internal/LoadEditorPackageHashOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/internal/LoadEditorPackageHashOperation.cs.meta new file mode 100644 index 0000000..f0f2677 --- /dev/null +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/internal/LoadEditorPackageHashOperation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 137c898b6a637c74d8d5e281e6124a72 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/internal/LoadEditorPackageManifestOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/internal/LoadEditorPackageManifestOperation.cs index 1afc80c..d08bf70 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/internal/LoadEditorPackageManifestOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/internal/LoadEditorPackageManifestOperation.cs @@ -8,11 +8,14 @@ namespace YooAsset { None, LoadFileData, + VerifyFileData, LoadManifest, Done, } private readonly DefaultEditorFileSystem _fileSystem; + private readonly string _packageVersion; + private readonly string _packageHash; private DeserializeManifestOperation _deserializer; private byte[] _fileData; private ESteps _steps = ESteps.None; @@ -23,9 +26,11 @@ namespace YooAsset public PackageManifest Manifest { private set; get; } - internal LoadEditorPackageManifestOperation(DefaultEditorFileSystem fileSystem) + internal LoadEditorPackageManifestOperation(DefaultEditorFileSystem fileSystem, string packageVersion, string packageHash) { _fileSystem = fileSystem; + _packageVersion = packageVersion; + _packageHash = packageHash; } internal override void InternalOnStart() { @@ -38,10 +43,10 @@ namespace YooAsset if (_steps == ESteps.LoadFileData) { - string manifestFilePath = _fileSystem.BuildResult.PackageManifestFilePath; + string manifestFilePath = _fileSystem.GetEditorPackageManifestFilePath(_packageVersion); if (File.Exists(manifestFilePath)) { - _steps = ESteps.LoadManifest; + _steps = ESteps.VerifyFileData; _fileData = FileUtility.ReadAllBytes(manifestFilePath); } else @@ -52,6 +57,21 @@ namespace YooAsset } } + if (_steps == ESteps.VerifyFileData) + { + string fileHash = HashUtility.BytesMD5(_fileData); + if (fileHash == _packageHash) + { + _steps = ESteps.LoadManifest; + } + else + { + _steps = ESteps.Done; + Status = EOperationStatus.Failed; + Error = "Failed to verify simulation package manifest file !"; + } + } + if (_steps == ESteps.LoadManifest) { if (_deserializer == null) @@ -67,7 +87,7 @@ namespace YooAsset if (_deserializer.Status == EOperationStatus.Succeed) { _steps = ESteps.Done; - Manifest = _deserializer.Manifest; + Manifest = _deserializer.Manifest; Status = EOperationStatus.Succeed; } else diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/internal/LoadEditorPackageVersionOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/internal/LoadEditorPackageVersionOperation.cs index 3624325..de0ba02 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/internal/LoadEditorPackageVersionOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/Operation/internal/LoadEditorPackageVersionOperation.cs @@ -35,7 +35,7 @@ namespace YooAsset if (_steps == ESteps.LoadVersion) { - string versionFilePath = _fileSystem.BuildResult.PackageVersionFilePath; + string versionFilePath = _fileSystem.GetEditorPackageVersionFilePath(); if (File.Exists(versionFilePath)) { _steps = ESteps.Done; diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/DefaultWebFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/DefaultWebFileSystem.cs index 5bbf61d..684984a 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/DefaultWebFileSystem.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/DefaultWebFileSystem.cs @@ -201,6 +201,11 @@ 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); + } /// /// 记录文件信息 diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSInitializeOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSInitializeOperation.cs index ac471b1..7196d1b 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSInitializeOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSInitializeOperation.cs @@ -32,6 +32,13 @@ namespace YooAsset { if (_loadCatalogFileOp == null) { +#if UNITY_EDITOR + // 兼容性初始化 + // 说明:内置文件系统在编辑器下运行时需要动态生成 + string packageRoot = _fileSystem.GetStreamingAssetsPackageRoot(); + DefaultBuildinFileSystemBuild.CreateBuildinCatalogFile(_fileSystem.PackageName, packageRoot); +#endif + _loadCatalogFileOp = new LoadWebCatalogFileOperation(_fileSystem); OperationSystem.StartOperation(_fileSystem.PackageName, _loadCatalogFileOp); } diff --git a/Assets/YooAsset/Runtime/InitializeParameters.cs b/Assets/YooAsset/Runtime/InitializeParameters.cs index 72d62e2..25076f7 100644 --- a/Assets/YooAsset/Runtime/InitializeParameters.cs +++ b/Assets/YooAsset/Runtime/InitializeParameters.cs @@ -92,8 +92,7 @@ namespace YooAsset public static FileSystemParameters CreateDefaultEditorFileSystemParameters(SimulateBuildResult simulateBuildResult) { string fileSystemClass = typeof(DefaultEditorFileSystem).FullName; - var fileSystemParams = new FileSystemParameters(fileSystemClass, null); - fileSystemParams.AddParameter("SIMULATE_BUILD_RESULT", simulateBuildResult); + var fileSystemParams = new FileSystemParameters(fileSystemClass, simulateBuildResult.PackageRootDirectory); return fileSystemParams; } diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/InitializationOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/InitializationOperation.cs index 0b7bee2..22cc9b2 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/InitializationOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/InitializationOperation.cs @@ -18,14 +18,12 @@ namespace YooAsset None, CreateFileSystem, InitFileSystem, - LoadManifestFile, Done, } private readonly EditorSimulateModeImpl _impl; private readonly EditorSimulateModeParameters _parameters; private FSInitializeFileSystemOperation _initFileSystemOp; - private FSLoadPackageManifestOperation _loadPackageManifestOp; private ESteps _steps = ESteps.None; internal EditorSimulateModeInitializationOperation(EditorSimulateModeImpl impl, EditorSimulateModeParameters parameters) @@ -71,37 +69,15 @@ namespace YooAsset return; if (_initFileSystemOp.Status == EOperationStatus.Succeed) - { - _steps = ESteps.LoadManifestFile; - } - else { _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = _initFileSystemOp.Error; - } - } - - if (_steps == ESteps.LoadManifestFile) - { - if (_loadPackageManifestOp == null) - _loadPackageManifestOp = _impl.EditorFileSystem.LoadPackageManifestAsync(null, int.MaxValue); - - Progress = _loadPackageManifestOp.Progress; - if (_loadPackageManifestOp.IsDone == false) - return; - - if (_loadPackageManifestOp.Status == EOperationStatus.Succeed) - { - _steps = ESteps.Done; - _impl.ActiveManifest = _loadPackageManifestOp.Manifest; Status = EOperationStatus.Succeed; } else { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = _loadPackageManifestOp.Error; + Error = _initFileSystemOp.Error; } } } @@ -117,13 +93,13 @@ namespace YooAsset None, CreateFileSystem, InitFileSystem, - LoadManifestFile, Done, } private readonly OfflinePlayModeImpl _impl; private readonly OfflinePlayModeParameters _parameters; private FSInitializeFileSystemOperation _initFileSystemOp; + private FSRequestPackageVersionOperation _requestPackageVersionOp; private FSLoadPackageManifestOperation _loadPackageManifestOp; private ESteps _steps = ESteps.None; @@ -173,37 +149,15 @@ namespace YooAsset return; if (_initFileSystemOp.Status == EOperationStatus.Succeed) - { - _steps = ESteps.LoadManifestFile; - } - else { _steps = ESteps.Done; - Status = EOperationStatus.Failed; - Error = _initFileSystemOp.Error; - } - } - - if (_steps == ESteps.LoadManifestFile) - { - if (_loadPackageManifestOp == null) - _loadPackageManifestOp = _impl.BuildinFileSystem.LoadPackageManifestAsync(null, int.MaxValue); - - Progress = _loadPackageManifestOp.Progress; - if (_loadPackageManifestOp.IsDone == false) - return; - - if (_loadPackageManifestOp.Status == EOperationStatus.Succeed) - { - _steps = ESteps.Done; - _impl.ActiveManifest = _loadPackageManifestOp.Manifest; Status = EOperationStatus.Succeed; } else { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = _loadPackageManifestOp.Error; + Error = _initFileSystemOp.Error; } } } diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateBuildResult.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateBuildResult.cs index c74b477..044ba7f 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateBuildResult.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateBuildResult.cs @@ -3,8 +3,6 @@ namespace YooAsset { public class SimulateBuildResult { - public string PackageVersionFilePath; - public string PackageManifestFilePath; - public string PackageHashFilePath; + public string PackageRootDirectory; } } \ No newline at end of file