diff --git a/Assets/YooAsset/Runtime/ResourceManager/Loader/DependAssetBundles.cs b/Assets/YooAsset/Runtime/ResourceManager/Loader/DependAssetBundles.cs index d2e5496b..130dbdc9 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Loader/DependAssetBundles.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Loader/DependAssetBundles.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using UnityEngine.Pool; namespace YooAsset { @@ -9,7 +10,7 @@ namespace YooAsset /// /// 依赖的资源包加载器列表 /// - internal readonly List DependList; + internal List DependList { private set; get; } public DependAssetBundles(List dpendList) @@ -92,6 +93,8 @@ namespace YooAsset { loader.Release(); } + ListPool.Release(DependList); + DependList = null; } /// diff --git a/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs b/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs index dfb2745f..4862fdc6 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics; using UnityEngine; +using UnityEngine.Pool; using UnityEngine.SceneManagement; namespace YooAsset @@ -107,7 +108,7 @@ namespace YooAsset } // 卸载依赖资源包加载器 - string[] dependBundleNames = _bundleQuery.GetDependBundleNames(assetInfo); + var dependBundleNames = _bundleQuery.GetDependBundleNames(assetInfo); foreach (var dependBundleName in dependBundleNames) { var dependLoader = TryGetAssetBundleLoader(dependBundleName); @@ -122,6 +123,7 @@ namespace YooAsset } } } + ListPool.Release(dependBundleNames); } /// @@ -392,13 +394,14 @@ namespace YooAsset } internal List CreateDependAssetBundleLoaders(AssetInfo assetInfo) { - BundleInfo[] depends = _bundleQuery.GetDependBundleInfos(assetInfo); - List result = new List(depends.Length); + List depends = _bundleQuery.GetDependBundleInfos(assetInfo); + List result = ListPool.Get(); foreach (var bundleInfo in depends) { BundleLoaderBase dependLoader = CreateAssetBundleLoaderInternal(bundleInfo); result.Add(dependLoader); } + ListPool.Release(depends); return result; } internal void RemoveBundleProviders(List removeList) diff --git a/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs b/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs index 5a0dcd68..f9d72e37 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs @@ -1,6 +1,7 @@ using System.IO; using System.Collections.Generic; using UnityEngine; +using UnityEngine.Pool; namespace YooAsset { @@ -186,6 +187,7 @@ namespace YooAsset var bundleInfo = CreateUnpackInfo(assist, packageBundle); result.Add(bundleInfo); } + ListPool.Release(unpackList); return result; } private static BundleInfo CreateUnpackInfo(ResourceAssist assist, PackageBundle packageBundle) diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Interface/IBundleQuery.cs b/Assets/YooAsset/Runtime/ResourcePackage/Interface/IBundleQuery.cs index bac81f13..97ba3a3a 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Interface/IBundleQuery.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Interface/IBundleQuery.cs @@ -1,4 +1,6 @@  +using System.Collections.Generic; + namespace YooAsset { internal interface IBundleQuery @@ -11,7 +13,7 @@ namespace YooAsset /// /// 获取依赖的资源包信息集合 /// - BundleInfo[] GetDependBundleInfos(AssetInfo assetPath); + List GetDependBundleInfos(AssetInfo assetPath); /// /// 获取主资源包名称 @@ -21,7 +23,7 @@ namespace YooAsset /// /// 获取依赖的资源包名称集合 /// - string[] GetDependBundleNames(AssetInfo assetInfo); + List GetDependBundleNames(AssetInfo assetInfo); /// /// 清单是否有效 diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PackageManifest.cs b/Assets/YooAsset/Runtime/ResourcePackage/PackageManifest.cs index 53a52fe7..3d275bff 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/PackageManifest.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/PackageManifest.cs @@ -3,6 +3,7 @@ using System.IO; using System.Diagnostics; using System.Collections; using System.Collections.Generic; +using UnityEngine.Pool; namespace YooAsset { @@ -146,10 +147,10 @@ namespace YooAsset /// 获取资源依赖列表 /// 注意:传入的资源路径一定合法有效! /// - public PackageBundle[] GetAllDependencies(string assetPath) + public List GetAllDependencies(string assetPath) { var packageBundle = GetMainPackageBundle(assetPath); - List result = new List(packageBundle.DependIDs.Length); + var result = ListPool.Get(); foreach (var dependID in packageBundle.DependIDs) { if (dependID >= 0 && dependID < BundleList.Count) @@ -162,7 +163,7 @@ namespace YooAsset throw new Exception($"Invalid bundle id : {dependID} Asset path : {assetPath}"); } } - return result.ToArray(); + return result; } /// diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs index 159842e3..68eae644 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/EditorSimulateModeImpl.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using UnityEngine.Pool; namespace YooAsset { @@ -114,20 +115,21 @@ namespace YooAsset var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath); return CreateBundleInfo(packageBundle, assetInfo); } - BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo) + List IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo) { if (assetInfo.IsInvalid) throw new Exception("Should never get here !"); // 注意:如果清单里未找到资源包会抛出异常! - var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); - List result = new List(depends.Length); + List depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); + List result = ListPool.Get(); foreach (var packageBundle in depends) { BundleInfo bundleInfo = CreateBundleInfo(packageBundle, assetInfo); result.Add(bundleInfo); } - return result.ToArray(); + ListPool.Release(depends); + return result; } string IBundleQuery.GetMainBundleName(AssetInfo assetInfo) { @@ -138,19 +140,20 @@ namespace YooAsset var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath); return packageBundle.BundleName; } - string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo) + List IBundleQuery.GetDependBundleNames(AssetInfo assetInfo) { if (assetInfo.IsInvalid) throw new Exception("Should never get here !"); // 注意:如果清单里未找到资源包会抛出异常! - var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); - List result = new List(depends.Length); + List depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); + List result = ListPool.Get(); foreach (var packageBundle in depends) { result.Add(packageBundle.BundleName); } - return result.ToArray(); + ListPool.Release(depends); + return result; } bool IBundleQuery.ManifestValid() { diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs index 601f61ec..6ddb8332 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/HostPlayModeImpl.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using UnityEngine.Pool; namespace YooAsset { @@ -60,6 +61,7 @@ namespace YooAsset var bundleInfo = ConvertToDownloadInfo(packageBundle); result.Add(bundleInfo); } + ListPool.Release(downloadList); return result; } private BundleInfo ConvertToDownloadInfo(PackageBundle packageBundle) @@ -133,7 +135,7 @@ namespace YooAsset } public List GetDownloadListByAll(PackageManifest manifest) { - List downloadList = new List(1000); + List downloadList = ListPool.Get(); foreach (var packageBundle in manifest.BundleList) { // 忽略分发文件 @@ -162,7 +164,7 @@ namespace YooAsset } public List GetDownloadListByTags(PackageManifest manifest, string[] tags) { - List downloadList = new List(1000); + List downloadList = ListPool.Get(); foreach (var packageBundle in manifest.BundleList) { // 忽略分发文件 @@ -219,15 +221,16 @@ namespace YooAsset checkList.Add(mainBundle); // 注意:如果清单里未找到资源包会抛出异常! - PackageBundle[] dependBundles = manifest.GetAllDependencies(assetInfo.AssetPath); + List dependBundles = manifest.GetAllDependencies(assetInfo.AssetPath); foreach (var dependBundle in dependBundles) { if (checkList.Contains(dependBundle) == false) checkList.Add(dependBundle); } + ListPool.Release(dependBundles); } - List downloadList = new List(1000); + List downloadList = ListPool.Get(); foreach (var packageBundle in checkList) { // 忽略分发文件 @@ -256,7 +259,7 @@ namespace YooAsset } private List GetUnpackListByAll(PackageManifest manifest) { - List downloadList = new List(1000); + List downloadList = ListPool.Get(); foreach (var packageBundle in manifest.BundleList) { // 忽略缓存文件 @@ -280,7 +283,7 @@ namespace YooAsset } private List GetUnpackListByTags(PackageManifest manifest, string[] tags) { - List downloadList = new List(1000); + List downloadList = ListPool.Get(); foreach (var packageBundle in manifest.BundleList) { // 忽略缓存文件 @@ -370,20 +373,21 @@ namespace YooAsset var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath); return CreateBundleInfo(packageBundle); } - BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo) + List IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo) { if (assetInfo.IsInvalid) throw new Exception("Should never get here !"); // 注意:如果清单里未找到资源包会抛出异常! - var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); - List result = new List(depends.Length); + List depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); + List result = ListPool.Get(); foreach (var packageBundle in depends) { BundleInfo bundleInfo = CreateBundleInfo(packageBundle); result.Add(bundleInfo); } - return result.ToArray(); + ListPool.Release(depends); + return result; } string IBundleQuery.GetMainBundleName(AssetInfo assetInfo) { @@ -394,19 +398,20 @@ namespace YooAsset var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath); return packageBundle.BundleName; } - string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo) + List IBundleQuery.GetDependBundleNames(AssetInfo assetInfo) { if (assetInfo.IsInvalid) throw new Exception("Should never get here !"); // 注意:如果清单里未找到资源包会抛出异常! - var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); - List result = new List(depends.Length); + List depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); + List result = ListPool.Get(); foreach (var packageBundle in depends) { result.Add(packageBundle.BundleName); } - return result.ToArray(); + ListPool.Release(depends); + return result; } bool IBundleQuery.ManifestValid() { diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs index c6d7cc92..a2557551 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/OfflinePlayModeImpl.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using UnityEngine.Pool; namespace YooAsset { @@ -103,7 +104,7 @@ namespace YooAsset } private List GetUnpackListByAll(PackageManifest manifest) { - List downloadList = new List(1000); + List downloadList = ListPool.Get(); foreach (var packageBundle in manifest.BundleList) { // 忽略缓存文件 @@ -124,7 +125,7 @@ namespace YooAsset } private List GetUnpackListByTags(PackageManifest manifest, string[] tags) { - List downloadList = new List(1000); + List downloadList = ListPool.Get(); foreach (var packageBundle in manifest.BundleList) { // 忽略缓存文件 @@ -199,20 +200,21 @@ namespace YooAsset var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath); return CreateBundleInfo(packageBundle); } - BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo) + List IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo) { if (assetInfo.IsInvalid) throw new Exception("Should never get here !"); // 注意:如果清单里未找到资源包会抛出异常! - var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); - List result = new List(depends.Length); + List depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); + List result = ListPool.Get(); foreach (var packageBundle in depends) { BundleInfo bundleInfo = CreateBundleInfo(packageBundle); result.Add(bundleInfo); } - return result.ToArray(); + ListPool.Release(depends); + return result; } string IBundleQuery.GetMainBundleName(AssetInfo assetInfo) { @@ -223,19 +225,20 @@ namespace YooAsset var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath); return packageBundle.BundleName; } - string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo) + List IBundleQuery.GetDependBundleNames(AssetInfo assetInfo) { if (assetInfo.IsInvalid) throw new Exception("Should never get here !"); // 注意:如果清单里未找到资源包会抛出异常! - var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); - List result = new List(depends.Length); + List depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); + List result = ListPool.Get(); foreach (var packageBundle in depends) { result.Add(packageBundle.BundleName); } - return result.ToArray(); + ListPool.Release(depends); + return result; } bool IBundleQuery.ManifestValid() { diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs index de073072..5722cb81 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using UnityEngine.Pool; namespace YooAsset { @@ -61,6 +62,7 @@ namespace YooAsset var bundleInfo = ConvertToDownloadInfo(packageBundle); result.Add(bundleInfo); } + ListPool.Release(downloadList); return result; } @@ -130,7 +132,7 @@ namespace YooAsset } public List GetDownloadListByAll(PackageManifest manifest) { - List downloadList = new List(1000); + List downloadList = ListPool.Get(); foreach (var packageBundle in manifest.BundleList) { // 忽略缓存文件 @@ -155,7 +157,7 @@ namespace YooAsset } public List GetDownloadListByTags(PackageManifest manifest, string[] tags) { - List downloadList = new List(1000); + List downloadList = ListPool.Get(); foreach (var packageBundle in manifest.BundleList) { // 忽略缓存文件 @@ -208,15 +210,16 @@ namespace YooAsset checkList.Add(mainBundle); // 注意:如果清单里未找到资源包会抛出异常! - PackageBundle[] dependBundles = manifest.GetAllDependencies(assetInfo.AssetPath); + List dependBundles = manifest.GetAllDependencies(assetInfo.AssetPath); foreach (var dependBundle in dependBundles) { if (checkList.Contains(dependBundle) == false) checkList.Add(dependBundle); } + ListPool.Release(dependBundles); } - List downloadList = new List(1000); + List downloadList = ListPool.Get(); foreach (var packageBundle in checkList) { // 忽略缓存文件 @@ -273,20 +276,21 @@ namespace YooAsset var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath); return CreateBundleInfo(packageBundle); } - BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo) + List IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo) { if (assetInfo.IsInvalid) throw new Exception("Should never get here !"); // 注意:如果清单里未找到资源包会抛出异常! - var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); - List result = new List(depends.Length); + List depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); + List result = ListPool.Get(); foreach (var packageBundle in depends) { BundleInfo bundleInfo = CreateBundleInfo(packageBundle); result.Add(bundleInfo); } - return result.ToArray(); + ListPool.Release(depends); + return result; } string IBundleQuery.GetMainBundleName(AssetInfo assetInfo) { @@ -297,19 +301,20 @@ namespace YooAsset var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath); return packageBundle.BundleName; } - string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo) + List IBundleQuery.GetDependBundleNames(AssetInfo assetInfo) { if (assetInfo.IsInvalid) throw new Exception("Should never get here !"); // 注意:如果清单里未找到资源包会抛出异常! - var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); - List result = new List(depends.Length); + List depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath); + List result = ListPool.Get(); foreach (var packageBundle in depends) { result.Add(packageBundle.BundleName); } - return result.ToArray(); + ListPool.Release(depends); + return result; } bool IBundleQuery.ManifestValid() { diff --git a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs index 301591fa..b4dc2d21 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Collections; using System.Collections.Generic; using UnityEngine.SceneManagement; +using UnityEngine.Pool; namespace YooAsset { @@ -534,13 +535,13 @@ namespace YooAsset if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote) return true; - BundleInfo[] depends = _bundleQuery.GetDependBundleInfos(assetInfo); + List depends = _bundleQuery.GetDependBundleInfos(assetInfo); foreach (var depend in depends) { if (depend.LoadMode == BundleInfo.ELoadMode.LoadFromRemote) return true; } - + ListPool.Release(depends); return false; } #endregion