From 4cad58760912fe63ea62103061043ed82133070f Mon Sep 17 00:00:00 2001 From: hevinci Date: Wed, 11 May 2022 16:48:17 +0800 Subject: [PATCH] Optimized asset system and patch system framework MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化了资源定位不正确导致的错误报告方式。 YooAssets.ProcessOperation()重命名为YooAssets.StartOperation() YooAssets.GetBundleInfo()已经移除方法。 YooAssets.IsNeedDownloadFromRemote()新增加方法。 --- .../Runtime/AssetSystem/AssetSystem.cs | 124 ++++---- .../Handles/AssetOperationHandle.cs | 2 +- .../Handles/OperationHandleBase.cs | 8 +- .../Handles/SceneOperationHandle.cs | 6 +- .../Loader/AssetBundleFileLoader.cs | 32 +- .../Loader/AssetBundleLoaderBase.cs | 8 +- .../Loader/AssetBundleWebLoader.cs | 16 +- .../Loader/DependAssetBundleGrouper.cs | 6 +- .../Operations/RawFileOperation.cs | 30 +- .../Provider/BundledAssetProvider.cs | 29 +- .../AssetSystem/Provider/BundledProvider.cs | 22 +- .../Provider/BundledSceneProvider.cs | 14 +- .../Provider/BundledSubAssetsProvider.cs | 29 +- .../AssetSystem/Provider/CompletedProvider.cs | 33 +++ .../Provider/CompletedProvider.cs.meta | 11 + .../Provider/DatabaseAssetProvider.cs | 23 +- .../Provider/DatabaseSceneProvider.cs | 9 +- .../Provider/DatabaseSubAssetsProvider.cs | 21 +- .../AssetSystem/Provider/ProviderBase.cs | 60 ++-- .../Runtime/DownloadSystem/DownloadSystem.cs | 2 +- .../OperationSystem/OperationSystem.cs | 2 +- .../YooAsset/Runtime/PatchSystem/AssetInfo.cs | 79 ++++- .../Runtime/PatchSystem/BundleInfo.cs | 63 ++-- .../Operations/DownloaderOperation.cs | 2 +- .../Runtime/PatchSystem/PatchManifest.cs | 146 ++++------ .../PlayMode/EditorSimulateModeImpl.cs | 35 +-- .../PatchSystem/PlayMode/HostPlayModeImpl.cs | 87 +++--- .../PlayMode/OfflinePlayModeImpl.cs | 54 ++-- .../Runtime/Services/IBundleServices.cs | 21 +- .../Runtime/Services/IDecryptionServices.cs | 2 +- .../AddressLocationServices.cs | 2 +- .../DefaultLocationServices.cs | 2 +- Assets/YooAsset/Runtime/Utility/YooHelper.cs | 44 +-- Assets/YooAsset/Runtime/YooAssets.cs | 275 +++++++++--------- 34 files changed, 726 insertions(+), 573 deletions(-) create mode 100644 Assets/YooAsset/Runtime/AssetSystem/Provider/CompletedProvider.cs create mode 100644 Assets/YooAsset/Runtime/AssetSystem/Provider/CompletedProvider.cs.meta diff --git a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs index 022e1da..1a229e6 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.IO; using UnityEngine; using UnityEngine.SceneManagement; @@ -12,16 +11,8 @@ namespace YooAsset private static readonly List _loaders = new List(1000); private static readonly List _providers = new List(1000); private static readonly Dictionary _sceneHandles = new Dictionary(100); - - /// - /// 在编辑器下模拟运行 - /// - public static bool SimulationOnEditor { private set; get; } - - /// - /// 运行时的最大加载个数 - /// - public static int AssetLoadingMaxNumber { private set; get; } + private static bool _simulationOnEditor; + private static int _loadingMaxNumber; public static IDecryptionServices DecryptionServices { private set; get; } public static IBundleServices BundleServices { private set; get; } @@ -31,10 +22,10 @@ namespace YooAsset /// 初始化资源系统 /// 注意:在使用AssetSystem之前需要初始化 /// - public static void Initialize(bool simulationOnEditor, int assetLoadingMaxNumber, IDecryptionServices decryptionServices, IBundleServices bundleServices) + public static void Initialize(bool simulationOnEditor, int loadingMaxNumber, IDecryptionServices decryptionServices, IBundleServices bundleServices) { - SimulationOnEditor = simulationOnEditor; - AssetLoadingMaxNumber = assetLoadingMaxNumber; + _simulationOnEditor = simulationOnEditor; + _loadingMaxNumber = loadingMaxNumber; DecryptionServices = decryptionServices; BundleServices = bundleServices; } @@ -63,7 +54,7 @@ namespace YooAsset } else { - if (loadingCount < AssetLoadingMaxNumber) + if (loadingCount < _loadingMaxNumber) provider.Update(); if (provider.IsDone == false) @@ -77,7 +68,7 @@ namespace YooAsset /// public static void UnloadUnusedAssets() { - if (SimulationOnEditor) + if (_simulationOnEditor) { for (int i = _providers.Count - 1; i >= 0; i--) { @@ -128,15 +119,21 @@ namespace YooAsset Resources.UnloadUnusedAssets(); } - /// /// 加载场景 /// - public static SceneOperationHandle LoadSceneAsync(string scenePath, LoadSceneMode sceneMode, bool activateOnLoad, int priority) + public static SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) { + if (assetInfo.IsInvalid) + { + CompletedProvider completedProvider = new CompletedProvider(assetInfo); + return completedProvider.CreateHandle(); + } + // 注意:场景句柄永远保持唯一 - if (_sceneHandles.ContainsKey(scenePath)) - return _sceneHandles[scenePath]; + string providerGUID = assetInfo.ProviderGUID; + if (_sceneHandles.ContainsKey(providerGUID)) + return _sceneHandles[providerGUID]; // 如果加载的是主场景,则卸载所有缓存的场景 if (sceneMode == LoadSceneMode.Single) @@ -144,68 +141,79 @@ namespace YooAsset UnloadAllScene(); } - ProviderBase provider = TryGetProvider(scenePath); + ProviderBase provider = TryGetProvider(providerGUID); if (provider == null) { - if (SimulationOnEditor) - provider = new DatabaseSceneProvider(scenePath, sceneMode, activateOnLoad, priority); + if (_simulationOnEditor) + provider = new DatabaseSceneProvider(assetInfo, sceneMode, activateOnLoad, priority); else - provider = new BundledSceneProvider(scenePath, sceneMode, activateOnLoad, priority); + provider = new BundledSceneProvider(assetInfo, sceneMode, activateOnLoad, priority); provider.InitSpawnDebugInfo(); _providers.Add(provider); } - var handle = provider.CreateHandle() as SceneOperationHandle; - _sceneHandles.Add(scenePath, handle); + var handle = provider.CreateHandle(); + _sceneHandles.Add(providerGUID, handle); return handle; } /// /// 加载资源对象 /// - public static AssetOperationHandle LoadAssetAsync(string assetPath, System.Type assetType) + public static AssetOperationHandle LoadAssetAsync(AssetInfo assetInfo) { - ProviderBase provider = TryGetProvider(assetPath); + if (assetInfo.IsInvalid) + { + CompletedProvider completedProvider = new CompletedProvider(assetInfo); + return completedProvider.CreateHandle(); + } + + ProviderBase provider = TryGetProvider(assetInfo.ProviderGUID); if (provider == null) { - if (SimulationOnEditor) - provider = new DatabaseAssetProvider(assetPath, assetType); + if (_simulationOnEditor) + provider = new DatabaseAssetProvider(assetInfo); else - provider = new BundledAssetProvider(assetPath, assetType); + provider = new BundledAssetProvider(assetInfo); provider.InitSpawnDebugInfo(); _providers.Add(provider); } - return provider.CreateHandle() as AssetOperationHandle; + return provider.CreateHandle(); } /// /// 加载子资源对象 /// - public static SubAssetsOperationHandle LoadSubAssetsAsync(string assetPath, System.Type assetType) + public static SubAssetsOperationHandle LoadSubAssetsAsync(AssetInfo assetInfo) { - ProviderBase provider = TryGetProvider(assetPath); + if (assetInfo.IsInvalid) + { + CompletedProvider completedProvider = new CompletedProvider(assetInfo); + return completedProvider.CreateHandle(); + } + + ProviderBase provider = TryGetProvider(assetInfo.ProviderGUID); if (provider == null) { - if (SimulationOnEditor) - provider = new DatabaseSubAssetsProvider(assetPath, assetType); + if (_simulationOnEditor) + provider = new DatabaseSubAssetsProvider(assetInfo); else - provider = new BundledSubAssetsProvider(assetPath, assetType); + provider = new BundledSubAssetsProvider(assetInfo); provider.InitSpawnDebugInfo(); _providers.Add(provider); } - return provider.CreateHandle() as SubAssetsOperationHandle; + return provider.CreateHandle(); } - internal static void UnloadSubScene(ProviderBase provider) { - string scenePath = provider.AssetPath; - if (_sceneHandles.ContainsKey(scenePath) == false) + string providerGUID = provider.MainAssetInfo.ProviderGUID; + if (_sceneHandles.ContainsKey(providerGUID) == false) throw new Exception("Should never get here !"); // 释放子场景句柄 - _sceneHandles[scenePath].ReleaseInternal(); - _sceneHandles.Remove(scenePath); + _sceneHandles[providerGUID].ReleaseInternal(); + _sceneHandles.Remove(providerGUID); // 卸载未被使用的资源(包括场景) AssetSystem.UnloadUnusedAssets(); @@ -239,24 +247,19 @@ namespace YooAsset } } - internal static AssetBundleLoaderBase CreateOwnerAssetBundleLoader(string assetPath) + internal static AssetBundleLoaderBase CreateOwnerAssetBundleLoader(AssetInfo assetInfo) { - string bundleName = BundleServices.GetBundleName(assetPath); - BundleInfo bundleInfo = BundleServices.GetBundleInfo(bundleName); + BundleInfo bundleInfo = BundleServices.GetBundleInfo(assetInfo); return CreateAssetBundleLoaderInternal(bundleInfo); } - internal static List CreateDependAssetBundleLoaders(string assetPath) + internal static List CreateDependAssetBundleLoaders(AssetInfo assetInfo) { - List result = new List(); - string[] depends = BundleServices.GetAllDependencies(assetPath); - if (depends != null) + BundleInfo[] depends = BundleServices.GetAllDependBundleInfos(assetInfo); + List result = new List(depends.Length); + foreach (var bundleInfo in depends) { - foreach (var dependBundleName in depends) - { - BundleInfo dependBundleInfo = BundleServices.GetBundleInfo(dependBundleName); - AssetBundleLoaderBase dependLoader = CreateAssetBundleLoaderInternal(dependBundleInfo); - result.Add(dependLoader); - } + AssetBundleLoaderBase dependLoader = CreateAssetBundleLoaderInternal(bundleInfo); + result.Add(dependLoader); } return result; } @@ -291,7 +294,7 @@ namespace YooAsset for (int i = 0; i < _loaders.Count; i++) { AssetBundleLoaderBase temp = _loaders[i]; - if (temp.BundleFileInfo.BundleName.Equals(bundleName)) + if (temp.MainBundleInfo.BundleName.Equals(bundleName)) { loader = temp; break; @@ -299,13 +302,13 @@ namespace YooAsset } return loader; } - private static ProviderBase TryGetProvider(string assetPath) + private static ProviderBase TryGetProvider(string providerGUID) { ProviderBase provider = null; for (int i = 0; i < _providers.Count; i++) { ProviderBase temp = _providers[i]; - if (temp.AssetPath.Equals(assetPath)) + if (temp.MainAssetInfo.ProviderGUID.Equals(providerGUID)) { provider = temp; break; @@ -314,7 +317,6 @@ namespace YooAsset return provider; } - #region 调试专属方法 internal static void GetDebugReport(DebugReport report) { @@ -325,7 +327,7 @@ namespace YooAsset foreach (var provider in _providers) { DebugProviderInfo providerInfo = new DebugProviderInfo(); - providerInfo.AssetPath = provider.AssetPath; + providerInfo.AssetPath = provider.MainAssetInfo.AssetPath; providerInfo.SpawnScene = provider.SpawnScene; providerInfo.SpawnTime = provider.SpawnTime; providerInfo.RefCount = provider.RefCount; diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs index 187f3aa..c8349e8 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs @@ -135,7 +135,7 @@ namespace YooAsset private InstantiateOperation InstantiateAsyncInternal(Vector3 position, Quaternion rotation, Transform parent, bool setPositionRotation) { InstantiateOperation operation = new InstantiateOperation(this, position, rotation, parent, setPositionRotation); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs index 13956ea..12a471a 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs @@ -4,13 +4,13 @@ namespace YooAsset { public abstract class OperationHandleBase : IEnumerator { - private readonly string _cachedAssetPath; + private readonly AssetInfo _assetInfo; internal ProviderBase Provider { private set; get; } internal OperationHandleBase(ProviderBase provider) { Provider = provider; - _cachedAssetPath = provider.AssetPath; + _assetInfo = provider.MainAssetInfo; } internal abstract void InvokeCallback(); @@ -85,9 +85,9 @@ namespace YooAsset else { if (Provider == null) - YooLogger.Warning($"Operation handle is released : {_cachedAssetPath}"); + YooLogger.Warning($"Operation handle is released : {_assetInfo.AssetPath}"); else if (Provider.IsDestroyed) - YooLogger.Warning($"Provider is destroyed : {_cachedAssetPath}"); + YooLogger.Warning($"Provider is destroyed : {_assetInfo.AssetPath}"); return false; } } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/SceneOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/SceneOperationHandle.cs index 8f1d000..53d5eca 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/SceneOperationHandle.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/SceneOperationHandle.cs @@ -102,7 +102,7 @@ namespace YooAsset { string error = $"{nameof(SceneOperationHandle)} is invalid."; var operation = new UnloadSceneOperation(error); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } @@ -112,7 +112,7 @@ namespace YooAsset string error = $"Cannot unload main scene. Use {nameof(YooAssets.LoadSceneAsync)} method to change the main scene !"; YooLogger.Error(error); var operation = new UnloadSceneOperation(error); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } @@ -121,7 +121,7 @@ namespace YooAsset AssetSystem.UnloadSubScene(Provider); { var operation = new UnloadSceneOperation(sceneObject); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs index 20dff8e..35ec821 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs @@ -39,31 +39,33 @@ namespace YooAsset if (_steps == ESteps.None) { - if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.None) + if(MainBundleInfo.IsInvalid) { _steps = ESteps.Done; Status = EStatus.Failed; - LastError = $"Invalid load mode : {BundleFileInfo.BundleName}"; + LastError = $"The bundle info is invalid : {MainBundleInfo.BundleName}"; YooLogger.Error(LastError); + return; } - else if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote) + + if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote) { _steps = ESteps.Download; - _fileLoadPath = BundleFileInfo.GetCacheLoadPath(); + _fileLoadPath = MainBundleInfo.GetCacheLoadPath(); } - else if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming) + else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming) { _steps = ESteps.LoadFile; - _fileLoadPath = BundleFileInfo.GetStreamingLoadPath(); + _fileLoadPath = MainBundleInfo.GetStreamingLoadPath(); } - else if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache) + else if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromCache) { _steps = ESteps.LoadFile; - _fileLoadPath = BundleFileInfo.GetCacheLoadPath(); + _fileLoadPath = MainBundleInfo.GetCacheLoadPath(); } else { - throw new System.NotImplementedException(BundleFileInfo.LoadMode.ToString()); + throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString()); } } @@ -71,7 +73,7 @@ namespace YooAsset if (_steps == ESteps.Download) { int failedTryAgain = int.MaxValue; - _downloader = DownloadSystem.BeginDownload(BundleFileInfo, failedTryAgain); + _downloader = DownloadSystem.BeginDownload(MainBundleInfo, failedTryAgain); _steps = ESteps.CheckDownload; } @@ -109,12 +111,12 @@ namespace YooAsset #endif // Load assetBundle file - if (BundleFileInfo.IsEncrypted) + if (MainBundleInfo.IsEncrypted) { if (AssetSystem.DecryptionServices == null) - throw new Exception($"{nameof(AssetBundleFileLoader)} need {nameof(IDecryptionServices)} : {BundleFileInfo.BundleName}"); + throw new Exception($"{nameof(AssetBundleFileLoader)} need {nameof(IDecryptionServices)} : {MainBundleInfo.BundleName}"); - ulong offset = AssetSystem.DecryptionServices.GetFileOffset(BundleFileInfo); + ulong offset = AssetSystem.DecryptionServices.GetFileOffset(); if (_isWaitForAsyncComplete) CacheBundle = AssetBundle.LoadFromFile(_fileLoadPath, 0, offset); else @@ -154,7 +156,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EStatus.Failed; - LastError = $"Failed to load assetBundle : {BundleFileInfo.BundleName}"; + LastError = $"Failed to load assetBundle : {MainBundleInfo.BundleName}"; YooLogger.Error(LastError); } else @@ -183,7 +185,7 @@ namespace YooAsset if (_isShowWaitForAsyncError == false) { _isShowWaitForAsyncError = true; - YooLogger.Error($"WaitForAsyncComplete failed ! BundleName : {BundleFileInfo.BundleName} States : {Status}"); + YooLogger.Error($"WaitForAsyncComplete failed ! BundleName : {MainBundleInfo.BundleName} States : {Status}"); } break; } diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleLoaderBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleLoaderBase.cs index f8c07f6..c1b9e07 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleLoaderBase.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleLoaderBase.cs @@ -17,7 +17,7 @@ namespace YooAsset /// /// 资源包文件信息 /// - public BundleInfo BundleFileInfo { private set; get; } + public BundleInfo MainBundleInfo { private set; get; } /// /// 引用计数 @@ -45,7 +45,7 @@ namespace YooAsset public AssetBundleLoaderBase(BundleInfo bundleInfo) { - BundleFileInfo = bundleInfo; + MainBundleInfo = bundleInfo; RefCount = 0; Status = EStatus.None; } @@ -91,9 +91,9 @@ namespace YooAsset if (forceDestroy == false) { if (RefCount > 0) - throw new Exception($"Bundle file loader ref is not zero : {BundleFileInfo.BundleName}"); + throw new Exception($"Bundle file loader ref is not zero : {MainBundleInfo.BundleName}"); if (IsDone() == false) - throw new Exception($"Bundle file loader is not done : {BundleFileInfo.BundleName}"); + throw new Exception($"Bundle file loader is not done : {MainBundleInfo.BundleName}"); } if (CacheBundle != null) diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs index cfb51d3..39e9b71 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs @@ -37,28 +37,30 @@ namespace YooAsset if (_steps == ESteps.None) { - if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.None) + if (MainBundleInfo.IsInvalid) { _steps = ESteps.Done; Status = EStatus.Failed; - LastError = $"Invalid load mode : {BundleFileInfo.BundleName}"; + LastError = $"The bundle info is invalid : {MainBundleInfo.BundleName}"; YooLogger.Error(LastError); + return; } - else if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming) + + if (MainBundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming) { _steps = ESteps.LoadFile; - _webURL = BundleFileInfo.GetStreamingLoadPath(); + _webURL = MainBundleInfo.GetStreamingLoadPath(); } else { - throw new System.NotImplementedException(BundleFileInfo.LoadMode.ToString()); + throw new System.NotImplementedException(MainBundleInfo.LoadMode.ToString()); } } // 1. 从服务器或缓存中获取AssetBundle文件 if (_steps == ESteps.LoadFile) { - string hash = StringUtility.RemoveExtension(BundleFileInfo.Hash); + string hash = StringUtility.RemoveExtension(MainBundleInfo.Hash); _webRequest = UnityWebRequestAssetBundle.GetAssetBundle(_webURL, Hash128.Parse(hash)); _webRequest.SendWebRequest(); _steps = ESteps.CheckFile; @@ -87,7 +89,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EStatus.Failed; - LastError = $"AssetBundle file is invalid : {BundleFileInfo.BundleName}"; + LastError = $"AssetBundle file is invalid : {MainBundleInfo.BundleName}"; YooLogger.Error(LastError); } else diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/DependAssetBundleGrouper.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/DependAssetBundleGrouper.cs index fe3ff33..7ea8c05 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/DependAssetBundleGrouper.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/DependAssetBundleGrouper.cs @@ -12,9 +12,9 @@ namespace YooAsset private readonly List _dependBundles; - public DependAssetBundleGroup(string assetPath) + public DependAssetBundleGroup(List dpendBundles) { - _dependBundles = AssetSystem.CreateDependAssetBundleLoaders(assetPath); + _dependBundles = dpendBundles; } /// @@ -102,7 +102,7 @@ namespace YooAsset foreach (var loader in _dependBundles) { var bundleInfo = new DebugBundleInfo(); - bundleInfo.BundleName = loader.BundleFileInfo.BundleName; + bundleInfo.BundleName = loader.MainBundleInfo.BundleName; bundleInfo.RefCount = loader.RefCount; bundleInfo.Status = loader.Status; output.Add(bundleInfo); diff --git a/Assets/YooAsset/Runtime/AssetSystem/Operations/RawFileOperation.cs b/Assets/YooAsset/Runtime/AssetSystem/Operations/RawFileOperation.cs index 8776582..38c7b14 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Operations/RawFileOperation.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Operations/RawFileOperation.cs @@ -7,7 +7,7 @@ namespace YooAsset /// public abstract class RawFileOperation : AsyncOperationBase { - protected readonly BundleInfo _bundleInfo; + internal readonly BundleInfo _bundleInfo; /// /// 原生文件的拷贝路径 @@ -49,6 +49,34 @@ namespace YooAsset } } + /// + /// 发生错误的原生文件操作 + /// + internal sealed class CompletedRawFileOperation : RawFileOperation + { + private readonly string _error; + internal CompletedRawFileOperation(string error, string copyPath) : base(null, copyPath) + { + _error = error; + } + internal override void Start() + { + Status = EOperationStatus.Failed; + Error = _error; + } + internal override void Update() + { + } + + /// + /// 原生文件的缓存路径 + /// + public override string GetCachePath() + { + return string.Empty; + } + } + /// /// 编辑器下模拟运行的原生文件操作 /// diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs index c104aae..e2efdc0 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs @@ -17,8 +17,7 @@ namespace YooAsset } } - public BundledAssetProvider(string assetPath, System.Type assetType) - : base(assetPath, assetType) + public BundledAssetProvider(AssetInfo assetInfo) : base(assetInfo) { } public override void Update() @@ -36,19 +35,19 @@ namespace YooAsset { if (IsWaitForAsyncComplete) { - DependBundles.WaitForAsyncComplete(); + DependBundleGroup.WaitForAsyncComplete(); OwnerBundle.WaitForAsyncComplete(); } - if (DependBundles.IsDone() == false) + if (DependBundleGroup.IsDone() == false) return; if (OwnerBundle.IsDone() == false) return; - if (DependBundles.IsSucceed() == false) + if (DependBundleGroup.IsSucceed() == false) { Status = EStatus.Fail; - LastError = DependBundles.GetLastError(); + LastError = DependBundleGroup.GetLastError(); InvokeCompletion(); return; } @@ -69,17 +68,17 @@ namespace YooAsset { if (IsWaitForAsyncComplete) { - if (AssetType == null) - AssetObject = OwnerBundle.CacheBundle.LoadAsset(AssetName); + if (MainAssetInfo.AssetType == null) + AssetObject = OwnerBundle.CacheBundle.LoadAsset(MainAssetInfo.AssetName); else - AssetObject = OwnerBundle.CacheBundle.LoadAsset(AssetName, AssetType); + AssetObject = OwnerBundle.CacheBundle.LoadAsset(MainAssetInfo.AssetName, MainAssetInfo.AssetType); } else { - if (AssetType == null) - _cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(AssetName); + if (MainAssetInfo.AssetType == null) + _cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(MainAssetInfo.AssetName); else - _cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(AssetName, AssetType); + _cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(MainAssetInfo.AssetName, MainAssetInfo.AssetType); } Status = EStatus.Checking; } @@ -106,10 +105,10 @@ namespace YooAsset Status = AssetObject == null ? EStatus.Fail : EStatus.Success; if (Status == EStatus.Fail) { - if(AssetType == null) - LastError = $"Failed to load asset : {AssetName} AssetType : null AssetBundle : {OwnerBundle.BundleFileInfo.BundleName}"; + if(MainAssetInfo.AssetType == null) + LastError = $"Failed to load asset : {MainAssetInfo.AssetName} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.BundleName}"; else - LastError = $"Failed to load asset : {AssetName} AssetType : {AssetType} AssetBundle : {OwnerBundle.BundleFileInfo.BundleName}"; + LastError = $"Failed to load asset : {MainAssetInfo.AssetName} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.BundleName}"; YooLogger.Error(LastError); } InvokeCompletion(); diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs index 040a2bc..171e831 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs @@ -6,15 +6,17 @@ namespace YooAsset internal abstract class BundledProvider : ProviderBase { protected AssetBundleLoaderBase OwnerBundle { private set; get; } - protected DependAssetBundleGroup DependBundles { private set; get; } + protected DependAssetBundleGroup DependBundleGroup { private set; get; } - public BundledProvider(string assetPath, System.Type assetType) : base(assetPath, assetType) + public BundledProvider(AssetInfo assetInfo) : base(assetInfo) { - OwnerBundle = AssetSystem.CreateOwnerAssetBundleLoader(assetPath); + OwnerBundle = AssetSystem.CreateOwnerAssetBundleLoader(assetInfo); OwnerBundle.Reference(); OwnerBundle.AddProvider(this); - DependBundles = new DependAssetBundleGroup(assetPath); - DependBundles.Reference(); + + var dependBundles = AssetSystem.CreateDependAssetBundleLoaders(assetInfo); + DependBundleGroup = new DependAssetBundleGroup(dependBundles); + DependBundleGroup.Reference(); } public override void Destroy() { @@ -26,10 +28,10 @@ namespace YooAsset OwnerBundle.Release(); OwnerBundle = null; } - if (DependBundles != null) + if (DependBundleGroup != null) { - DependBundles.Release(); - DependBundles = null; + DependBundleGroup.Release(); + DependBundleGroup = null; } } @@ -39,12 +41,12 @@ namespace YooAsset internal void GetBundleDebugInfos(List output) { var bundleInfo = new DebugBundleInfo(); - bundleInfo.BundleName = OwnerBundle.BundleFileInfo.BundleName; + bundleInfo.BundleName = OwnerBundle.MainBundleInfo.BundleName; bundleInfo.RefCount = OwnerBundle.RefCount; bundleInfo.Status = OwnerBundle.Status; output.Add(bundleInfo); - DependBundles.GetBundleDebugInfos(output); + DependBundleGroup.GetBundleDebugInfos(output); } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs index aaa3868..5ac6320 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using System.IO; using UnityEngine; using UnityEngine.SceneManagement; @@ -22,11 +23,10 @@ namespace YooAsset } } - public BundledSceneProvider(string scenePath, LoadSceneMode sceneMode, bool activateOnLoad, int priority) - : base(scenePath, null) + public BundledSceneProvider(AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) : base(assetInfo) { SceneMode = sceneMode; - _sceneName = System.IO.Path.GetFileNameWithoutExtension(scenePath); + _sceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath); _activateOnLoad = activateOnLoad; _priority = priority; } @@ -43,15 +43,15 @@ namespace YooAsset // 1. 检测资源包 if (Status == EStatus.CheckBundle) { - if (DependBundles.IsDone() == false) + if (DependBundleGroup.IsDone() == false) return; if (OwnerBundle.IsDone() == false) return; - if (DependBundles.IsSucceed() == false) + if (DependBundleGroup.IsSucceed() == false) { Status = EStatus.Fail; - LastError = DependBundles.GetLastError(); + LastError = DependBundleGroup.GetLastError(); InvokeCompletion(); return; } @@ -98,7 +98,7 @@ namespace YooAsset Status = SceneObject.IsValid() ? EStatus.Success : EStatus.Fail; if(Status == EStatus.Fail) { - LastError = $"The load scene is invalid : {AssetPath}"; + LastError = $"The load scene is invalid : {MainAssetInfo.AssetPath}"; YooLogger.Error(LastError); } InvokeCompletion(); diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs index 6194e68..68be4dc 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs @@ -17,8 +17,7 @@ namespace YooAsset } } - public BundledSubAssetsProvider(string assetPath, System.Type assetType) - : base(assetPath, assetType) + public BundledSubAssetsProvider(AssetInfo assetInfo) : base(assetInfo) { } public override void Update() @@ -36,19 +35,19 @@ namespace YooAsset { if (IsWaitForAsyncComplete) { - DependBundles.WaitForAsyncComplete(); + DependBundleGroup.WaitForAsyncComplete(); OwnerBundle.WaitForAsyncComplete(); } - if (DependBundles.IsDone() == false) + if (DependBundleGroup.IsDone() == false) return; if (OwnerBundle.IsDone() == false) return; - if (DependBundles.IsSucceed() == false) + if (DependBundleGroup.IsSucceed() == false) { Status = EStatus.Fail; - LastError = DependBundles.GetLastError(); + LastError = DependBundleGroup.GetLastError(); InvokeCompletion(); return; } @@ -69,17 +68,17 @@ namespace YooAsset { if (IsWaitForAsyncComplete) { - if (AssetType == null) - AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(AssetName); + if (MainAssetInfo.AssetType == null) + AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(MainAssetInfo.AssetName); else - AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(AssetName, AssetType); + AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(MainAssetInfo.AssetName, MainAssetInfo.AssetType); } else { - if (AssetType == null) - _cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(AssetName); + if (MainAssetInfo.AssetType == null) + _cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(MainAssetInfo.AssetName); else - _cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(AssetName, AssetType); + _cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(MainAssetInfo.AssetName, MainAssetInfo.AssetType); } Status = EStatus.Checking; } @@ -106,10 +105,10 @@ namespace YooAsset Status = AllAssetObjects == null ? EStatus.Fail : EStatus.Success; if (Status == EStatus.Fail) { - if (AssetType == null) - LastError = $"Failed to load sub assets : {AssetName} AssetType : null AssetBundle : {OwnerBundle.BundleFileInfo.BundleName}"; + if (MainAssetInfo.AssetType == null) + LastError = $"Failed to load sub assets : {MainAssetInfo.AssetName} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.BundleName}"; else - LastError = $"Failed to load sub assets : {AssetName} AssetType : {AssetType} AssetBundle : {OwnerBundle.BundleFileInfo.BundleName}"; + LastError = $"Failed to load sub assets : {MainAssetInfo.AssetName} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.BundleName}"; YooLogger.Error(LastError); } InvokeCompletion(); diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/CompletedProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/CompletedProvider.cs new file mode 100644 index 0000000..bf58be7 --- /dev/null +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/CompletedProvider.cs @@ -0,0 +1,33 @@ + +namespace YooAsset +{ + internal sealed class CompletedProvider : ProviderBase + { + public override float Progress + { + get + { + if (IsDone) + return 1f; + else + return 0; + } + } + + public CompletedProvider(AssetInfo assetInfo) : base(assetInfo) + { + } + public override void Update() + { + if (IsDone) + return; + + if (Status == EStatus.None) + { + Status = EStatus.Fail; + LastError = MainAssetInfo.Error; + InvokeCompletion(); + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/CompletedProvider.cs.meta b/Assets/YooAsset/Runtime/AssetSystem/Provider/CompletedProvider.cs.meta new file mode 100644 index 0000000..0390f84 --- /dev/null +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/CompletedProvider.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8e64fd2ee771f7d498838ebf375a9531 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs index ca8c704..6e08780 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs @@ -17,8 +17,7 @@ namespace YooAsset } } - public DatabaseAssetProvider(string assetPath, System.Type assetType) - : base(assetPath, assetType) + public DatabaseAssetProvider(AssetInfo assetInfo) : base(assetInfo) { } public override void Update() @@ -30,11 +29,11 @@ namespace YooAsset if (Status == EStatus.None) { // 检测资源文件是否存在 - string guid = UnityEditor.AssetDatabase.AssetPathToGUID(AssetPath); + string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath); if (string.IsNullOrEmpty(guid)) { Status = EStatus.Fail; - LastError = $"Not found asset : {AssetPath}"; + LastError = $"Not found asset : {MainAssetInfo.AssetPath}"; YooLogger.Error(LastError); InvokeCompletion(); return; @@ -50,10 +49,10 @@ namespace YooAsset // 1. 加载资源对象 if (Status == EStatus.Loading) { - if (AssetType == null) - AssetObject = UnityEditor.AssetDatabase.LoadMainAssetAtPath(AssetPath); + if (MainAssetInfo.AssetType == null) + AssetObject = UnityEditor.AssetDatabase.LoadMainAssetAtPath(MainAssetInfo.AssetPath); else - AssetObject = UnityEditor.AssetDatabase.LoadAssetAtPath(AssetPath, AssetType); + AssetObject = UnityEditor.AssetDatabase.LoadAssetAtPath(MainAssetInfo.AssetPath, MainAssetInfo.AssetType); Status = EStatus.Checking; } @@ -66,7 +65,7 @@ namespace YooAsset { AssetObject = null; Status = EStatus.Fail; - LastError = $"The loaded asset object is not main asset : {AssetPath} AssetType : {AssetType}"; + LastError = $"The loaded asset object is not main asset : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}"; YooLogger.Error(LastError); InvokeCompletion(); return; @@ -76,12 +75,12 @@ namespace YooAsset Status = AssetObject == null ? EStatus.Fail : EStatus.Success; if (Status == EStatus.Fail) { - if (AssetType == null) - LastError = $"Failed to load asset object : {AssetPath} AssetType : null"; + if (MainAssetInfo.AssetType == null) + LastError = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : null"; else - LastError = $"Failed to load asset object : {AssetPath} AssetType : {AssetType}"; + LastError = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}"; YooLogger.Error(LastError); - } + } InvokeCompletion(); } #endif diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs index c2a17bf..5a96241 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs @@ -19,8 +19,7 @@ namespace YooAsset } } - public DatabaseSceneProvider(string scenePath, LoadSceneMode sceneMode, bool activateOnLoad, int priority) - : base(scenePath, null) + public DatabaseSceneProvider(AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) : base(assetInfo) { SceneMode = sceneMode; _activateOnLoad = activateOnLoad; @@ -42,7 +41,7 @@ namespace YooAsset { LoadSceneParameters loadSceneParameters = new LoadSceneParameters(); loadSceneParameters.loadSceneMode = SceneMode; - _asyncOp = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(AssetPath, loadSceneParameters); + _asyncOp = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters); if (_asyncOp != null) { _asyncOp.allowSceneActivation = true; @@ -52,7 +51,7 @@ namespace YooAsset else { Status = EStatus.Fail; - LastError = $"Failed to load scene : {AssetPath}"; + LastError = $"Failed to load scene : {MainAssetInfo.AssetPath}"; YooLogger.Error(LastError); InvokeCompletion(); } @@ -70,7 +69,7 @@ namespace YooAsset Status = SceneObject.IsValid() ? EStatus.Success : EStatus.Fail; if (Status == EStatus.Fail) { - LastError = $"The loaded scene is invalid : {AssetPath}"; + LastError = $"The loaded scene is invalid : {MainAssetInfo.AssetPath}"; YooLogger.Error(LastError); } InvokeCompletion(); diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSubAssetsProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSubAssetsProvider.cs index ad71171..db7579b 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSubAssetsProvider.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSubAssetsProvider.cs @@ -17,8 +17,7 @@ namespace YooAsset } } - public DatabaseSubAssetsProvider(string assetPath, System.Type assetType) - : base(assetPath, assetType) + public DatabaseSubAssetsProvider(AssetInfo assetInfo) : base(assetInfo) { } public override void Update() @@ -30,11 +29,11 @@ namespace YooAsset if (Status == EStatus.None) { // 检测资源文件是否存在 - string guid = UnityEditor.AssetDatabase.AssetPathToGUID(AssetPath); + string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath); if (string.IsNullOrEmpty(guid)) { Status = EStatus.Fail; - LastError = $"Not found asset : {AssetPath}"; + LastError = $"Not found asset : {MainAssetInfo.AssetPath}"; YooLogger.Error(LastError); InvokeCompletion(); return; @@ -50,17 +49,17 @@ namespace YooAsset // 1. 加载资源对象 if (Status == EStatus.Loading) { - if (AssetType == null) + if (MainAssetInfo.AssetType == null) { - AllAssetObjects = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(AssetPath); + AllAssetObjects = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(MainAssetInfo.AssetPath); } else { - UnityEngine.Object[] findAssets = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(AssetPath); + UnityEngine.Object[] findAssets = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(MainAssetInfo.AssetPath); List result = new List(findAssets.Length); foreach (var findAsset in findAssets) { - if (AssetType.IsAssignableFrom(findAsset.GetType())) + if (MainAssetInfo.AssetType.IsAssignableFrom(findAsset.GetType())) result.Add(findAsset); } AllAssetObjects = result.ToArray(); @@ -74,10 +73,10 @@ namespace YooAsset Status = AllAssetObjects == null ? EStatus.Fail : EStatus.Success; if (Status == EStatus.Fail) { - if (AssetType == null) - LastError = $"Failed to load sub assets : {AssetPath} AssetType : null"; + if (MainAssetInfo.AssetType == null) + LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null"; else - LastError = $"Failed to load sub assets : {AssetPath} AssetType : {AssetType}"; + LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}"; YooLogger.Error(LastError); } InvokeCompletion(); diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs index 0e0c78d..887ebf6 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs @@ -18,19 +18,9 @@ namespace YooAsset } /// - /// 资源路径 + /// 资源信息 /// - public string AssetPath { private set; get; } - - /// - /// 资源对象的名称 - /// - public string AssetName { private set; get; } - - /// - /// 资源对象的类型 - /// - public System.Type AssetType { private set; get; } + public AssetInfo MainAssetInfo { private set; get; } /// /// 获取的资源对象 @@ -95,11 +85,9 @@ namespace YooAsset private readonly List _handles = new List(); - public ProviderBase(string assetPath, System.Type assetType) + public ProviderBase(AssetInfo assetInfo) { - AssetPath = assetPath; - AssetName = System.IO.Path.GetFileName(assetPath); - AssetType = assetType; + MainAssetInfo = assetInfo; } /// @@ -126,25 +114,38 @@ namespace YooAsset return RefCount <= 0; } + /// + /// 是否为场景提供者 + /// + public bool IsSceneProvider() + { + if (this is BundledSceneProvider || this is DatabaseSceneProvider) + return true; + else + return false; + } + /// /// 创建操作句柄 /// /// - public OperationHandleBase CreateHandle() + public T CreateHandle() where T : OperationHandleBase { // 引用计数增加 RefCount++; OperationHandleBase handle; - if (IsSceneProvider()) + if (typeof(T) == typeof(AssetOperationHandle)) + handle = new AssetOperationHandle(this); + else if (typeof(T) == typeof(SceneOperationHandle)) handle = new SceneOperationHandle(this); - else if (IsSubAssetsProvider()) + else if (typeof(T) == typeof(SubAssetsOperationHandle)) handle = new SubAssetsOperationHandle(this); else - handle = new AssetOperationHandle(this); + throw new System.NotImplementedException(); _handles.Add(handle); - return handle; + return handle as T; } /// @@ -175,7 +176,7 @@ namespace YooAsset // 验证结果 if (IsDone == false) { - YooLogger.Warning($"WaitForAsyncComplete failed to loading : {AssetPath}"); + YooLogger.Warning($"WaitForAsyncComplete failed to loading : {MainAssetInfo.AssetPath}"); } } @@ -196,21 +197,6 @@ namespace YooAsset } } - public bool IsSceneProvider() - { - if (this is BundledSceneProvider || this is DatabaseSceneProvider) - return true; - else - return false; - } - public bool IsSubAssetsProvider() - { - if (this is BundledSubAssetsProvider || this is DatabaseSubAssetsProvider) - return true; - else - return false; - } - #region 异步编程相关 private TaskCompletionSource _taskCompletionSource; protected void InvokeCompletion() diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystem.cs b/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystem.cs index c77c992..2b59106 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystem.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/DownloadSystem.cs @@ -15,7 +15,7 @@ namespace YooAsset private static readonly Dictionary _downloaderDic = new Dictionary(); private static readonly List _removeList = new List(100); private static readonly Dictionary _cachedHashList = new Dictionary(1000); - private static int _breakpointResumeFileSize; + private static int _breakpointResumeFileSize = int.MaxValue; /// /// 初始化 diff --git a/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs b/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs index 730f6a6..3733c12 100644 --- a/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs +++ b/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs @@ -48,7 +48,7 @@ namespace YooAsset /// /// 开始处理异步操作类 /// - public static void ProcessOperaiton(AsyncOperationBase operationBase) + public static void StartOperaiton(AsyncOperationBase operationBase) { _operations.Add(operationBase); operationBase.Start(); diff --git a/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs b/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs index 6a0767a..6738426 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/AssetInfo.cs @@ -1,8 +1,35 @@ - +using System.IO; + namespace YooAsset { public class AssetInfo { + private readonly PatchAsset _patchAsset; + private string _providerGUID; + + /// + /// 资源提供者唯一标识符 + /// + internal string ProviderGUID + { + get + { + if (string.IsNullOrEmpty(_providerGUID) == false) + return _providerGUID; + + if (AssetType == null) + _providerGUID = $"{AssetPath}[null]"; + else + _providerGUID = $"{AssetPath}[{AssetType.Name}]"; + return _providerGUID; + } + } + + /// + /// 资源对象名称 + /// + public string AssetName { private set; get; } + /// /// 资源路径 /// @@ -13,15 +40,55 @@ namespace YooAsset /// public System.Type AssetType { private set; get; } - public AssetInfo(string assetPath, System.Type assetType) + /// + /// 身份是否无效 + /// + public bool IsInvalid { - AssetPath = assetPath; - AssetType = assetType; + get + { + return _patchAsset == null; + } } - public AssetInfo(string assetPath) + + /// + /// 错误信息 + /// + public string Error { private set; get; } + + + private AssetInfo() { - AssetPath = assetPath; + } + internal AssetInfo(PatchAsset patchAsset, System.Type assetType) + { + if (patchAsset == null) + throw new System.Exception("Should never get here !"); + + _patchAsset = patchAsset; + AssetType = assetType; + AssetPath = patchAsset.AssetPath; + AssetName = Path.GetFileName(patchAsset.AssetPath); + Error = string.Empty; + } + internal AssetInfo(PatchAsset patchAsset) + { + if (patchAsset == null) + throw new System.Exception("Should never get here !"); + + _patchAsset = patchAsset; AssetType = null; + AssetPath = patchAsset.AssetPath; + AssetName = Path.GetFileName(patchAsset.AssetPath); + Error = string.Empty; + } + internal AssetInfo(string error) + { + _patchAsset = null; + AssetType = null; + AssetPath = string.Empty; + AssetName = string.Empty; + Error = error; } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PatchSystem/BundleInfo.cs b/Assets/YooAsset/Runtime/PatchSystem/BundleInfo.cs index 3a5f26b..ae18bfc 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/BundleInfo.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/BundleInfo.cs @@ -1,9 +1,9 @@  namespace YooAsset { - public class BundleInfo + internal class BundleInfo { - internal enum ELoadMode + public enum ELoadMode { None, LoadFromStreaming, @@ -13,7 +13,7 @@ namespace YooAsset } private readonly PatchBundle _patchBundle; - internal readonly ELoadMode LoadMode; + public readonly ELoadMode LoadMode; private string _streamingPath; private string _cachePath; @@ -26,17 +26,17 @@ namespace YooAsset /// /// 远端下载地址 /// - internal string RemoteMainURL { private set; get; } + public string RemoteMainURL { private set; get; } /// /// 远端下载备用地址 /// - internal string RemoteFallbackURL { private set; get; } + public string RemoteFallbackURL { private set; get; } /// /// 编辑器资源路径 /// - internal string EditorAssetPath { private set; get; } + public string EditorAssetPath { private set; get; } /// /// 文件哈希值 @@ -108,11 +108,27 @@ namespace YooAsset } } + /// + /// 身份是否无效 + /// + public bool IsInvalid + { + get + { + return _patchBundle == null; + } + } + + /// + /// 错误信息 + /// + public string Error { private set; get; } + private BundleInfo() { } - internal BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string mainURL, string fallbackURL) + public BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string mainURL, string fallbackURL) { _patchBundle = patchBundle; LoadMode = loadMode; @@ -120,8 +136,9 @@ namespace YooAsset RemoteMainURL = mainURL; RemoteFallbackURL = fallbackURL; EditorAssetPath = string.Empty; + Error = string.Empty; } - internal BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string editorAssetPath) + public BundleInfo(PatchBundle patchBundle, ELoadMode loadMode, string editorAssetPath) { _patchBundle = patchBundle; LoadMode = loadMode; @@ -129,8 +146,9 @@ namespace YooAsset RemoteMainURL = string.Empty; RemoteFallbackURL = string.Empty; EditorAssetPath = editorAssetPath; + Error = string.Empty; } - internal BundleInfo(PatchBundle patchBundle, ELoadMode loadMode) + public BundleInfo(PatchBundle patchBundle, ELoadMode loadMode) { _patchBundle = patchBundle; LoadMode = loadMode; @@ -138,37 +156,23 @@ namespace YooAsset RemoteMainURL = string.Empty; RemoteFallbackURL = string.Empty; EditorAssetPath = string.Empty; + Error = string.Empty; } - internal BundleInfo(string bundleName) + public BundleInfo(string error) { _patchBundle = null; LoadMode = ELoadMode.None; - BundleName = bundleName; + BundleName = string.Empty; RemoteMainURL = string.Empty; RemoteFallbackURL = string.Empty; EditorAssetPath = string.Empty; - } - - /// - /// 资源包是否有效 - /// - public bool IsValid() - { - return _patchBundle != null; - } - - /// - /// 资源包文件是否在云端 - /// - public bool InCloud() - { - return LoadMode == ELoadMode.LoadFromRemote; + Error = error; } /// /// 获取流文件夹的加载路径 /// - internal string GetStreamingLoadPath() + public string GetStreamingLoadPath() { if (_patchBundle == null) return string.Empty; @@ -181,7 +185,7 @@ namespace YooAsset /// /// 获取缓存文件夹的加载路径 /// - internal string GetCacheLoadPath() + public string GetCacheLoadPath() { if (_patchBundle == null) return string.Empty; @@ -191,7 +195,6 @@ namespace YooAsset return _cachePath; } - /// /// 是否为JAR包内文件 /// diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs index 1e01f08..6615234 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs @@ -192,7 +192,7 @@ namespace YooAsset { if (_steps == ESteps.None) { - OperationSystem.ProcessOperaiton(this); + OperationSystem.StartOperaiton(this); } } } diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs index 06e84de..f7628ed 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs @@ -61,90 +61,6 @@ namespace YooAsset private bool _locationToLower = false; - /// - /// 获取内置资源标签列表 - /// - public string[] GetBuildinTags() - { - return StringUtility.StringToStringList(BuildinTags, ';').ToArray(); - } - - /// - /// 获取资源依赖列表 - /// - public string[] GetAllDependencies(string assetPath) - { - if (Assets.TryGetValue(assetPath, out PatchAsset patchAsset)) - { - List result = new List(patchAsset.DependIDs.Length); - foreach (var dependID in patchAsset.DependIDs) - { - if (dependID >= 0 && dependID < BundleList.Count) - { - var dependPatchBundle = BundleList[dependID]; - result.Add(dependPatchBundle.BundleName); - } - else - { - throw new Exception($"Invalid bundle id : {dependID} Asset path : {assetPath}"); - } - } - return result.ToArray(); - } - else - { - YooLogger.Warning($"Not found asset path in patch manifest : {assetPath}"); - return new string[] { }; - } - } - - /// - /// 获取资源包名称 - /// - public string GetBundleName(string assetPath) - { - if (Assets.TryGetValue(assetPath, out PatchAsset patchAsset)) - { - int bundleID = patchAsset.BundleID; - if (bundleID >= 0 && bundleID < BundleList.Count) - { - var patchBundle = BundleList[bundleID]; - return patchBundle.BundleName; - } - else - { - throw new Exception($"Invalid bundle id : {bundleID} Asset path : {assetPath}"); - } - } - else - { - YooLogger.Warning($"Not found asset path in patch manifest : {assetPath}"); - return string.Empty; - } - } - - /// - /// 尝试获取资源包的主资源路径 - /// - public string TryGetBundleMainAssetPath(string bundleName) - { - foreach (var patchAsset in AssetList) - { - int bundleID = patchAsset.BundleID; - if (bundleID >= 0 && bundleID < BundleList.Count) - { - var patchBundle = BundleList[bundleID]; - if (patchBundle.BundleName == bundleName) - return patchAsset.AssetPath; - } - else - { - throw new Exception($"Invalid bundle id : {bundleID} Asset path : {patchAsset.AssetPath}"); - } - } - return string.Empty; - } - /// /// 初始化资源路径映射 /// @@ -201,6 +117,12 @@ namespace YooAsset /// public string MappingToAssetPath(string location) { + if(string.IsNullOrEmpty(location)) + { + YooLogger.Error("Failed to mapping location to asset path, The location is null or empty."); + return string.Empty; + } + if (_locationToLower) location = location.ToLower(); @@ -210,11 +132,65 @@ namespace YooAsset } else { - YooLogger.Error($"Failed to mapping location to asset path : {location}"); + YooLogger.Warning($"Failed to mapping location to asset path : {location}"); return string.Empty; } } + /// + /// 获取资源包名称 + /// 注意:传入的资源路径一定合法有效! + /// + public string GetBundleName(string assetPath) + { + if (Assets.TryGetValue(assetPath, out PatchAsset patchAsset)) + { + int bundleID = patchAsset.BundleID; + if (bundleID >= 0 && bundleID < BundleList.Count) + { + var patchBundle = BundleList[bundleID]; + return patchBundle.BundleName; + } + else + { + throw new Exception($"Invalid bundle id : {bundleID} Asset path : {assetPath}"); + } + } + else + { + throw new Exception("Should never get here !"); + } + } + + /// + /// 获取资源依赖列表 + /// 注意:传入的资源路径一定合法有效! + /// + public string[] GetAllDependencies(string assetPath) + { + if (Assets.TryGetValue(assetPath, out PatchAsset patchAsset)) + { + List result = new List(patchAsset.DependIDs.Length); + foreach (var dependID in patchAsset.DependIDs) + { + if (dependID >= 0 && dependID < BundleList.Count) + { + var dependPatchBundle = BundleList[dependID]; + result.Add(dependPatchBundle.BundleName); + } + else + { + throw new Exception($"Invalid bundle id : {dependID} Asset path : {assetPath}"); + } + } + return result.ToArray(); + } + else + { + throw new Exception("Should never get here !"); + } + } + /// /// 序列化 diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs index 964e729..8f3bc42 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorSimulateModeImpl.cs @@ -16,7 +16,7 @@ namespace YooAsset { _locationToLower = locationToLower; var operation = new EditorSimulateModeInitializationOperation(this, simulatePatchManifestPath); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } @@ -38,44 +38,41 @@ namespace YooAsset } #region IBundleServices接口 - BundleInfo IBundleServices.GetBundleInfo(string bundleName) + BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo) { - if (string.IsNullOrEmpty(bundleName)) - return new BundleInfo(string.Empty); + if(assetInfo.IsInvalid) + throw new Exception("Should never get here !"); + string bundleName = _simulatePatchManifest.GetBundleName(assetInfo.AssetPath); if (_simulatePatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle)) { - string mainAssetPath = _simulatePatchManifest.TryGetBundleMainAssetPath(bundleName); - BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromEditor, mainAssetPath); + BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromEditor, assetInfo.AssetPath); return bundleInfo; } else { - YooLogger.Warning($"Not found bundle in patch manifest : {bundleName}"); - BundleInfo bundleInfo = new BundleInfo(bundleName); - return bundleInfo; + throw new Exception("Should never get here !"); } } - AssetInfo[] IBundleServices.GetAssetInfos(string bundleName) + BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo) { - return PatchHelper.GetAssetsInfoByBundleName(_simulatePatchManifest, bundleName); + throw new NotImplementedException(); } AssetInfo[] IBundleServices.GetAssetInfos(string[] tags) { return PatchHelper.GetAssetsInfoByTags(_simulatePatchManifest, tags); } + PatchAsset IBundleServices.TryGetPatchAsset(string assetPath) + { + if (_simulatePatchManifest.Assets.TryGetValue(assetPath, out PatchAsset patchAsset)) + return patchAsset; + else + return null; + } string IBundleServices.MappingToAssetPath(string location) { return _simulatePatchManifest.MappingToAssetPath(location); } - string IBundleServices.GetBundleName(string assetPath) - { - return _simulatePatchManifest.GetBundleName(assetPath); - } - string[] IBundleServices.GetAllDependencies(string assetPath) - { - return _simulatePatchManifest.GetAllDependencies(assetPath); - } #endregion } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs index 8d608dd..467111a 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/HostPlayModeImpl.cs @@ -28,7 +28,7 @@ namespace YooAsset _fallbackHostServer = fallbackHostServer; var operation = new HostPlayModeInitializationOperation(this); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } @@ -38,7 +38,7 @@ namespace YooAsset public UpdateStaticVersionOperation UpdateStaticVersionAsync(int timeout) { var operation = new HostPlayModeUpdateStaticVersionOperation(this, timeout); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } @@ -48,7 +48,7 @@ namespace YooAsset public UpdateManifestOperation UpdatePatchManifestAsync(int resourceVersion, int timeout) { var operation = new HostPlayModeUpdateManifestOperation(this, resourceVersion, timeout); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } @@ -58,7 +58,7 @@ namespace YooAsset public UpdatePackageOperation UpdatePackageAsync(int resourceVersion, int timeout) { var operation = new HostPlayModeUpdatePackageOperation(this, resourceVersion, timeout); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } @@ -182,29 +182,32 @@ namespace YooAsset /// /// 创建下载器 /// - public PatchDownloaderOperation CreatePatchDownloaderByPaths(List assetPaths, int fileLoadingMaxNumber, int failedTryAgain) + public PatchDownloaderOperation CreatePatchDownloaderByPaths(AssetInfo[] assetInfos, int fileLoadingMaxNumber, int failedTryAgain) { - List downloadList = GetDownloadListByPaths(assetPaths); + List downloadList = GetDownloadListByPaths(assetInfos); var operation = new PatchDownloaderOperation(downloadList, fileLoadingMaxNumber, failedTryAgain); return operation; } - private List GetDownloadListByPaths(List assetPaths) + private List GetDownloadListByPaths(AssetInfo[] assetInfos) { // 获取资源对象的资源包和所有依赖资源包 List checkList = new List(); - foreach (var assetPath in assetPaths) + foreach (var assetInfo in assetInfos) { - string mainBundleName = LocalPatchManifest.GetBundleName(assetPath); - if (string.IsNullOrEmpty(mainBundleName) == false) + if (assetInfo.IsInvalid) { - if (LocalPatchManifest.Bundles.TryGetValue(mainBundleName, out PatchBundle mainBundle)) - { - if (checkList.Contains(mainBundle) == false) - checkList.Add(mainBundle); - } + YooLogger.Warning(assetInfo.Error); + continue; } - string[] dependBundleNames = LocalPatchManifest.GetAllDependencies(assetPath); + string mainBundleName = LocalPatchManifest.GetBundleName(assetInfo.AssetPath); + if (LocalPatchManifest.Bundles.TryGetValue(mainBundleName, out PatchBundle mainBundle)) + { + if (checkList.Contains(mainBundle) == false) + checkList.Add(mainBundle); + } + + string[] dependBundleNames = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath); foreach (var dependBundleName in dependBundleNames) { if (LocalPatchManifest.Bundles.TryGetValue(dependBundleName, out PatchBundle dependBundle)) @@ -245,6 +248,12 @@ namespace YooAsset var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain); return operation; } + public PatchUnpackerOperation CreatePatchUnpackerByAll(int fileUpackingMaxNumber, int failedTryAgain) + { + List unpcakList = PatchHelper.GetUnpackListByAll(AppPatchManifest); + var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain); + return operation; + } // WEB相关 public string GetPatchDownloadMainURL(string fileName) @@ -288,11 +297,8 @@ namespace YooAsset } #region IBundleServices接口 - BundleInfo IBundleServices.GetBundleInfo(string bundleName) + private BundleInfo CreateBundleInfo(string bundleName) { - if (string.IsNullOrEmpty(bundleName)) - return new BundleInfo(string.Empty); - if (LocalPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle)) { // 查询沙盒资源 @@ -317,31 +323,46 @@ namespace YooAsset } else { - YooLogger.Warning($"Not found bundle in patch manifest : {bundleName}"); - BundleInfo bundleInfo = new BundleInfo(bundleName); - return bundleInfo; + throw new Exception("Should never get here !"); } } - AssetInfo[] IBundleServices.GetAssetInfos(string bundleName) + BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo) { - return PatchHelper.GetAssetsInfoByBundleName(LocalPatchManifest, bundleName); + if (assetInfo.IsInvalid) + throw new Exception("Should never get here !"); + + string bundleName = LocalPatchManifest.GetBundleName(assetInfo.AssetPath); + return CreateBundleInfo(bundleName); + } + BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo) + { + if (assetInfo.IsInvalid) + throw new Exception("Should never get here !"); + + var depends = LocalPatchManifest.GetAllDependencies(assetInfo.AssetPath); + List result = new List(depends.Length); + foreach (var bundleName in depends) + { + BundleInfo bundleInfo = CreateBundleInfo(bundleName); + result.Add(bundleInfo); + } + return result.ToArray(); } AssetInfo[] IBundleServices.GetAssetInfos(string[] tags) { return PatchHelper.GetAssetsInfoByTags(LocalPatchManifest, tags); } + PatchAsset IBundleServices.TryGetPatchAsset(string assetPath) + { + if (LocalPatchManifest.Assets.TryGetValue(assetPath, out PatchAsset patchAsset)) + return patchAsset; + else + return null; + } string IBundleServices.MappingToAssetPath(string location) { return LocalPatchManifest.MappingToAssetPath(location); } - string IBundleServices.GetBundleName(string assetPath) - { - return LocalPatchManifest.GetBundleName(assetPath); - } - string[] IBundleServices.GetAllDependencies(string assetPath) - { - return LocalPatchManifest.GetAllDependencies(assetPath); - } #endregion } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs index 2847a16..40e080a 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PlayMode/OfflinePlayModeImpl.cs @@ -16,7 +16,7 @@ namespace YooAsset { _locationToLower = locationToLower; var operation = new OfflinePlayModeInitializationOperation(this); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } @@ -39,6 +39,12 @@ namespace YooAsset var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain); return operation; } + public PatchUnpackerOperation CreatePatchUnpackerByAll(int fileUpackingMaxNumber, int failedTryAgain) + { + List unpcakList = PatchHelper.GetUnpackListByAll(_appPatchManifest); + var operation = new PatchUnpackerOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain); + return operation; + } // 设置资源清单 internal void SetAppPatchManifest(PatchManifest patchManifest) @@ -48,11 +54,8 @@ namespace YooAsset } #region IBundleServices接口 - BundleInfo IBundleServices.GetBundleInfo(string bundleName) + private BundleInfo CreateBundleInfo(string bundleName) { - if (string.IsNullOrEmpty(bundleName)) - return new BundleInfo(string.Empty); - if (_appPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle patchBundle)) { BundleInfo bundleInfo = new BundleInfo(patchBundle, BundleInfo.ELoadMode.LoadFromStreaming); @@ -60,31 +63,46 @@ namespace YooAsset } else { - YooLogger.Warning($"Not found bundle in patch manifest : {bundleName}"); - BundleInfo bundleInfo = new BundleInfo(bundleName); - return bundleInfo; + throw new Exception("Should never get here !"); } } - AssetInfo[] IBundleServices.GetAssetInfos(string bundleName) + BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo) { - return PatchHelper.GetAssetsInfoByBundleName(_appPatchManifest, bundleName); + if (assetInfo.IsInvalid) + throw new Exception("Should never get here !"); + + string bundleName = _appPatchManifest.GetBundleName(assetInfo.AssetPath); + return CreateBundleInfo(bundleName); + } + BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo) + { + if (assetInfo.IsInvalid) + throw new Exception("Should never get here !"); + + var depends = _appPatchManifest.GetAllDependencies(assetInfo.AssetPath); + List result = new List(depends.Length); + foreach (var bundleName in depends) + { + BundleInfo bundleInfo = CreateBundleInfo(bundleName); + result.Add(bundleInfo); + } + return result.ToArray(); } AssetInfo[] IBundleServices.GetAssetInfos(string[] tags) { return PatchHelper.GetAssetsInfoByTags(_appPatchManifest, tags); } + PatchAsset IBundleServices.TryGetPatchAsset(string assetPath) + { + if (_appPatchManifest.Assets.TryGetValue(assetPath, out PatchAsset patchAsset)) + return patchAsset; + else + return null; + } string IBundleServices.MappingToAssetPath(string location) { return _appPatchManifest.MappingToAssetPath(location); } - string IBundleServices.GetBundleName(string assetPath) - { - return _appPatchManifest.GetBundleName(assetPath); - } - string[] IBundleServices.GetAllDependencies(string assetPath) - { - return _appPatchManifest.GetAllDependencies(assetPath); - } #endregion } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/Services/IBundleServices.cs b/Assets/YooAsset/Runtime/Services/IBundleServices.cs index 7fea0d0..3eb381c 100644 --- a/Assets/YooAsset/Runtime/Services/IBundleServices.cs +++ b/Assets/YooAsset/Runtime/Services/IBundleServices.cs @@ -6,31 +6,26 @@ namespace YooAsset /// /// 获取资源包信息 /// - BundleInfo GetBundleInfo(string bundleName); + BundleInfo GetBundleInfo(AssetInfo assetInfo); /// - /// 获取资源信息列表 + /// 获取依赖的资源包信息集合 /// - AssetInfo[] GetAssetInfos(string bundleName); + BundleInfo[] GetAllDependBundleInfos(AssetInfo assetPath); /// /// 获取资源信息列表 /// AssetInfo[] GetAssetInfos(string[] tags); + /// + /// 尝试获取补丁资源 + /// + PatchAsset TryGetPatchAsset(string assetPath); + /// /// 映射为资源路径 /// string MappingToAssetPath(string location); - - /// - /// 获取资源所属的资源包名称 - /// - string GetBundleName(string assetPath); - - /// - /// 获取资源依赖的所有AssetBundle列表 - /// - string[] GetAllDependencies(string assetPath); } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/Services/IDecryptionServices.cs b/Assets/YooAsset/Runtime/Services/IDecryptionServices.cs index 58434f7..47ff2bd 100644 --- a/Assets/YooAsset/Runtime/Services/IDecryptionServices.cs +++ b/Assets/YooAsset/Runtime/Services/IDecryptionServices.cs @@ -6,6 +6,6 @@ namespace YooAsset /// /// 获取加密文件的数据偏移量 /// - ulong GetFileOffset(BundleInfo bundleInfo); + ulong GetFileOffset(); } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs b/Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs index cce26b7..ff1d7e7 100644 --- a/Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs +++ b/Assets/YooAsset/Runtime/Services/LocationServices/AddressLocationServices.cs @@ -3,7 +3,7 @@ namespace YooAsset { public class AddressLocationServices : ILocationServices { - public string ConvertLocationToAssetPath(string location) + string ILocationServices.ConvertLocationToAssetPath(string location) { return YooAssets.MappingToAssetPath(location); } diff --git a/Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs b/Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs index 53126c6..a0338ed 100644 --- a/Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs +++ b/Assets/YooAsset/Runtime/Services/LocationServices/DefaultLocationServices.cs @@ -11,7 +11,7 @@ namespace YooAsset _resourceRoot = PathHelper.GetRegularPath(resourceRoot); } - public string ConvertLocationToAssetPath(string location) + string ILocationServices.ConvertLocationToAssetPath(string location) { if (string.IsNullOrEmpty(_resourceRoot)) { diff --git a/Assets/YooAsset/Runtime/Utility/YooHelper.cs b/Assets/YooAsset/Runtime/Utility/YooHelper.cs index 0ab520c..deda52f 100644 --- a/Assets/YooAsset/Runtime/Utility/YooHelper.cs +++ b/Assets/YooAsset/Runtime/Utility/YooHelper.cs @@ -151,6 +151,26 @@ namespace YooAsset return ConvertToUnpackList(downloadList); } + public static List GetUnpackListByAll(PatchManifest appPatchManifest) + { + // 注意:离线运行模式也依赖下面逻辑,所以判断沙盒内文件是否存在不能通过缓存系统去验证。 + List downloadList = new List(1000); + foreach (var patchBundle in appPatchManifest.BundleList) + { + // 如果已经在沙盒内 + string filePath = SandboxHelper.MakeCacheFilePath(patchBundle.Hash); + if (System.IO.File.Exists(filePath)) + continue; + + // 如果不是内置资源 + if (patchBundle.IsBuildin == false) + continue; + + downloadList.Add(patchBundle); + } + + return ConvertToUnpackList(downloadList); + } private static List ConvertToUnpackList(List unpackList) { List result = new List(unpackList.Count); @@ -178,31 +198,13 @@ namespace YooAsset List result = new List(100); foreach (var patchAsset in patchManifest.AssetList) { - string bundleName = patchManifest.GetBundleName(patchAsset.AssetPath); - if(patchManifest.Bundles.TryGetValue(bundleName, out PatchBundle bundle)) + if(patchAsset.HasTag(tags)) { - if(bundle.HasTag(tags)) - { - result.Add(new AssetInfo(patchAsset.AssetPath)); - } + AssetInfo assetInfo = new AssetInfo(patchAsset); + result.Add(assetInfo); } } return result.ToArray(); } - - /// - /// 获取资源信息列表 - /// - public static AssetInfo[] GetAssetsInfoByBundleName(PatchManifest patchManifest, string bundleName) - { - List result = new List(100); - foreach (var patchAsset in patchManifest.AssetList) - { - string tempName = patchManifest.GetBundleName(patchAsset.AssetPath); - if (tempName == bundleName) - result.Add(new AssetInfo(patchAsset.AssetPath)); - } - return result.ToArray(); - } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index 08c6be1..ba085b9 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -149,19 +149,19 @@ namespace YooAsset throw new Exception("YooAsset is initialized yet."); } + // 检测参数范围 if (parameters.AssetLoadingMaxNumber < 1) { parameters.AssetLoadingMaxNumber = 1; YooLogger.Warning($"{nameof(parameters.AssetLoadingMaxNumber)} minimum value is 1"); } - if (parameters.OperationSystemMaxTimeSlice < 30) { parameters.OperationSystemMaxTimeSlice = 30; - YooLogger.Warning($"{nameof(parameters.OperationSystemMaxTimeSlice)} minimum value is 33 milliseconds"); + YooLogger.Warning($"{nameof(parameters.OperationSystemMaxTimeSlice)} minimum value is 30 milliseconds"); } - // 运行模式 + // 鉴定运行模式 if (parameters is EditorSimulateModeParameters) _playMode = EPlayMode.EditorSimulateMode; else if (parameters is OfflinePlayModeParameters) @@ -241,19 +241,17 @@ namespace YooAsset if (_playMode == EPlayMode.EditorSimulateMode) { var operation = new EditorPlayModeUpdateStaticVersionOperation(); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } else if (_playMode == EPlayMode.OfflinePlayMode) { var operation = new OfflinePlayModeUpdateStaticVersionOperation(); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } else if (_playMode == EPlayMode.HostPlayMode) { - if (_hostPlayModeImpl == null) - throw new Exception("YooAsset is not initialized."); return _hostPlayModeImpl.UpdateStaticVersionAsync(timeout); } else @@ -273,19 +271,17 @@ namespace YooAsset if (_playMode == EPlayMode.EditorSimulateMode) { var operation = new EditorPlayModeUpdateManifestOperation(); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } else if (_playMode == EPlayMode.OfflinePlayMode) { var operation = new OfflinePlayModeUpdateManifestOperation(); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } else if (_playMode == EPlayMode.HostPlayMode) { - if (_hostPlayModeImpl == null) - throw new Exception("YooAsset is not initialized."); return _hostPlayModeImpl.UpdatePatchManifestAsync(resourceVersion, timeout); } else @@ -298,9 +294,9 @@ namespace YooAsset /// 开启一个异步操作 /// /// 异步操作对象 - public static void ProcessOperaiton(GameAsyncOperation operation) + public static void StartOperaiton(GameAsyncOperation operation) { - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); } /// @@ -311,20 +307,14 @@ namespace YooAsset DebugCheckInitialize(); if (_playMode == EPlayMode.EditorSimulateMode) { - if (_editorSimulateModeImpl == null) - throw new Exception("YooAsset is not initialized."); return _editorSimulateModeImpl.GetResourceVersion(); } else if (_playMode == EPlayMode.OfflinePlayMode) { - if (_offlinePlayModeImpl == null) - throw new Exception("YooAsset is not initialized."); return _offlinePlayModeImpl.GetResourceVersion(); } else if (_playMode == EPlayMode.HostPlayMode) { - if (_hostPlayModeImpl == null) - throw new Exception("YooAsset is not initialized."); return _hostPlayModeImpl.GetResourceVersion(); } else @@ -338,8 +328,11 @@ namespace YooAsset /// public static void UnloadUnusedAssets() { - AssetSystem.Update(); - AssetSystem.UnloadUnusedAssets(); + if (_isInitialize) + { + AssetSystem.Update(); + AssetSystem.UnloadUnusedAssets(); + } } /// @@ -347,52 +340,30 @@ namespace YooAsset /// public static void ForceUnloadAllAssets() { - AssetSystem.ForceUnloadAllAssets(); + if (_isInitialize) + { + AssetSystem.ForceUnloadAllAssets(); + } } - /// - /// 获取调试信息 - /// - internal static void GetDebugReport(DebugReport report) - { - if (report == null) - YooLogger.Error($"{nameof(DebugReport)} is null"); - - AssetSystem.GetDebugReport(report); - } #region 资源信息 /// - /// 获取资源包信息 + /// 是否需要从远端更新下载 /// /// 资源的定位地址 - public static BundleInfo GetBundleInfo(string location) + public static bool IsNeedDownloadFromRemote(string location) { DebugCheckInitialize(); - string assetPath = _locationServices.ConvertLocationToAssetPath(location); - string bundleName = _bundleServices.GetBundleName(assetPath); - return _bundleServices.GetBundleInfo(bundleName); - } - - /// - /// 获取资源包信息 - /// - /// 资源信息 - public static BundleInfo GetBundleInfo(AssetInfo assetInfo) - { - DebugCheckInitialize(); - string bundleName = _bundleServices.GetBundleName(assetInfo.AssetPath); - return _bundleServices.GetBundleInfo(bundleName); - } - - /// - /// 获取资源信息列表 - /// - /// 资源包信息 - public static AssetInfo[] GetAssetInfos(BundleInfo bundleInfo) - { - DebugCheckInitialize(); - return _bundleServices.GetAssetInfos(bundleInfo.BundleName); + AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); + if (assetInfo.IsInvalid) + return false; + + BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo); + if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote) + return true; + else + return false; } /// @@ -428,8 +399,8 @@ namespace YooAsset public static SceneOperationHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) { DebugCheckInitialize(); - string scenePath = _locationServices.ConvertLocationToAssetPath(location); - var handle = AssetSystem.LoadSceneAsync(scenePath, sceneMode, activateOnLoad, priority); + AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); + var handle = AssetSystem.LoadSceneAsync(assetInfo, sceneMode, activateOnLoad, priority); return handle; } @@ -443,8 +414,7 @@ namespace YooAsset public static SceneOperationHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) { DebugCheckInitialize(); - string scenePath = assetInfo.AssetPath; - var handle = AssetSystem.LoadSceneAsync(scenePath, sceneMode, activateOnLoad, priority); + var handle = AssetSystem.LoadSceneAsync(assetInfo, sceneMode, activateOnLoad, priority); return handle; } #endregion @@ -458,8 +428,8 @@ namespace YooAsset public static RawFileOperation GetRawFileAsync(string location, string copyPath = null) { DebugCheckInitialize(); - string assetPath = _locationServices.ConvertLocationToAssetPath(location); - return GetRawFileInternal(assetPath, copyPath); + AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); + return GetRawFileInternal(assetInfo, copyPath); } /// @@ -470,31 +440,36 @@ namespace YooAsset public static RawFileOperation GetRawFileAsync(AssetInfo assetInfo, string copyPath = null) { DebugCheckInitialize(); - return GetRawFileInternal(assetInfo.AssetPath, copyPath); + return GetRawFileInternal(assetInfo, copyPath); } - private static RawFileOperation GetRawFileInternal(string assetPath, string copyPath) + private static RawFileOperation GetRawFileInternal(AssetInfo assetInfo, string copyPath) { - string bundleName = _bundleServices.GetBundleName(assetPath); - BundleInfo bundleInfo = _bundleServices.GetBundleInfo(bundleName); + if (assetInfo.IsInvalid) + { + RawFileOperation operation = new CompletedRawFileOperation(assetInfo.Error, copyPath); + OperationSystem.StartOperaiton(operation); + return operation; + } + BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo); if (_playMode == EPlayMode.EditorSimulateMode) { RawFileOperation operation = new EditorPlayModeRawFileOperation(bundleInfo, copyPath); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } else if (_playMode == EPlayMode.OfflinePlayMode) { RawFileOperation operation = new OfflinePlayModeRawFileOperation(bundleInfo, copyPath); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } else if (_playMode == EPlayMode.HostPlayMode) { RawFileOperation operation = new HostPlayModeRawFileOperation(bundleInfo, copyPath); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } else @@ -512,7 +487,7 @@ namespace YooAsset public static AssetOperationHandle LoadAssetSync(AssetInfo assetInfo) { DebugCheckInitialize(); - return LoadAssetInternal(assetInfo.AssetPath, assetInfo.AssetType, true); + return LoadAssetInternal(assetInfo, true); } /// @@ -523,8 +498,8 @@ namespace YooAsset public static AssetOperationHandle LoadAssetSync(string location) where TObject : class { DebugCheckInitialize(); - string assetPath = _locationServices.ConvertLocationToAssetPath(location); - return LoadAssetInternal(assetPath, typeof(TObject), true); + AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject)); + return LoadAssetInternal(assetInfo, true); } /// @@ -535,8 +510,8 @@ namespace YooAsset public static AssetOperationHandle LoadAssetSync(string location, System.Type type) { DebugCheckInitialize(); - string assetPath = _locationServices.ConvertLocationToAssetPath(location); - return LoadAssetInternal(assetPath, type, true); + AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type); + return LoadAssetInternal(assetInfo, true); } @@ -547,7 +522,7 @@ namespace YooAsset public static AssetOperationHandle LoadAssetAsync(AssetInfo assetInfo) { DebugCheckInitialize(); - return LoadAssetInternal(assetInfo.AssetPath, assetInfo.AssetType, false); + return LoadAssetInternal(assetInfo, false); } /// @@ -558,8 +533,8 @@ namespace YooAsset public static AssetOperationHandle LoadAssetAsync(string location) { DebugCheckInitialize(); - string assetPath = _locationServices.ConvertLocationToAssetPath(location); - return LoadAssetInternal(assetPath, typeof(TObject), false); + AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject)); + return LoadAssetInternal(assetInfo, false); } /// @@ -570,14 +545,14 @@ namespace YooAsset public static AssetOperationHandle LoadAssetAsync(string location, System.Type type) { DebugCheckInitialize(); - string assetPath = _locationServices.ConvertLocationToAssetPath(location); - return LoadAssetInternal(assetPath, type, false); + AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type); + return LoadAssetInternal(assetInfo, false); } - private static AssetOperationHandle LoadAssetInternal(string assetPath, System.Type assetType, bool waitForAsyncComplete) + private static AssetOperationHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete) { - var handle = AssetSystem.LoadAssetAsync(assetPath, assetType); + var handle = AssetSystem.LoadAssetAsync(assetInfo); if (waitForAsyncComplete) handle.WaitForAsyncComplete(); return handle; @@ -592,7 +567,7 @@ namespace YooAsset public static SubAssetsOperationHandle LoadSubAssetsSync(AssetInfo assetInfo) { DebugCheckInitialize(); - return LoadSubAssetsInternal(assetInfo.AssetPath, assetInfo.AssetType, true); + return LoadSubAssetsInternal(assetInfo, true); } /// @@ -603,8 +578,8 @@ namespace YooAsset public static SubAssetsOperationHandle LoadSubAssetsSync(string location) { DebugCheckInitialize(); - string assetPath = _locationServices.ConvertLocationToAssetPath(location); - return LoadSubAssetsInternal(assetPath, typeof(TObject), true); + AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject)); + return LoadSubAssetsInternal(assetInfo, true); } /// @@ -615,8 +590,8 @@ namespace YooAsset public static SubAssetsOperationHandle LoadSubAssetsSync(string location, System.Type type) { DebugCheckInitialize(); - string assetPath = _locationServices.ConvertLocationToAssetPath(location); - return LoadSubAssetsInternal(assetPath, type, true); + AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type); + return LoadSubAssetsInternal(assetInfo, true); } @@ -627,7 +602,7 @@ namespace YooAsset public static SubAssetsOperationHandle LoadSubAssetsAsync(AssetInfo assetInfo) { DebugCheckInitialize(); - return LoadSubAssetsInternal(assetInfo.AssetPath, assetInfo.AssetType, false); + return LoadSubAssetsInternal(assetInfo, false); } /// @@ -638,8 +613,8 @@ namespace YooAsset public static SubAssetsOperationHandle LoadSubAssetsAsync(string location) { DebugCheckInitialize(); - string assetPath = _locationServices.ConvertLocationToAssetPath(location); - return LoadSubAssetsInternal(assetPath, typeof(TObject), false); + AssetInfo assetInfo = ConvertLocationToAssetInfo(location, typeof(TObject)); + return LoadSubAssetsInternal(assetInfo, false); } /// @@ -650,14 +625,14 @@ namespace YooAsset public static SubAssetsOperationHandle LoadSubAssetsAsync(string location, System.Type type) { DebugCheckInitialize(); - string assetPath = _locationServices.ConvertLocationToAssetPath(location); - return LoadSubAssetsInternal(assetPath, type, false); + AssetInfo assetInfo = ConvertLocationToAssetInfo(location, type); + return LoadSubAssetsInternal(assetInfo, false); } - private static SubAssetsOperationHandle LoadSubAssetsInternal(string assetPath, System.Type assetType, bool waitForAsyncComplete) + private static SubAssetsOperationHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete) { - var handle = AssetSystem.LoadSubAssetsAsync(assetPath, assetType); + var handle = AssetSystem.LoadSubAssetsAsync(assetInfo); if (waitForAsyncComplete) handle.WaitForAsyncComplete(); return handle; @@ -694,8 +669,6 @@ namespace YooAsset } else if (_playMode == EPlayMode.HostPlayMode) { - if (_hostPlayModeImpl == null) - throw new Exception("YooAsset is not initialized."); return _hostPlayModeImpl.CreatePatchDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain); } else @@ -720,8 +693,6 @@ namespace YooAsset } else if (_playMode == EPlayMode.HostPlayMode) { - if (_hostPlayModeImpl == null) - throw new Exception("YooAsset is not initialized."); return _hostPlayModeImpl.CreatePatchDownloaderByAll(downloadingMaxNumber, failedTryAgain); } else @@ -748,16 +719,13 @@ namespace YooAsset } else if (_playMode == EPlayMode.HostPlayMode) { - if (_hostPlayModeImpl == null) - throw new Exception("YooAsset is not initialized."); - - List assetPaths = new List(locations.Length); + List assetInfos = new List(locations.Length); foreach (var location in locations) { - string assetPath = _locationServices.ConvertLocationToAssetPath(location); - assetPaths.Add(assetPath); + AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null); + assetInfos.Add(assetInfo); } - return _hostPlayModeImpl.CreatePatchDownloaderByPaths(assetPaths, downloadingMaxNumber, failedTryAgain); + return _hostPlayModeImpl.CreatePatchDownloaderByPaths(assetInfos.ToArray(), downloadingMaxNumber, failedTryAgain); } else { @@ -782,15 +750,7 @@ namespace YooAsset } else if (_playMode == EPlayMode.HostPlayMode) { - if (_hostPlayModeImpl == null) - throw new Exception("YooAsset is not initialized."); - - List assetPaths = new List(assetInfos.Length); - foreach (var assetInfo in assetInfos) - { - assetPaths.Add(assetInfo.AssetPath); - } - return _hostPlayModeImpl.CreatePatchDownloaderByPaths(assetPaths, downloadingMaxNumber, failedTryAgain); + return _hostPlayModeImpl.CreatePatchDownloaderByPaths(assetInfos, downloadingMaxNumber, failedTryAgain); } else { @@ -829,14 +789,10 @@ namespace YooAsset } else if (_playMode == EPlayMode.OfflinePlayMode) { - if (_offlinePlayModeImpl == null) - throw new Exception("YooAsset is not initialized."); return _offlinePlayModeImpl.CreatePatchUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain); } else if (_playMode == EPlayMode.HostPlayMode) { - if (_hostPlayModeImpl == null) - throw new Exception("YooAsset is not initialized."); return _hostPlayModeImpl.CreatePatchUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain); } else @@ -844,6 +800,34 @@ namespace YooAsset throw new NotImplementedException(); } } + + /// + /// 创建补丁解压器 + /// + /// 同时解压的最大文件数 + /// 解压失败的重试次数 + public static PatchUnpackerOperation CreatePatchUnpacker(int unpackingMaxNumber, int failedTryAgain) + { + DebugCheckInitialize(); + if (_playMode == EPlayMode.EditorSimulateMode) + { + List downloadList = new List(); + var operation = new PatchUnpackerOperation(downloadList, unpackingMaxNumber, failedTryAgain); + return operation; + } + else if (_playMode == EPlayMode.OfflinePlayMode) + { + return _offlinePlayModeImpl.CreatePatchUnpackerByAll(unpackingMaxNumber, failedTryAgain); + } + else if (_playMode == EPlayMode.HostPlayMode) + { + return _hostPlayModeImpl.CreatePatchUnpackerByAll(unpackingMaxNumber, failedTryAgain); + } + else + { + throw new NotImplementedException(); + } + } #endregion #region 包裹更新 @@ -858,19 +842,17 @@ namespace YooAsset if (_playMode == EPlayMode.EditorSimulateMode) { var operation = new EditorPlayModeUpdatePackageOperation(); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } else if (_playMode == EPlayMode.OfflinePlayMode) { var operation = new OfflinePlayModeUpdatePackageOperation(); - OperationSystem.ProcessOperaiton(operation); + OperationSystem.StartOperaiton(operation); return operation; } else if (_playMode == EPlayMode.HostPlayMode) { - if (_hostPlayModeImpl == null) - throw new Exception("YooAsset is not initialized."); return _hostPlayModeImpl.UpdatePackageAsync(resourceVersion, timeout); } else @@ -918,22 +900,32 @@ namespace YooAsset #region 内部方法 internal static void InternalUpdate() { - // 更新异步请求操作 + // 更新异步操作系统 OperationSystem.Update(); // 更新下载管理系统 DownloadSystem.Update(); - // 轮询更新资源系统 + // 更新资源系统 AssetSystem.Update(); } + /// + /// 获取调试信息 + /// + internal static void GetDebugReport(DebugReport report) + { + if (report == null) + YooLogger.Error($"{nameof(DebugReport)} is null"); + + AssetSystem.GetDebugReport(report); + } + /// /// 资源定位地址转换为资源完整路径 /// internal static string MappingToAssetPath(string location) { - DebugCheckLocation(location); return _bundleServices.MappingToAssetPath(location); } #endregion @@ -951,11 +943,7 @@ namespace YooAsset [Conditional("DEBUG")] private static void DebugCheckLocation(string location) { - if (string.IsNullOrEmpty(location)) - { - YooLogger.Error("location param is null or empty!"); - } - else + if (string.IsNullOrEmpty(location) == false) { // 检查路径末尾是否有空格 int index = location.LastIndexOf(" "); @@ -970,5 +958,30 @@ namespace YooAsset } } #endregion + + #region 私有方法 + private static AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType) + { + DebugCheckLocation(location); + string assetPath = _locationServices.ConvertLocationToAssetPath(location); + PatchAsset patchAsset = _bundleServices.TryGetPatchAsset(assetPath); + if (patchAsset != null) + { + AssetInfo assetInfo = new AssetInfo(patchAsset, assetType); + return assetInfo; + } + else + { + string error; + if (string.IsNullOrEmpty(location)) + error = $"The location is null or empty !"; + else + error = $"The location is invalid : {location}"; + YooLogger.Error(error); + AssetInfo assetInfo = new AssetInfo(error); + return assetInfo; + } + } + #endregion } } \ No newline at end of file