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 639a5226..912044ea 100644
--- a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/IResourceManager.cs
+++ b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/IResourceManager.cs
@@ -86,8 +86,9 @@ namespace TEngine
///
/// 初始化操作。
///
+ /// 指定资源包的名称。不传使用默认资源包
///
- InitializationOperation InitPackage();
+ 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 9c172386..4893dd9f 100644
--- a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs
+++ b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs
@@ -15,7 +15,7 @@ namespace TEngine
#region Propreties
///
- /// 资源包名称。
+ /// 默认资源包名称。
///
public string PackageName { get; set; } = "DefaultPackage";
@@ -332,18 +332,24 @@ namespace TEngine
/// 初始化资源包裹。
///
/// 初始化资源包裹操作句柄。
- public InitializationOperation InitPackage()
+ public InitializationOperation InitPackage(string customPackageName = "")
{
// 创建默认的资源包
- string packageName = PackageName;
- var package = YooAssets.TryGetPackage(packageName);
+ var targetPackageName = string.IsNullOrEmpty(customPackageName) || customPackageName.Equals(PackageName)
+ ? PackageName
+ : customPackageName;
+ var package = YooAssets.TryGetPackage(targetPackageName);
if (package == null)
{
- package = YooAssets.CreatePackage(packageName);
- YooAssets.SetDefaultPackage(package);
+ package = YooAssets.CreatePackage(targetPackageName);
}
- DefaultPackage = package;
+ // 设置默认资源包
+ if (targetPackageName.Equals(PackageName))
+ {
+ YooAssets.SetDefaultPackage(package);
+ DefaultPackage = package;
+ }
#if UNITY_EDITOR
//编辑器模式使用。
@@ -359,7 +365,7 @@ namespace TEngine
if (playMode == EPlayMode.EditorSimulateMode)
{
var createParameters = new EditorSimulateModeParameters();
- createParameters.SimulateManifestFilePath = EditorSimulateModeHelper.SimulateBuild(packageName);
+ createParameters.SimulateManifestFilePath = EditorSimulateModeHelper.SimulateBuild(targetPackageName);
initializationOperation = package.InitializeAsync(createParameters);
}
diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceModule.cs
index 2f486bf9..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);
}
///
@@ -306,6 +307,27 @@ namespace TEngine
}
}
+ ///
+ /// 创建资源下载器,用于下载当前资源版本指定地址的资源文件。
+ ///
+ /// 资源地址
+ /// 指定资源包的名称。不传使用默认资源包
+ public ResourceDownloaderOperation CreateResourceDownloader(string location, string packageName = "")
+ {
+ if (string.IsNullOrEmpty(packageName))
+ {
+ var package = YooAssets.GetPackage(this.packageName);
+ Downloader = package.CreateResourceDownloader(location, downloadingMaxNum, failedTryAgain);
+ return Downloader;
+ }
+ else
+ {
+ var package = YooAssets.GetPackage(packageName);
+ Downloader = package.CreateResourceDownloader(location, downloadingMaxNum, failedTryAgain);
+ return Downloader;
+ }
+ }
+
///
/// 清理包裹未使用的缓存文件。
///
@@ -507,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);
}
///
@@ -538,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);
}
///
@@ -652,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);
@@ -699,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);
}
///