From 4385123976f25dbbbe8586ef9a7a3339609bad3c Mon Sep 17 00:00:00 2001 From: Weekend <872285171@qq.com> Date: Wed, 15 Nov 2023 15:39:04 +0800 Subject: [PATCH] =?UTF-8?q?add:=E8=AE=BE=E7=BD=AE=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=94=AF=E6=8C=81=E4=BB=8E=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=8C=85=E4=B8=AD=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runtime/Extension/UnityExtension.cs | 26 ++++++++++++------- .../ResourceModule/IResourceManager.cs | 4 +-- .../Modules/ResourceModule/ResourceManager.cs | 6 ++--- .../Modules/ResourceModule/ResourceModule.cs | 17 +++++++----- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/UnityProject/Assets/TEngine/Runtime/Extension/UnityExtension.cs b/UnityProject/Assets/TEngine/Runtime/Extension/UnityExtension.cs index 98760532..7e6a7127 100644 --- a/UnityProject/Assets/TEngine/Runtime/Extension/UnityExtension.cs +++ b/UnityProject/Assets/TEngine/Runtime/Extension/UnityExtension.cs @@ -132,7 +132,9 @@ namespace TEngine /// 图片名称。 /// 是否使用原生分辨率。 /// 是否使用异步加载。 - public static void SetSprite(this UnityEngine.UI.Image image, string spriteName, bool isSetNativeSize = false, bool isAsync = false) + /// 指定资源包的名称。不传使用默认资源包 + public static void SetSprite(this UnityEngine.UI.Image image, string spriteName, bool isSetNativeSize = false, + bool isAsync = false, string customPackageName = "") { if (image == null) { @@ -147,7 +149,8 @@ namespace TEngine { if (!isAsync) { - image.sprite = GameModule.Resource.LoadAsset(spriteName); + image.sprite = + GameModule.Resource.LoadAsset(spriteName, customPackageName: customPackageName); if (isSetNativeSize) { image.SetNativeSize(); @@ -167,7 +170,7 @@ namespace TEngine { image.SetNativeSize(); } - }); + }, customPackageName: customPackageName); } } } @@ -178,7 +181,9 @@ namespace TEngine /// Image组件。 /// 图片名称。 /// 是否使用异步加载。 - public static void SetSprite(this SpriteRenderer spriteRenderer, string spriteName, bool isAsync = false) + /// 指定资源包的名称。不传使用默认资源包 + public static void SetSprite(this SpriteRenderer spriteRenderer, string spriteName, bool isAsync = false, + string customPackageName = "") { if (spriteRenderer == null) { @@ -193,7 +198,8 @@ namespace TEngine { if (!isAsync) { - spriteRenderer.sprite = GameModule.Resource.LoadAsset(spriteName); + spriteRenderer.sprite = + GameModule.Resource.LoadAsset(spriteName, customPackageName: customPackageName); } else { @@ -205,11 +211,11 @@ namespace TEngine } spriteRenderer.sprite = operation.AssetObject as Sprite; - }); + }, customPackageName: customPackageName); } } } - + /// /// 查找子节点。 /// @@ -221,7 +227,7 @@ namespace TEngine var findTrans = transform.Find(path); return findTrans != null ? findTrans : null; } - + /// /// 根据名字找到子节点,主要用于dummy接口。 /// @@ -252,7 +258,7 @@ namespace TEngine return null; } - + [TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)] public static Component FindChildComponent(this Type type, Transform transform, string path) { @@ -264,7 +270,7 @@ namespace TEngine return null; } - + public static T FindChildComponent(this Transform transform, string path) where T : Component { var findTrans = transform.Find(path); diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/IResourceManager.cs b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/IResourceManager.cs index b8f96b13..912044ea 100644 --- a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/IResourceManager.cs +++ b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/IResourceManager.cs @@ -86,9 +86,9 @@ namespace TEngine /// /// 初始化操作。 /// - /// 指定资源包的名称。不传使用默认资源包 + /// 指定资源包的名称。不传使用默认资源包 /// - InitializationOperation InitPackage(string packageName = ""); + InitializationOperation InitPackage(string customPackageName = ""); /// /// 卸载资源。 diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs index 2bdb714a..4893dd9f 100644 --- a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs +++ b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs @@ -332,12 +332,12 @@ namespace TEngine /// 初始化资源包裹。 /// /// 初始化资源包裹操作句柄。 - public InitializationOperation InitPackage(string packageName = "") + public InitializationOperation InitPackage(string customPackageName = "") { // 创建默认的资源包 - var targetPackageName = string.IsNullOrEmpty(packageName) || packageName.Equals(PackageName) + var targetPackageName = string.IsNullOrEmpty(customPackageName) || customPackageName.Equals(PackageName) ? PackageName - : packageName; + : customPackageName; var package = YooAssets.TryGetPackage(targetPackageName); if (package == null) { diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs index c50ab81b..6c1a79d7 100644 --- a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs +++ b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs @@ -230,10 +230,11 @@ namespace TEngine /// /// 初始化操作。 /// + /// 指定资源包的名称。不传使用默认资源包 /// - public InitializationOperation InitPackage() + public InitializationOperation InitPackage(string customPackageName = "") { - return m_ResourceManager.InitPackage(); + return m_ResourceManager.InitPackage(customPackageName); } /// @@ -528,7 +529,8 @@ namespace TEngine public T LoadAsset(string location, Transform parent, bool needInstance = true, bool needCache = false, string customPackageName = "") where T : UnityEngine.Object { - return m_ResourceManager.LoadAsset(location, parent, needInstance, needCache, packageName: customPackageName); + return m_ResourceManager.LoadAsset(location, parent, needInstance, needCache, + packageName: customPackageName); } /// @@ -559,7 +561,8 @@ namespace TEngine public T LoadAsset(string location, Transform parent, out AssetOperationHandle handle, bool needCache = false, string customPackageName = "") where T : UnityEngine.Object { - return m_ResourceManager.LoadAsset(location, parent, out handle, needCache, packageName: customPackageName); + return m_ResourceManager.LoadAsset(location, parent, out handle, needCache, + packageName: customPackageName); } /// @@ -673,7 +676,8 @@ namespace TEngine /// 要加载资源的类型。 /// 异步资源实例。 public async UniTask LoadAssetAsync(string location, CancellationToken cancellationToken = default, - bool needInstance = true, bool needCache = false, string customPackageName = "") where T : UnityEngine.Object + bool needInstance = true, bool needCache = false, string customPackageName = "") + where T : UnityEngine.Object { return await m_ResourceManager.LoadAssetAsync(location, cancellationToken, needInstance, needCache, packageName: customPackageName); @@ -720,7 +724,8 @@ namespace TEngine public async UniTask LoadRawAssetAsync(string location, CancellationToken cancellationToken = default, string customPackageName = "") { - return await m_ResourceManager.LoadRawAssetAsync(location, cancellationToken, packageName: customPackageName); + return await m_ResourceManager.LoadRawAssetAsync(location, cancellationToken, + packageName: customPackageName); } ///