diff --git a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs index ef158fb..022e1da 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs @@ -196,24 +196,6 @@ namespace YooAsset return provider.CreateHandle() as SubAssetsOperationHandle; } - /// - /// 加载资源包里的所有资源对象 - /// - public static AllAssetsOperationHandle LoadAllAssetsAsync(string assetPath, System.Type assetType) - { - ProviderBase provider = TryGetProvider(assetPath); - if (provider == null) - { - if (SimulationOnEditor) - provider = new DatabaseAllAssetsProvider(assetPath, assetType); - else - provider = new BundledAllAssetsProvider(assetPath, assetType); - provider.InitSpawnDebugInfo(); - _providers.Add(provider); - } - return provider.CreateHandle() as AllAssetsOperationHandle; - } - internal static void UnloadSubScene(ProviderBase provider) { diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/AllAssetsOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/AllAssetsOperationHandle.cs deleted file mode 100644 index 3d0ae3e..0000000 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/AllAssetsOperationHandle.cs +++ /dev/null @@ -1,69 +0,0 @@ - -namespace YooAsset -{ - public sealed class AllAssetsOperationHandle : OperationHandleBase - { - private System.Action _callback; - - internal AllAssetsOperationHandle(ProviderBase provider) : base(provider) - { - } - internal override void InvokeCallback() - { - _callback?.Invoke(this); - } - - /// - /// 完成委托 - /// - public event System.Action Completed - { - add - { - if (IsValid == false) - throw new System.Exception($"{nameof(AllAssetsOperationHandle)} is invalid"); - if (Provider.IsDone) - value.Invoke(this); - else - _callback += value; - } - remove - { - if (IsValid == false) - throw new System.Exception($"{nameof(AllAssetsOperationHandle)} is invalid"); - _callback -= value; - } - } - - /// - /// 资源包内的资源对象集合 - /// - public UnityEngine.Object[] AllAssetObjects - { - get - { - if (IsValid == false) - return null; - return Provider.AllAssetObjects; - } - } - - /// - /// 等待异步执行完毕 - /// - public void WaitForAsyncComplete() - { - if (IsValid == false) - return; - Provider.WaitForAsyncComplete(); - } - - /// - /// 释放资源句柄 - /// - public void Release() - { - this.ReleaseInternal(); - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/AllAssetsOperationHandle.cs.meta b/Assets/YooAsset/Runtime/AssetSystem/Handles/AllAssetsOperationHandle.cs.meta deleted file mode 100644 index b5dd03a..0000000 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/AllAssetsOperationHandle.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 05c287035a2264f469a654a6152b02c9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAllAssetsProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAllAssetsProvider.cs deleted file mode 100644 index 420a2b6..0000000 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAllAssetsProvider.cs +++ /dev/null @@ -1,116 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace YooAsset -{ - internal sealed class BundledAllAssetsProvider : BundledProvider - { - private AssetBundleRequest _cacheRequest; - public override float Progress - { - get - { - if (_cacheRequest == null) - return 0; - return _cacheRequest.progress; - } - } - - public BundledAllAssetsProvider(string assetPath, System.Type assetType) - : base(assetPath, assetType) - { - } - public override void Update() - { - if (IsDone) - return; - - if (Status == EStatus.None) - { - Status = EStatus.CheckBundle; - } - - // 1. 检测资源包 - if (Status == EStatus.CheckBundle) - { - if (IsWaitForAsyncComplete) - { - DependBundles.WaitForAsyncComplete(); - OwnerBundle.WaitForAsyncComplete(); - } - - if (DependBundles.IsDone() == false) - return; - if (OwnerBundle.IsDone() == false) - return; - - if (DependBundles.IsSucceed() == false) - { - Status = EStatus.Fail; - LastError = DependBundles.GetLastError(); - InvokeCompletion(); - return; - } - - if (OwnerBundle.Status != AssetBundleLoaderBase.EStatus.Succeed) - { - Status = EStatus.Fail; - LastError = OwnerBundle.LastError; - InvokeCompletion(); - return; - } - - Status = EStatus.Loading; - } - - // 2. 加载资源对象 - if (Status == EStatus.Loading) - { - if (IsWaitForAsyncComplete) - { - if (AssetType == null) - AllAssetObjects = OwnerBundle.CacheBundle.LoadAllAssets(); - else - AllAssetObjects = OwnerBundle.CacheBundle.LoadAllAssets(AssetType); - } - else - { - if (AssetType == null) - _cacheRequest = OwnerBundle.CacheBundle.LoadAllAssetsAsync(); - else - _cacheRequest = OwnerBundle.CacheBundle.LoadAllAssetsAsync(AssetType); - } - Status = EStatus.Checking; - } - - // 3. 检测加载结果 - if (Status == EStatus.Checking) - { - if (_cacheRequest != null) - { - if (IsWaitForAsyncComplete) - { - // 强制挂起主线程(注意:该操作会很耗时) - YooLogger.Warning("Suspend the main thread to load unity asset."); - AllAssetObjects = _cacheRequest.allAssets; - } - else - { - if (_cacheRequest.isDone == false) - return; - AllAssetObjects = _cacheRequest.allAssets; - } - } - - Status = AllAssetObjects == null ? EStatus.Fail : EStatus.Success; - if (Status == EStatus.Fail) - { - LastError = $"Failed to load all assets from bundle : {OwnerBundle.BundleFileInfo.BundleName}"; - YooLogger.Error(LastError); - } - InvokeCompletion(); - } - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAllAssetsProvider.cs.meta b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAllAssetsProvider.cs.meta deleted file mode 100644 index c2a5778..0000000 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAllAssetsProvider.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: dd972d8e33cbbaf4aa7f976d59896b0e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAllAssetsProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAllAssetsProvider.cs deleted file mode 100644 index b88f6b6..0000000 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAllAssetsProvider.cs +++ /dev/null @@ -1,127 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace YooAsset -{ - internal sealed class DatabaseAllAssetsProvider : ProviderBase - { - private string _bundleName; - - public override float Progress - { - get - { - if (IsDone) - return 100f; - else - return 0; - } - } - - public DatabaseAllAssetsProvider(string assetPath, System.Type assetType) - : base(assetPath, assetType) - { - } - public override void Update() - { -#if UNITY_EDITOR - if (IsDone) - return; - - if (Status == EStatus.None) - { - // 检测资源文件是否存在 - string guid = UnityEditor.AssetDatabase.AssetPathToGUID(AssetPath); - if (string.IsNullOrEmpty(guid)) - { - Status = EStatus.Fail; - LastError = $"Not found asset : {AssetPath}"; - YooLogger.Error(LastError); - InvokeCompletion(); - return; - } - - // 获取资源包名称 - _bundleName = AssetSystem.BundleServices.GetBundleName(AssetPath); - if (string.IsNullOrEmpty(_bundleName)) - { - Status = EStatus.Fail; - LastError = $"Not found bundle name : {AssetPath}"; - YooLogger.Error(LastError); - InvokeCompletion(); - return; - } - - Status = EStatus.Loading; - - // 注意:模拟异步加载效果提前返回 - if (IsWaitForAsyncComplete == false) - return; - } - - // 1. 加载资源对象 - if (Status == EStatus.Loading) - { - bool loadFailed = false; - if (AssetType == null) - { - List result = new List(100); - AssetInfo[] allAssetInfos = AssetSystem.BundleServices.GetAssetInfos(_bundleName); - foreach (var assetInfo in allAssetInfos) - { - var assetObject = UnityEditor.AssetDatabase.LoadMainAssetAtPath(assetInfo.AssetPath); - if (assetObject != null) - { - result.Add(assetObject); - } - else - { - YooLogger.Warning($"Failed to load main asset : {assetInfo.AssetPath}"); - loadFailed = true; - break; - } - } - if (loadFailed == false) - AllAssetObjects = result.ToArray(); - } - else - { - List result = new List(100); - AssetInfo[] allAssetInfos = AssetSystem.BundleServices.GetAssetInfos(_bundleName); - foreach (var assetInfo in allAssetInfos) - { - var assetObject = UnityEditor.AssetDatabase.LoadAssetAtPath(assetInfo.AssetPath, AssetType); - if (assetObject != null) - { - if (AssetType.IsAssignableFrom(assetObject.GetType())) - result.Add(assetObject); - } - else - { - YooLogger.Warning($"Failed to load asset : {assetInfo.AssetPath}"); - loadFailed = true; - break; - } - } - if (loadFailed == false) - AllAssetObjects = result.ToArray(); - } - Status = EStatus.Checking; - } - - // 2. 检测加载结果 - if (Status == EStatus.Checking) - { - Status = AllAssetObjects == null ? EStatus.Fail : EStatus.Success; - if (Status == EStatus.Fail) - { - LastError = $"Failed to load all assets : {nameof(AssetType)} in bundle {_bundleName}"; - YooLogger.Error(LastError); - } - InvokeCompletion(); - } -#endif - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAllAssetsProvider.cs.meta b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAllAssetsProvider.cs.meta deleted file mode 100644 index cec238b..0000000 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAllAssetsProvider.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b418b6a8da0e3d240b1566cc44fc4b2b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs index 4b75c6d..0e0c78d 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs @@ -140,8 +140,6 @@ namespace YooAsset handle = new SceneOperationHandle(this); else if (IsSubAssetsProvider()) handle = new SubAssetsOperationHandle(this); - else if (IsAllAssetsProvider()) - handle = new AllAssetsOperationHandle(this); else handle = new AssetOperationHandle(this); @@ -212,13 +210,6 @@ namespace YooAsset else return false; } - public bool IsAllAssetsProvider() - { - if (this is BundledAllAssetsProvider || this is DatabaseAllAssetsProvider) - return true; - else - return false; - } #region 异步编程相关 private TaskCompletionSource _taskCompletionSource; diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index 1acef15..3eab286 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -342,6 +342,18 @@ namespace YooAsset AssetSystem.ForceUnloadAllAssets(); } + /// + /// 获取调试信息 + /// + internal static void GetDebugReport(DebugReport report) + { + if (report == null) + YooLogger.Error($"{nameof(DebugReport)} is null"); + + AssetSystem.GetDebugReport(report); + } + + #region 资源信息 /// /// 获取资源包信息 /// @@ -365,11 +377,20 @@ namespace YooAsset return _bundleServices.GetBundleInfo(bundleName); } + /// + /// 获取资源信息列表 + /// + /// 资源包信息 + public static AssetInfo[] GetAssetInfos(BundleInfo bundleInfo) + { + DebugCheckInitialize(); + return _bundleServices.GetAssetInfos(bundleInfo.BundleName); + } + /// /// 获取资源信息列表 /// /// 资源标签 - /// public static AssetInfo[] GetAssetInfos(string tag) { DebugCheckInitialize(); @@ -381,23 +402,12 @@ namespace YooAsset /// 获取资源信息列表 /// /// 资源标签列表 - /// public static AssetInfo[] GetAssetInfos(string[] tags) { DebugCheckInitialize(); return _bundleServices.GetAssetInfos(tags); } - - /// - /// 获取调试信息 - /// - internal static void GetDebugReport(DebugReport report) - { - if (report == null) - YooLogger.Error($"{nameof(DebugReport)} is null"); - - AssetSystem.GetDebugReport(report); - } + #endregion #region 场景加载 /// @@ -646,86 +656,6 @@ namespace YooAsset } #endregion - #region 资源加载 - /// - /// 同步加载资源对象所属资源包里的所有资源 - /// - /// 资源信息 - public static AllAssetsOperationHandle LoadAllAssetsSync(AssetInfo assetInfo) - { - DebugCheckInitialize(); - return LoadAllAssetsInternal(assetInfo.AssetPath, assetInfo.AssetType, true); - } - - /// - /// 同步加载资源对象所属资源包里的所有资源 - /// - /// 资源类型 - /// 资源的定位地址 - public static AllAssetsOperationHandle LoadAllAssetsSync(string location) - { - DebugCheckInitialize(); - string assetPath = _locationServices.ConvertLocationToAssetPath(location); - return LoadAllAssetsInternal(assetPath, typeof(TObject), true); - } - - /// - /// 同步加载资源对象所属资源包里的所有资源 - /// - /// 资源的定位地址 - /// 资源类型 - public static AllAssetsOperationHandle LoadAllAssetsSync(string location, System.Type type) - { - DebugCheckInitialize(); - string assetPath = _locationServices.ConvertLocationToAssetPath(location); - return LoadAllAssetsInternal(assetPath, type, true); - } - - - /// - /// 异步加载资源对象所属资源包里的所有资源 - /// - /// 资源信息 - public static AllAssetsOperationHandle LoadAllAssetsAsync(AssetInfo assetInfo) - { - DebugCheckInitialize(); - return LoadAllAssetsInternal(assetInfo.AssetPath, assetInfo.AssetType, false); - } - - /// - /// 异步加载资源对象所属资源包里的所有资源 - /// - /// 资源类型 - /// 资源的定位地址 - public static AllAssetsOperationHandle LoadAllAssetsAsync(string location) - { - DebugCheckInitialize(); - string assetPath = _locationServices.ConvertLocationToAssetPath(location); - return LoadAllAssetsInternal(assetPath, typeof(TObject), false); - } - - /// - /// 异步加载资源对象所属资源包里的所有资源 - /// - /// 资源的定位地址 - /// 资源类型 - public static AllAssetsOperationHandle LoadAllAssetsAsync(string location, System.Type type) - { - DebugCheckInitialize(); - string assetPath = _locationServices.ConvertLocationToAssetPath(location); - return LoadAllAssetsInternal(assetPath, type, false); - } - - - private static AllAssetsOperationHandle LoadAllAssetsInternal(string assetPath, System.Type assetType, bool waitForAsyncComplete) - { - var handle = AssetSystem.LoadAllAssetsAsync(assetPath, assetType); - if (waitForAsyncComplete) - handle.WaitForAsyncComplete(); - return handle; - } - #endregion - #region 资源下载 /// /// 创建补丁下载器,用于下载更新资源标签指定的资源包文件