From a00924bb54c56689649334dc77da378eac998649 Mon Sep 17 00:00:00 2001 From: hevinci Date: Wed, 9 Mar 2022 23:57:04 +0800 Subject: [PATCH] Update YooAsset --- .../Runtime/AssetSystem/AssetSystem.cs | 8 +- .../Runtime/AssetSystem/EDecryptMethod.cs | 19 ---- .../AssetSystem/EDecryptMethod.cs.meta | 11 -- .../Runtime/AssetSystem/IDecryptServices.cs | 18 --- .../AssetSystem/IDecryptionServices.cs | 11 ++ ...es.cs.meta => IDecryptionServices.cs.meta} | 0 .../AssetSystem/Loader/BundleFileLoader.cs | 77 ++++++------- .../AssetSystem/Loader/DependBundleGrouper.cs | 2 +- .../AssetSystem/Loader/ELoaderStates.cs | 17 --- .../AssetSystem/Loader/ELoaderStates.cs.meta | 11 -- .../Runtime/AssetSystem/Operations.meta | 8 ++ .../{ => Operations}/AssetOperationHandle.cs | 13 ++- .../AssetOperationHandle.cs.meta | 0 .../AssetSystem/Provider/AssetProviderBase.cs | 16 ++- .../Provider/BundledAssetProvider.cs | 20 ++-- .../AssetSystem/Provider/BundledProvider.cs | 2 +- .../Provider/BundledSceneProvider.cs | 20 ++-- .../Provider/BundledSubAssetsProvider.cs | 20 ++-- .../Provider/DatabaseAssetProvider.cs | 16 +-- .../Provider/DatabaseSceneProvider.cs | 14 +-- .../Provider/DatabaseSubAssetsProvider.cs | 16 +-- .../AssetSystem/Provider/EAssetStates.cs | 16 --- .../AssetSystem/Provider/EAssetStates.cs.meta | 11 -- .../AssetSystem/Provider/IAssetProvider.cs | 2 +- .../OperationSystem/AsyncOperationBase.cs | 8 +- .../PatchSystem/Download/DownloadSystem.cs | 4 +- .../Operations/InitializationOperation.cs | 16 +-- .../Operations/UpdateManifestOperation.cs | 8 +- .../Runtime/PatchSystem/PatchCache.cs | 8 +- .../Runtime/PatchSystem/PatchHelper.cs | 100 ---------------- .../Runtime/PatchSystem/PatchHelper.cs.meta | 11 -- .../PatchSystem/PlayMode/HostPlayModeImpl.cs | 12 +- .../PlayMode/OfflinePlayModeImpl.cs | 2 +- .../YooAsset/Runtime/Profiler/DebugSummy.cs | 4 +- .../Runtime/Settings/YooAssetSettings.cs | 2 +- .../Runtime/Settings/YooAssetSettingsData.cs | 2 +- .../YooHelper.cs} | 107 +++++++++++++++++- .../YooHelper.cs.meta} | 0 Assets/YooAsset/Runtime/YooAssets.cs | 20 ++-- 39 files changed, 283 insertions(+), 369 deletions(-) delete mode 100644 Assets/YooAsset/Runtime/AssetSystem/EDecryptMethod.cs delete mode 100644 Assets/YooAsset/Runtime/AssetSystem/EDecryptMethod.cs.meta delete mode 100644 Assets/YooAsset/Runtime/AssetSystem/IDecryptServices.cs create mode 100644 Assets/YooAsset/Runtime/AssetSystem/IDecryptionServices.cs rename Assets/YooAsset/Runtime/AssetSystem/{IDecryptServices.cs.meta => IDecryptionServices.cs.meta} (100%) delete mode 100644 Assets/YooAsset/Runtime/AssetSystem/Loader/ELoaderStates.cs delete mode 100644 Assets/YooAsset/Runtime/AssetSystem/Loader/ELoaderStates.cs.meta create mode 100644 Assets/YooAsset/Runtime/AssetSystem/Operations.meta rename Assets/YooAsset/Runtime/AssetSystem/{ => Operations}/AssetOperationHandle.cs (90%) rename Assets/YooAsset/Runtime/AssetSystem/{ => Operations}/AssetOperationHandle.cs.meta (100%) delete mode 100644 Assets/YooAsset/Runtime/AssetSystem/Provider/EAssetStates.cs delete mode 100644 Assets/YooAsset/Runtime/AssetSystem/Provider/EAssetStates.cs.meta delete mode 100644 Assets/YooAsset/Runtime/PatchSystem/PatchHelper.cs delete mode 100644 Assets/YooAsset/Runtime/PatchSystem/PatchHelper.cs.meta rename Assets/YooAsset/Runtime/{AssetSystem/AssetPathHelper.cs => Utility/YooHelper.cs} (53%) rename Assets/YooAsset/Runtime/{AssetSystem/AssetPathHelper.cs.meta => Utility/YooHelper.cs.meta} (100%) diff --git a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs index 8be7f14..a1feec7 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs @@ -20,7 +20,7 @@ namespace YooAsset /// public static int AssetLoadingMaxNumber { private set; get; } - public static IDecryptServices DecryptServices { private set; get; } + public static IDecryptionServices DecryptionServices { private set; get; } public static IBundleServices BundleServices { private set; get; } @@ -28,11 +28,11 @@ namespace YooAsset /// 初始化资源系统 /// 注意:在使用AssetSystem之前需要初始化 /// - public static void Initialize(bool simulationOnEditor, int assetLoadingMaxNumber, IDecryptServices decryptServices, IBundleServices bundleServices) + public static void Initialize(bool simulationOnEditor, int assetLoadingMaxNumber, IDecryptionServices decryptionServices, IBundleServices bundleServices) { SimulationOnEditor = simulationOnEditor; AssetLoadingMaxNumber = assetLoadingMaxNumber; - DecryptServices = decryptServices; + DecryptionServices = decryptionServices; BundleServices = bundleServices; } @@ -307,7 +307,7 @@ namespace YooAsset DebugSummy.DebugProviderInfo providerInfo = new DebugSummy.DebugProviderInfo(); providerInfo.AssetPath = provider.AssetPath; providerInfo.RefCount = provider.RefCount; - providerInfo.States = (int)provider.States; + providerInfo.Status = (int)provider.Status; providerInfo.BundleInfos.Clear(); summy.ProviderInfos.Add(providerInfo); diff --git a/Assets/YooAsset/Runtime/AssetSystem/EDecryptMethod.cs b/Assets/YooAsset/Runtime/AssetSystem/EDecryptMethod.cs deleted file mode 100644 index 0c4c1d7..0000000 --- a/Assets/YooAsset/Runtime/AssetSystem/EDecryptMethod.cs +++ /dev/null @@ -1,19 +0,0 @@ - -namespace YooAsset -{ - /// - /// 解密方法 - /// - public enum EDecryptMethod - { - /// - /// 获取解密的数据偏移 - /// - GetDecryptOffset, - - /// - /// 获取解密的字节数据 - /// - GetDecryptBinary, - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/EDecryptMethod.cs.meta b/Assets/YooAsset/Runtime/AssetSystem/EDecryptMethod.cs.meta deleted file mode 100644 index ea68fc6..0000000 --- a/Assets/YooAsset/Runtime/AssetSystem/EDecryptMethod.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 6a446add12cd4554a9bd178a7ef2db55 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/AssetSystem/IDecryptServices.cs b/Assets/YooAsset/Runtime/AssetSystem/IDecryptServices.cs deleted file mode 100644 index 4cca90d..0000000 --- a/Assets/YooAsset/Runtime/AssetSystem/IDecryptServices.cs +++ /dev/null @@ -1,18 +0,0 @@ - -namespace YooAsset -{ - public interface IDecryptServices - { - EDecryptMethod DecryptType { get; } - - /// - /// 获取解密的数据偏移 - /// - ulong GetDecryptOffset(BundleInfo bundleInfo); - - /// - /// 获取解密的字节数据 - /// - byte[] GetDecryptBinary(BundleInfo bundleInfo); - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/IDecryptionServices.cs b/Assets/YooAsset/Runtime/AssetSystem/IDecryptionServices.cs new file mode 100644 index 0000000..58434f7 --- /dev/null +++ b/Assets/YooAsset/Runtime/AssetSystem/IDecryptionServices.cs @@ -0,0 +1,11 @@ + +namespace YooAsset +{ + public interface IDecryptionServices + { + /// + /// 获取加密文件的数据偏移量 + /// + ulong GetFileOffset(BundleInfo bundleInfo); + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/IDecryptServices.cs.meta b/Assets/YooAsset/Runtime/AssetSystem/IDecryptionServices.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/AssetSystem/IDecryptServices.cs.meta rename to Assets/YooAsset/Runtime/AssetSystem/IDecryptionServices.cs.meta diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleFileLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleFileLoader.cs index d5299b7..8f9d1e4 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleFileLoader.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleFileLoader.cs @@ -7,6 +7,17 @@ namespace YooAsset { internal class BundleFileLoader { + public enum EStatus + { + None = 0, + Download, + CheckDownload, + LoadFile, + CheckFile, + Success, + Fail, + } + /// /// 资源包文件信息 /// @@ -20,7 +31,7 @@ namespace YooAsset /// /// 加载状态 /// - public ELoaderStates States { private set; get; } + public EStatus Status { private set; get; } /// /// 是否已经销毁 @@ -33,13 +44,13 @@ namespace YooAsset private FileDownloader _fileDownloader; private AssetBundleCreateRequest _cacheRequest; internal AssetBundle CacheBundle { private set; get; } - + public BundleFileLoader(BundleInfo bundleInfo) { BundleFileInfo = bundleInfo; RefCount = 0; - States = ELoaderStates.None; + Status = EStatus.None; } /// @@ -89,31 +100,31 @@ namespace YooAsset if (IsDone()) return; - if (States == ELoaderStates.None) + if (Status == EStatus.None) { // 检测加载地址是否为空 if (string.IsNullOrEmpty(BundleFileInfo.LocalPath)) { - States = ELoaderStates.Fail; + Status = EStatus.Fail; return; } if (string.IsNullOrEmpty(BundleFileInfo.RemoteMainURL)) - States = ELoaderStates.LoadFile; + Status = EStatus.LoadFile; else - States = ELoaderStates.Download; + Status = EStatus.Download; } // 1. 从服务器下载 - if (States == ELoaderStates.Download) + if (Status == EStatus.Download) { int failedTryAgain = int.MaxValue; _fileDownloader = DownloadSystem.BeginDownload(BundleFileInfo, failedTryAgain); - States = ELoaderStates.CheckDownload; + Status = EStatus.CheckDownload; } // 2. 检测服务器下载结果 - if (States == ELoaderStates.CheckDownload) + if (Status == EStatus.CheckDownload) { if (_fileDownloader.IsDone() == false) return; @@ -121,23 +132,23 @@ namespace YooAsset if (_fileDownloader.HasError()) { _fileDownloader.ReportError(); - States = ELoaderStates.Fail; + Status = EStatus.Fail; } else { - States = ELoaderStates.LoadFile; + Status = EStatus.LoadFile; } } // 3. 加载AssetBundle - if (States == ELoaderStates.LoadFile) + if (Status == EStatus.LoadFile) { #if UNITY_EDITOR // 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。 if (System.IO.File.Exists(BundleFileInfo.LocalPath) == false) { YooLogger.Warning($"Not found assetBundle file : {BundleFileInfo.LocalPath}"); - States = ELoaderStates.Fail; + Status = EStatus.Fail; return; } #endif @@ -145,30 +156,14 @@ namespace YooAsset // Load assetBundle file if (BundleFileInfo.IsEncrypted) { - if (AssetSystem.DecryptServices == null) + if (AssetSystem.DecryptionServices == null) throw new Exception($"{nameof(BundleFileLoader)} need IDecryptServices : {BundleFileInfo.BundleName}"); - EDecryptMethod decryptType = AssetSystem.DecryptServices.DecryptType; - if (decryptType == EDecryptMethod.GetDecryptOffset) - { - ulong offset = AssetSystem.DecryptServices.GetDecryptOffset(BundleFileInfo); - if (_isWaitForAsyncComplete) - CacheBundle = AssetBundle.LoadFromFile(BundleFileInfo.LocalPath, 0, offset); - else - _cacheRequest = AssetBundle.LoadFromFileAsync(BundleFileInfo.LocalPath, 0, offset); - } - else if (decryptType == EDecryptMethod.GetDecryptBinary) - { - byte[] binary = AssetSystem.DecryptServices.GetDecryptBinary(BundleFileInfo); - if (_isWaitForAsyncComplete) - CacheBundle = AssetBundle.LoadFromMemory(binary); - else - _cacheRequest = AssetBundle.LoadFromMemoryAsync(binary); - } + ulong offset = AssetSystem.DecryptionServices.GetFileOffset(BundleFileInfo); + if (_isWaitForAsyncComplete) + CacheBundle = AssetBundle.LoadFromFile(BundleFileInfo.LocalPath, 0, offset); else - { - throw new NotImplementedException($"{decryptType}"); - } + _cacheRequest = AssetBundle.LoadFromFileAsync(BundleFileInfo.LocalPath, 0, offset); } else { @@ -177,11 +172,11 @@ namespace YooAsset else _cacheRequest = AssetBundle.LoadFromFileAsync(BundleFileInfo.LocalPath); } - States = ELoaderStates.CheckFile; + Status = EStatus.CheckFile; } // 4. 检测AssetBundle加载结果 - if (States == ELoaderStates.CheckFile) + if (Status == EStatus.CheckFile) { if (_cacheRequest != null) { @@ -203,11 +198,11 @@ namespace YooAsset if (CacheBundle == null) { YooLogger.Error($"Failed to load assetBundle file : {BundleFileInfo.BundleName}"); - States = ELoaderStates.Fail; + Status = EStatus.Fail; } else { - States = ELoaderStates.Success; + Status = EStatus.Success; } } } @@ -240,7 +235,7 @@ namespace YooAsset /// public bool IsDone() { - return States == ELoaderStates.Success || States == ELoaderStates.Fail; + return Status == EStatus.Success || Status == EStatus.Fail; } /// @@ -302,7 +297,7 @@ namespace YooAsset if (_isShowWaitForAsyncError == false) { _isShowWaitForAsyncError = true; - YooLogger.Error($"WaitForAsyncComplete failed ! BundleName : {BundleFileInfo.BundleName} States : {States}"); + YooLogger.Error($"WaitForAsyncComplete failed ! BundleName : {BundleFileInfo.BundleName} States : {Status}"); } break; } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/DependBundleGrouper.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/DependBundleGrouper.cs index 9176d05..2e090c6 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/DependBundleGrouper.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/DependBundleGrouper.cs @@ -74,7 +74,7 @@ namespace YooAsset debugInfo.BundleName = loader.BundleFileInfo.BundleName; debugInfo.Version = loader.BundleFileInfo.Version; debugInfo.RefCount = loader.RefCount; - debugInfo.States = (int)loader.States; + debugInfo.Status = (int)loader.Status; output.Add(debugInfo); } } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/ELoaderStates.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/ELoaderStates.cs deleted file mode 100644 index d9b91fe..0000000 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/ELoaderStates.cs +++ /dev/null @@ -1,17 +0,0 @@ - -namespace YooAsset -{ - /// - /// 文件加载器状态 - /// - public enum ELoaderStates - { - None = 0, - Download, - CheckDownload, - LoadFile, - CheckFile, - Success, - Fail, - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/ELoaderStates.cs.meta b/Assets/YooAsset/Runtime/AssetSystem/Loader/ELoaderStates.cs.meta deleted file mode 100644 index 3674a8a..0000000 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/ELoaderStates.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 90f00fe388279034aaee9c89c07e2ef1 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/AssetSystem/Operations.meta b/Assets/YooAsset/Runtime/AssetSystem/Operations.meta new file mode 100644 index 0000000..f43acf5 --- /dev/null +++ b/Assets/YooAsset/Runtime/AssetSystem/Operations.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fcfac83df022948478c32bf11b8e0987 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/AssetSystem/AssetOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Operations/AssetOperationHandle.cs similarity index 90% rename from Assets/YooAsset/Runtime/AssetSystem/AssetOperationHandle.cs rename to Assets/YooAsset/Runtime/AssetSystem/Operations/AssetOperationHandle.cs index bb26d9b..13e8a64 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/AssetOperationHandle.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Operations/AssetOperationHandle.cs @@ -24,15 +24,20 @@ namespace YooAsset } /// - /// 当前的加载状态 + /// 当前状态 /// - public EAssetStates States + public EOperationStatus Status { get { if (IsValid == false) - return EAssetStates.None; - return _provider.States; + return EOperationStatus.None; + if (_provider.Status == AssetProviderBase.EStatus.Fail) + return EOperationStatus.Failed; + else if (_provider.Status == AssetProviderBase.EStatus.Success) + return EOperationStatus.Succeed; + else + return EOperationStatus.None; } } diff --git a/Assets/YooAsset/Runtime/AssetSystem/AssetOperationHandle.cs.meta b/Assets/YooAsset/Runtime/AssetSystem/Operations/AssetOperationHandle.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/AssetSystem/AssetOperationHandle.cs.meta rename to Assets/YooAsset/Runtime/AssetSystem/Operations/AssetOperationHandle.cs.meta diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/AssetProviderBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/AssetProviderBase.cs index 96d1d16..6d0809a 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/AssetProviderBase.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/AssetProviderBase.cs @@ -3,6 +3,16 @@ namespace YooAsset { internal abstract class AssetProviderBase : IAssetProvider { + public enum EStatus + { + None = 0, + CheckBundle, + Loading, + Checking, + Success, + Fail, + } + protected bool IsWaitForAsyncComplete { private set; get; } = false; public string AssetPath { private set; get; } @@ -11,7 +21,7 @@ namespace YooAsset public UnityEngine.Object AssetObject { protected set; get; } public UnityEngine.Object[] AllAssets { protected set; get; } public IAssetInstance AssetInstance { protected set; get; } - public EAssetStates States { protected set; get; } + public EStatus Status { protected set; get; } public int RefCount { private set; get; } public AssetOperationHandle Handle { private set; get; } public System.Action Callback { set; get; } @@ -20,7 +30,7 @@ namespace YooAsset { get { - return States == EAssetStates.Success || States == EAssetStates.Fail; + return Status == EStatus.Success || Status == EStatus.Fail; } } public bool IsValid @@ -44,7 +54,7 @@ namespace YooAsset AssetPath = assetPath; AssetName = System.IO.Path.GetFileName(assetPath); AssetType = assetType; - States = EAssetStates.None; + Status = EStatus.None; Handle = new AssetOperationHandle(this); } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs index 9dddcb3..ca2c521 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs @@ -26,13 +26,13 @@ namespace YooAsset if (IsDone) return; - if (States == EAssetStates.None) + if (Status == EStatus.None) { - States = EAssetStates.CheckBundle; + Status = EStatus.CheckBundle; } // 1. 检测资源包 - if (States == EAssetStates.CheckBundle) + if (Status == EStatus.CheckBundle) { if (IsWaitForAsyncComplete) { @@ -47,17 +47,17 @@ namespace YooAsset if (OwnerBundle.CacheBundle == null) { - States = EAssetStates.Fail; + Status = EStatus.Fail; InvokeCompletion(); } else { - States = EAssetStates.Loading; + Status = EStatus.Loading; } } // 2. 加载资源对象 - if (States == EAssetStates.Loading) + if (Status == EStatus.Loading) { if (IsWaitForAsyncComplete) { @@ -73,11 +73,11 @@ namespace YooAsset else _cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(AssetName, AssetType); } - States = EAssetStates.Checking; + Status = EStatus.Checking; } // 3. 检测加载结果 - if (States == EAssetStates.Checking) + if (Status == EStatus.Checking) { if (_cacheRequest != null) { @@ -95,8 +95,8 @@ namespace YooAsset } } - States = AssetObject == null ? EAssetStates.Fail : EAssetStates.Success; - if (States == EAssetStates.Fail) + Status = AssetObject == null ? EStatus.Fail : EStatus.Success; + if (Status == EStatus.Fail) YooLogger.Warning($"Failed to load asset : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}"); InvokeCompletion(); } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs index 1a26259..610b950 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs @@ -42,7 +42,7 @@ namespace YooAsset ownerInfo.BundleName = OwnerBundle.BundleFileInfo.BundleName; ownerInfo.Version = OwnerBundle.BundleFileInfo.Version; ownerInfo.RefCount = OwnerBundle.RefCount; - ownerInfo.States = (int)OwnerBundle.States; + ownerInfo.Status = (int)OwnerBundle.Status; output.Add(ownerInfo); DependBundles.GetBundleDebugInfos(output); diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs index 69afe9c..5236f25 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs @@ -29,13 +29,13 @@ namespace YooAsset if (IsDone) return; - if (States == EAssetStates.None) + if (Status == EStatus.None) { - States = EAssetStates.CheckBundle; + Status = EStatus.CheckBundle; } // 1. 检测资源包 - if (States == EAssetStates.CheckBundle) + if (Status == EStatus.CheckBundle) { if (DependBundles.IsDone() == false) return; @@ -44,34 +44,34 @@ namespace YooAsset if (OwnerBundle.CacheBundle == null) { - States = EAssetStates.Fail; + Status = EStatus.Fail; InvokeCompletion(); } else { - States = EAssetStates.Loading; + Status = EStatus.Loading; } } // 2. 加载场景 - if (States == EAssetStates.Loading) + if (Status == EStatus.Loading) { _asyncOp = SceneManager.LoadSceneAsync(AssetName, _param.LoadMode); if (_asyncOp != null) { _asyncOp.allowSceneActivation = true; - States = EAssetStates.Checking; + Status = EStatus.Checking; } else { YooLogger.Warning($"Failed to load scene : {AssetName}"); - States = EAssetStates.Fail; + Status = EStatus.Fail; InvokeCompletion(); } } // 3. 检测加载结果 - if (States == EAssetStates.Checking) + if (Status == EStatus.Checking) { if (_asyncOp.isDone) { @@ -81,7 +81,7 @@ namespace YooAsset if (_param.ActivateOnLoad) instance.Activate(); - States = instance.Scene.IsValid() ? EAssetStates.Success : EAssetStates.Fail; + Status = instance.Scene.IsValid() ? EStatus.Success : EStatus.Fail; InvokeCompletion(); } } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs index 0114db5..849cb5e 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs @@ -26,13 +26,13 @@ namespace YooAsset if (IsDone) return; - if (States == EAssetStates.None) + if (Status == EStatus.None) { - States = EAssetStates.CheckBundle; + Status = EStatus.CheckBundle; } // 1. 检测资源包 - if (States == EAssetStates.CheckBundle) + if (Status == EStatus.CheckBundle) { if (IsWaitForAsyncComplete) { @@ -47,17 +47,17 @@ namespace YooAsset if (OwnerBundle.CacheBundle == null) { - States = EAssetStates.Fail; + Status = EStatus.Fail; InvokeCompletion(); } else { - States = EAssetStates.Loading; + Status = EStatus.Loading; } } // 2. 加载资源对象 - if (States == EAssetStates.Loading) + if (Status == EStatus.Loading) { if (IsWaitForAsyncComplete) { @@ -73,11 +73,11 @@ namespace YooAsset else _cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(AssetName, AssetType); } - States = EAssetStates.Checking; + Status = EStatus.Checking; } // 3. 检测加载结果 - if (States == EAssetStates.Checking) + if (Status == EStatus.Checking) { if (_cacheRequest != null) { @@ -95,8 +95,8 @@ namespace YooAsset } } - States = AllAssets == null ? EAssetStates.Fail : EAssetStates.Success; - if (States == EAssetStates.Fail) + Status = AllAssets == null ? EStatus.Fail : EStatus.Success; + if (Status == EStatus.Fail) YooLogger.Warning($"Failed to load sub assets : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}"); InvokeCompletion(); } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs index 9b2f1ab..eab4f90 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs @@ -27,19 +27,19 @@ namespace YooAsset if (IsDone) return; - if (States == EAssetStates.None) + if (Status == EStatus.None) { // 检测资源文件是否存在 string guid = UnityEditor.AssetDatabase.AssetPathToGUID(AssetPath); if (string.IsNullOrEmpty(guid)) { - States = EAssetStates.Fail; + Status = EStatus.Fail; InvokeCompletion(); return; } else { - States = EAssetStates.Loading; + Status = EStatus.Loading; } // 注意:模拟异步加载效果提前返回 @@ -48,17 +48,17 @@ namespace YooAsset } // 1. 加载资源对象 - if (States == EAssetStates.Loading) + if (Status == EStatus.Loading) { AssetObject = UnityEditor.AssetDatabase.LoadAssetAtPath(AssetPath, AssetType); - States = EAssetStates.Checking; + Status = EStatus.Checking; } // 2. 检测加载结果 - if (States == EAssetStates.Checking) + if (Status == EStatus.Checking) { - States = AssetObject == null ? EAssetStates.Fail : EAssetStates.Success; - if (States == EAssetStates.Fail) + Status = AssetObject == null ? EStatus.Fail : EStatus.Success; + if (Status == EStatus.Fail) YooLogger.Warning($"Failed to load asset object : {AssetPath}"); InvokeCompletion(); } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs index d52fb8d..a92b1ef 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs @@ -28,13 +28,13 @@ namespace YooAsset if (IsDone) return; - if (States == EAssetStates.None) + if (Status == EStatus.None) { - States = EAssetStates.Loading; + Status = EStatus.Loading; } // 1. 加载资源对象 - if (States == EAssetStates.Loading) + if (Status == EStatus.Loading) { LoadSceneParameters loadSceneParameters = new LoadSceneParameters(); loadSceneParameters.loadSceneMode = _param.LoadMode; @@ -42,18 +42,18 @@ namespace YooAsset if (_asyncOp != null) { _asyncOp.allowSceneActivation = true; - States = EAssetStates.Checking; + Status = EStatus.Checking; } else { YooLogger.Warning($"Failed to load scene : {AssetName}"); - States = EAssetStates.Fail; + Status = EStatus.Fail; InvokeCompletion(); } } // 2. 检测加载结果 - if (States == EAssetStates.Checking) + if (Status == EStatus.Checking) { if (_asyncOp.isDone) { @@ -63,7 +63,7 @@ namespace YooAsset if(_param.ActivateOnLoad) instance.Activate(); - States = instance.Scene.IsValid() ? EAssetStates.Success : EAssetStates.Fail; + Status = instance.Scene.IsValid() ? EStatus.Success : EStatus.Fail; InvokeCompletion(); } } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSubAssetsProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSubAssetsProvider.cs index 9fa14e4..068e27b 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSubAssetsProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSubAssetsProvider.cs @@ -27,19 +27,19 @@ namespace YooAsset if (IsDone) return; - if (States == EAssetStates.None) + if (Status == EStatus.None) { // 检测资源文件是否存在 string guid = UnityEditor.AssetDatabase.AssetPathToGUID(AssetPath); if (string.IsNullOrEmpty(guid)) { - States = EAssetStates.Fail; + Status = EStatus.Fail; InvokeCompletion(); return; } else { - States = EAssetStates.Loading; + Status = EStatus.Loading; } // 注意:模拟异步加载效果提前返回 @@ -48,7 +48,7 @@ namespace YooAsset } // 1. 加载资源对象 - if (States == EAssetStates.Loading) + if (Status == EStatus.Loading) { var findAssets = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(AssetPath); List result = new List(findAssets.Length); @@ -58,14 +58,14 @@ namespace YooAsset result.Add(findObj); } AllAssets = result.ToArray(); - States = EAssetStates.Checking; + Status = EStatus.Checking; } // 2. 检测加载结果 - if (States == EAssetStates.Checking) + if (Status == EStatus.Checking) { - States = AllAssets == null ? EAssetStates.Fail : EAssetStates.Success; - if (States == EAssetStates.Fail) + Status = AllAssets == null ? EStatus.Fail : EStatus.Success; + if (Status == EStatus.Fail) YooLogger.Warning($"Failed to load all asset object : {AssetPath}"); InvokeCompletion(); } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/EAssetStates.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/EAssetStates.cs deleted file mode 100644 index 5551491..0000000 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/EAssetStates.cs +++ /dev/null @@ -1,16 +0,0 @@ - -namespace YooAsset -{ - /// - /// 资源加载状态 - /// - public enum EAssetStates - { - None = 0, - CheckBundle, - Loading, - Checking, - Success, - Fail, - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/EAssetStates.cs.meta b/Assets/YooAsset/Runtime/AssetSystem/Provider/EAssetStates.cs.meta deleted file mode 100644 index 2ba38a7..0000000 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/EAssetStates.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: aa6c0fe63326c604bb699be16747c1e2 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/IAssetProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/IAssetProvider.cs index 41da080..ff6ce39 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/IAssetProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/IAssetProvider.cs @@ -39,7 +39,7 @@ namespace YooAsset /// /// 当前的加载状态 /// - EAssetStates States { get; } + AssetProviderBase.EStatus Status { get; } /// /// 引用计数 diff --git a/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs b/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs index 21ecb83..2514f93 100644 --- a/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs +++ b/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs @@ -6,6 +6,9 @@ namespace YooAsset { public abstract class AsyncOperationBase : IEnumerator { + // 用户请求的回调 + private Action _callback; + /// /// 状态 /// @@ -27,11 +30,6 @@ namespace YooAsset } } - /// - /// 用户请求的回调 - /// - private Action _callback; - /// /// 完成事件 /// diff --git a/Assets/YooAsset/Runtime/PatchSystem/Download/DownloadSystem.cs b/Assets/YooAsset/Runtime/PatchSystem/Download/DownloadSystem.cs index eff94e6..238254e 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Download/DownloadSystem.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Download/DownloadSystem.cs @@ -86,7 +86,7 @@ namespace YooAsset { if (_cachedHashList.ContainsKey(hash)) { - string filePath = PatchHelper.MakeSandboxCacheFilePath(hash); + string filePath = SandboxHelper.MakeSandboxCacheFilePath(hash); if (File.Exists(filePath)) { return true; @@ -124,7 +124,7 @@ namespace YooAsset } public static bool CheckContentIntegrity(PatchBundle patchBundle) { - string filePath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash); + string filePath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash); return CheckContentIntegrity(filePath, patchBundle.SizeBytes, patchBundle.CRC); } public static bool CheckContentIntegrity(string filePath, long size, string crc) diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs index f3a0def..e960567 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/InitializationOperation.cs @@ -59,8 +59,8 @@ namespace YooAsset if (_steps == ESteps.LoadAppManifest) { - string filePath = AssetPathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName); - _downloadURL = AssetPathHelper.ConvertToWWWPath(filePath); + string filePath = PathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName); + _downloadURL = PathHelper.ConvertToWWWPath(filePath); _downloader = new UnityWebRequester(); _downloader.SendRequest(_downloadURL); _steps = ESteps.CheckAppManifest; @@ -134,11 +134,11 @@ namespace YooAsset if (_impl.ClearCacheWhenDirty) { YooLogger.Warning("Clear cache files."); - PatchHelper.DeleteSandboxCacheFolder(); + SandboxHelper.DeleteSandboxCacheFolder(); } // 删除清单文件 - PatchHelper.DeleteSandboxPatchManifestFile(); + SandboxHelper.DeleteSandboxPatchManifestFile(); // 更新缓存文件 PatchCache.UpdateCache(); } @@ -149,8 +149,8 @@ namespace YooAsset { // 加载APP内的补丁清单 YooLogger.Log($"Load application patch manifest."); - string filePath = AssetPathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName); - _downloadURL = AssetPathHelper.ConvertToWWWPath(filePath); + string filePath = PathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName); + _downloadURL = PathHelper.ConvertToWWWPath(filePath); _downloader = new UnityWebRequester(); _downloader.SendRequest(_downloadURL); _steps = ESteps.CheckAppManifest; @@ -181,10 +181,10 @@ namespace YooAsset if (_steps == ESteps.LoadSandboxManifest) { // 加载沙盒内的补丁清单 - if (PatchHelper.CheckSandboxPatchManifestFileExist()) + if (SandboxHelper.CheckSandboxPatchManifestFileExist()) { YooLogger.Log($"Load sandbox patch manifest."); - string filePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName); + string filePath = PathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName); string jsonData = File.ReadAllText(filePath); _impl.LocalPatchManifest = PatchManifest.Deserialize(jsonData); } diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs index c8469a7..c18e212 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateManifestOperation.cs @@ -122,7 +122,7 @@ namespace YooAsset _downloaderHash.Dispose(); // 如果补丁清单文件的哈希值相同 - string currentFileHash = PatchHelper.GetSandboxPatchManifestFileHash(); + string currentFileHash = SandboxHelper.GetSandboxPatchManifestFileHash(); if (currentFileHash == webManifestHash) { YooLogger.Log($"Patch manifest file hash is not change : {webManifestHash}"); @@ -206,7 +206,7 @@ namespace YooAsset // 注意:这里会覆盖掉沙盒内的补丁清单文件 YooLogger.Log("Save remote patch manifest file."); - string savePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName); + string savePath = PathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName); PatchManifest.Serialize(savePath, _impl.LocalPatchManifest); } @@ -246,7 +246,7 @@ namespace YooAsset } // 查看文件是否存在 - string filePath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash); + string filePath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash); if (File.Exists(filePath) == false) continue; @@ -285,7 +285,7 @@ namespace YooAsset } private bool RunThread(PatchBundle patchBundle) { - string filePath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash); + string filePath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash); ThreadInfo info = new ThreadInfo(filePath, patchBundle); return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyFile), info); } diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchCache.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchCache.cs index 9bd9a36..7fc67f1 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchCache.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PatchCache.cs @@ -19,10 +19,10 @@ namespace YooAsset /// public static PatchCache LoadCache() { - if (PatchHelper.CheckSandboxCacheFileExist()) + if (SandboxHelper.CheckSandboxCacheFileExist()) { YooLogger.Log("Load patch cache from disk."); - string filePath = PatchHelper.GetSandboxCacheFilePath(); + string filePath = SandboxHelper.GetSandboxCacheFilePath(); string jsonData = FileUtility.ReadFile(filePath); return JsonUtility.FromJson(jsonData); } @@ -31,7 +31,7 @@ namespace YooAsset YooLogger.Log($"Create patch cache to disk : {Application.version}"); PatchCache cache = new PatchCache(); cache.CacheAppVersion = Application.version; - string filePath = PatchHelper.GetSandboxCacheFilePath(); + string filePath = SandboxHelper.GetSandboxCacheFilePath(); string jsonData = JsonUtility.ToJson(cache); FileUtility.CreateFile(filePath, jsonData); return cache; @@ -46,7 +46,7 @@ namespace YooAsset YooLogger.Log($"Update patch cache to disk : {Application.version}"); PatchCache cache = new PatchCache(); cache.CacheAppVersion = Application.version; - string filePath = PatchHelper.GetSandboxCacheFilePath(); + string filePath = SandboxHelper.GetSandboxCacheFilePath(); string jsonData = JsonUtility.ToJson(cache); FileUtility.CreateFile(filePath, jsonData); } diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchHelper.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchHelper.cs deleted file mode 100644 index 8e25edb..0000000 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchHelper.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System.IO; -using System.Text; - -namespace YooAsset -{ - internal static class PatchHelper - { - private const string StrCacheFileName = "Cache.bytes"; - private const string StrCacheFolderName = "CacheFiles"; - - /// - /// 清空沙盒目录 - /// - public static void ClearSandbox() - { - string directoryPath = AssetPathHelper.MakePersistentLoadPath(string.Empty); - if (Directory.Exists(directoryPath)) - Directory.Delete(directoryPath, true); - } - - /// - /// 删除沙盒内补丁清单文件 - /// - public static void DeleteSandboxPatchManifestFile() - { - string filePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName); - if (File.Exists(filePath)) - File.Delete(filePath); - } - - /// - /// 删除沙盒内的缓存文件 - /// - public static void DeleteSandboxCacheFile() - { - string filePath = GetSandboxCacheFilePath(); - if (File.Exists(filePath)) - File.Delete(filePath); - } - - /// - /// 删除沙盒内的缓存文件夹 - /// - public static void DeleteSandboxCacheFolder() - { - string directoryPath = AssetPathHelper.MakePersistentLoadPath(StrCacheFolderName); - if (Directory.Exists(directoryPath)) - Directory.Delete(directoryPath, true); - } - - - /// - /// 获取沙盒内缓存文件的路径 - /// - public static string GetSandboxCacheFilePath() - { - return AssetPathHelper.MakePersistentLoadPath(StrCacheFileName); - } - - /// - /// 检测沙盒内缓存文件是否存在 - /// - public static bool CheckSandboxCacheFileExist() - { - string filePath = GetSandboxCacheFilePath(); - return File.Exists(filePath); - } - - /// - /// 检测沙盒内补丁清单文件是否存在 - /// - public static bool CheckSandboxPatchManifestFileExist() - { - string filePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName); - return File.Exists(filePath); - } - - /// - /// 获取沙盒内补丁清单文件的哈希值 - /// 注意:如果沙盒内补丁清单文件不存在,返回空字符串 - /// - /// - public static string GetSandboxPatchManifestFileHash() - { - string filePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName); - if (File.Exists(filePath)) - return HashUtility.FileMD5(filePath); - else - return string.Empty; - } - - /// - /// 获取缓存文件的存储路径 - /// - public static string MakeSandboxCacheFilePath(string fileName) - { - return AssetPathHelper.MakePersistentLoadPath($"{StrCacheFolderName}/{fileName}"); - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchHelper.cs.meta b/Assets/YooAsset/Runtime/PatchSystem/PatchHelper.cs.meta deleted file mode 100644 index 03ad6d1..0000000 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 887179b2bb92ca04988d1091b3b8f8e2 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs index 6a509a0..a1f1343 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs @@ -170,7 +170,7 @@ namespace YooAsset foreach (var patchBundle in AppPatchManifest.BundleList) { // 如果已经在沙盒内 - string filePath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash); + string filePath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash); if (System.IO.File.Exists(filePath)) continue; @@ -216,7 +216,7 @@ namespace YooAsset private BundleInfo ConvertToDownloadInfo(PatchBundle patchBundle) { // 注意:资源版本号只用于确定下载路径 - string sandboxPath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash); + string sandboxPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash); string remoteMainURL = GetPatchDownloadMainURL(patchBundle.Version, patchBundle.Hash); string remoteFallbackURL = GetPatchDownloadFallbackURL(patchBundle.Version, patchBundle.Hash); BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, remoteMainURL, remoteFallbackURL); @@ -236,8 +236,8 @@ namespace YooAsset // 解压相关 private BundleInfo ConvertToUnpackInfo(PatchBundle patchBundle) { - string sandboxPath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash); - string streamingLoadPath = AssetPathHelper.MakeStreamingLoadPath(patchBundle.Hash); + string sandboxPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash); + string streamingLoadPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash); BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxPath, streamingLoadPath, streamingLoadPath); return bundleInfo; } @@ -265,7 +265,7 @@ namespace YooAsset { if (appPatchBundle.IsBuildin && appPatchBundle.Hash == patchBundle.Hash) { - string appLoadPath = AssetPathHelper.MakeStreamingLoadPath(appPatchBundle.Hash); + string appLoadPath = PathHelper.MakeStreamingLoadPath(appPatchBundle.Hash); BundleInfo bundleInfo = new BundleInfo(appPatchBundle, appLoadPath); return bundleInfo; } @@ -274,7 +274,7 @@ namespace YooAsset // 查询沙盒资源 if (DownloadSystem.ContainsVerifyFile(patchBundle.Hash)) { - string sandboxLoadPath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash); + string sandboxLoadPath = SandboxHelper.MakeSandboxCacheFilePath(patchBundle.Hash); BundleInfo bundleInfo = new BundleInfo(patchBundle, sandboxLoadPath); return bundleInfo; } diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs index 8d796aa..fb6b6ad 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs @@ -36,7 +36,7 @@ namespace YooAsset if (AppPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle)) { - string localPath = AssetPathHelper.MakeStreamingLoadPath(patchBundle.Hash); + string localPath = PathHelper.MakeStreamingLoadPath(patchBundle.Hash); BundleInfo bundleInfo = new BundleInfo(patchBundle, localPath); return bundleInfo; } diff --git a/Assets/YooAsset/Runtime/Profiler/DebugSummy.cs b/Assets/YooAsset/Runtime/Profiler/DebugSummy.cs index 14aa6e3..e457f72 100644 --- a/Assets/YooAsset/Runtime/Profiler/DebugSummy.cs +++ b/Assets/YooAsset/Runtime/Profiler/DebugSummy.cs @@ -29,7 +29,7 @@ namespace YooAsset /// /// 加载状态 /// - public int States { set; get; } + public int Status { set; get; } } /// @@ -50,7 +50,7 @@ namespace YooAsset /// /// 加载状态 /// - public int States { set; get; } + public int Status { set; get; } /// /// 依赖的资源包列表 diff --git a/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs b/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs index 171f398..c65767d 100644 --- a/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs +++ b/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs @@ -3,7 +3,7 @@ namespace YooAsset { [CreateAssetMenu(fileName = "YooAssetSettings", menuName = "YooAsset/Create Settings")] - public class YooAssetSettings : ScriptableObject + internal class YooAssetSettings : ScriptableObject { /// /// AssetBundle文件的后缀名 diff --git a/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs b/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs index 3b08f18..f7c8de8 100644 --- a/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs +++ b/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs @@ -2,7 +2,7 @@ namespace YooAsset { - public static class ResourceSettingData + internal static class ResourceSettingData { private static YooAssetSettings _setting = null; public static YooAssetSettings Setting diff --git a/Assets/YooAsset/Runtime/AssetSystem/AssetPathHelper.cs b/Assets/YooAsset/Runtime/Utility/YooHelper.cs similarity index 53% rename from Assets/YooAsset/Runtime/AssetSystem/AssetPathHelper.cs rename to Assets/YooAsset/Runtime/Utility/YooHelper.cs index 8da5de1..341d0d5 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/AssetPathHelper.cs +++ b/Assets/YooAsset/Runtime/Utility/YooHelper.cs @@ -2,7 +2,10 @@ namespace YooAsset { - internal static class AssetPathHelper + /// + /// 资源路径帮助类 + /// + internal static class PathHelper { /// /// 获取规范化的路径 @@ -72,7 +75,7 @@ namespace YooAsset /// /// 合并资源路径 /// - internal static string CombineAssetPath(string root, string location) + public static string CombineAssetPath(string root, string location) { if (string.IsNullOrEmpty(root)) return location; @@ -83,7 +86,7 @@ namespace YooAsset /// /// 获取AssetDatabase的加载路径 /// - internal static string FindDatabaseAssetPath(string filePath) + public static string FindDatabaseAssetPath(string filePath) { #if UNITY_EDITOR if (File.Exists(filePath)) @@ -119,4 +122,102 @@ namespace YooAsset #endif } } + + /// + /// 沙盒帮助类 + /// + internal static class SandboxHelper + { + private const string StrCacheFileName = "Cache.bytes"; + private const string StrCacheFolderName = "CacheFiles"; + + /// + /// 清空沙盒目录 + /// + public static void ClearSandbox() + { + string directoryPath = PathHelper.MakePersistentLoadPath(string.Empty); + if (Directory.Exists(directoryPath)) + Directory.Delete(directoryPath, true); + } + + /// + /// 删除沙盒内补丁清单文件 + /// + public static void DeleteSandboxPatchManifestFile() + { + string filePath = PathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName); + if (File.Exists(filePath)) + File.Delete(filePath); + } + + /// + /// 删除沙盒内的缓存文件 + /// + public static void DeleteSandboxCacheFile() + { + string filePath = GetSandboxCacheFilePath(); + if (File.Exists(filePath)) + File.Delete(filePath); + } + + /// + /// 删除沙盒内的缓存文件夹 + /// + public static void DeleteSandboxCacheFolder() + { + string directoryPath = PathHelper.MakePersistentLoadPath(StrCacheFolderName); + if (Directory.Exists(directoryPath)) + Directory.Delete(directoryPath, true); + } + + + /// + /// 获取沙盒内缓存文件的路径 + /// + public static string GetSandboxCacheFilePath() + { + return PathHelper.MakePersistentLoadPath(StrCacheFileName); + } + + /// + /// 检测沙盒内缓存文件是否存在 + /// + public static bool CheckSandboxCacheFileExist() + { + string filePath = GetSandboxCacheFilePath(); + return File.Exists(filePath); + } + + /// + /// 检测沙盒内补丁清单文件是否存在 + /// + public static bool CheckSandboxPatchManifestFileExist() + { + string filePath = PathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName); + return File.Exists(filePath); + } + + /// + /// 获取沙盒内补丁清单文件的哈希值 + /// 注意:如果沙盒内补丁清单文件不存在,返回空字符串 + /// + /// + public static string GetSandboxPatchManifestFileHash() + { + string filePath = PathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName); + if (File.Exists(filePath)) + return HashUtility.FileMD5(filePath); + else + return string.Empty; + } + + /// + /// 获取缓存文件的存储路径 + /// + public static string MakeSandboxCacheFilePath(string fileName) + { + return PathHelper.MakePersistentLoadPath($"{StrCacheFolderName}/{fileName}"); + } + } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/AssetPathHelper.cs.meta b/Assets/YooAsset/Runtime/Utility/YooHelper.cs.meta similarity index 100% rename from Assets/YooAsset/Runtime/AssetSystem/AssetPathHelper.cs.meta rename to Assets/YooAsset/Runtime/Utility/YooHelper.cs.meta diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index 52a6e96..98d672e 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -38,7 +38,7 @@ namespace YooAsset /// /// 文件解密接口 /// - public IDecryptServices DecryptServices = null; + public IDecryptionServices DecryptionServices = null; /// /// 资源系统自动释放零引用资源的间隔秒数 @@ -145,7 +145,7 @@ namespace YooAsset } if (string.IsNullOrEmpty(parameters.LocationRoot) == false) - _locationRoot = AssetPathHelper.GetRegularPath(parameters.LocationRoot); + _locationRoot = PathHelper.GetRegularPath(parameters.LocationRoot); // 运行模式 if (parameters is EditorPlayModeParameters) @@ -162,21 +162,21 @@ namespace YooAsset { _editorPlayModeImpl = new EditorPlayModeImpl(); _bundleServices = _editorPlayModeImpl; - AssetSystem.Initialize(true, parameters.AssetLoadingMaxNumber, parameters.DecryptServices, _bundleServices); + AssetSystem.Initialize(true, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices); return _editorPlayModeImpl.InitializeAsync(); } else if (_playMode == EPlayMode.OfflinePlayMode) { _offlinePlayModeImpl = new OfflinePlayModeImpl(); _bundleServices = _offlinePlayModeImpl; - AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptServices, _bundleServices); + AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices); return _offlinePlayModeImpl.InitializeAsync(); } else if (_playMode == EPlayMode.HostPlayMode) { _hostPlayModeImpl = new HostPlayModeImpl(); _bundleServices = _hostPlayModeImpl; - AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptServices, _bundleServices); + AssetSystem.Initialize(false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices); var hostPlayModeParameters = parameters as HostPlayModeParameters; return _hostPlayModeImpl.InitializeAsync( hostPlayModeParameters.ClearCacheWhenDirty, @@ -508,7 +508,7 @@ namespace YooAsset public static void ClearSandbox() { YooLogger.Warning("Clear sandbox."); - PatchHelper.ClearSandbox(); + SandboxHelper.ClearSandbox(); } /// @@ -516,7 +516,7 @@ namespace YooAsset /// public static string GetSandboxRoot() { - return AssetPathHelper.MakePersistentRootPath(); + return PathHelper.MakePersistentRootPath(); } #endregion @@ -554,12 +554,12 @@ namespace YooAsset { if (_playMode == EPlayMode.EditorPlayMode) { - string filePath = AssetPathHelper.CombineAssetPath(_locationRoot, location); - return AssetPathHelper.FindDatabaseAssetPath(filePath); + string filePath = PathHelper.CombineAssetPath(_locationRoot, location); + return PathHelper.FindDatabaseAssetPath(filePath); } else { - return AssetPathHelper.CombineAssetPath(_locationRoot, location); + return PathHelper.CombineAssetPath(_locationRoot, location); } } #endregion