mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
add:设置图片资源支持从指定资源包中加载
This commit is contained in:
@@ -132,7 +132,9 @@ namespace TEngine
|
||||
/// <param name="spriteName">图片名称。</param>
|
||||
/// <param name="isSetNativeSize">是否使用原生分辨率。</param>
|
||||
/// <param name="isAsync">是否使用异步加载。</param>
|
||||
public static void SetSprite(this UnityEngine.UI.Image image, string spriteName, bool isSetNativeSize = false, bool isAsync = false)
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
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<Sprite>(spriteName);
|
||||
image.sprite =
|
||||
GameModule.Resource.LoadAsset<Sprite>(spriteName, customPackageName: customPackageName);
|
||||
if (isSetNativeSize)
|
||||
{
|
||||
image.SetNativeSize();
|
||||
@@ -167,7 +170,7 @@ namespace TEngine
|
||||
{
|
||||
image.SetNativeSize();
|
||||
}
|
||||
});
|
||||
}, customPackageName: customPackageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,7 +181,9 @@ namespace TEngine
|
||||
/// <param name="spriteRenderer">Image组件。</param>
|
||||
/// <param name="spriteName">图片名称。</param>
|
||||
/// <param name="isAsync">是否使用异步加载。</param>
|
||||
public static void SetSprite(this SpriteRenderer spriteRenderer, string spriteName, bool isAsync = false)
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
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<Sprite>(spriteName);
|
||||
spriteRenderer.sprite =
|
||||
GameModule.Resource.LoadAsset<Sprite>(spriteName, customPackageName: customPackageName);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -205,11 +211,11 @@ namespace TEngine
|
||||
}
|
||||
|
||||
spriteRenderer.sprite = operation.AssetObject as Sprite;
|
||||
});
|
||||
}, customPackageName: customPackageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查找子节点。
|
||||
/// </summary>
|
||||
@@ -221,7 +227,7 @@ namespace TEngine
|
||||
var findTrans = transform.Find(path);
|
||||
return findTrans != null ? findTrans : null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据名字找到子节点,主要用于dummy接口。
|
||||
/// </summary>
|
||||
@@ -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<T>(this Transform transform, string path) where T : Component
|
||||
{
|
||||
var findTrans = transform.Find(path);
|
||||
|
@@ -86,9 +86,9 @@ namespace TEngine
|
||||
/// <summary>
|
||||
/// 初始化操作。
|
||||
/// </summary>
|
||||
/// <param name="packageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns></returns>
|
||||
InitializationOperation InitPackage(string packageName = "");
|
||||
InitializationOperation InitPackage(string customPackageName = "");
|
||||
|
||||
/// <summary>
|
||||
/// 卸载资源。
|
||||
|
@@ -332,12 +332,12 @@ namespace TEngine
|
||||
/// 初始化资源包裹。
|
||||
/// </summary>
|
||||
/// <returns>初始化资源包裹操作句柄。</returns>
|
||||
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)
|
||||
{
|
||||
|
@@ -230,10 +230,11 @@ namespace TEngine
|
||||
/// <summary>
|
||||
/// 初始化操作。
|
||||
/// </summary>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns></returns>
|
||||
public InitializationOperation InitPackage()
|
||||
public InitializationOperation InitPackage(string customPackageName = "")
|
||||
{
|
||||
return m_ResourceManager.InitPackage();
|
||||
return m_ResourceManager.InitPackage(customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -528,7 +529,8 @@ namespace TEngine
|
||||
public T LoadAsset<T>(string location, Transform parent, bool needInstance = true, bool needCache = false,
|
||||
string customPackageName = "") where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, needInstance, needCache, packageName: customPackageName);
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, needInstance, needCache,
|
||||
packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -559,7 +561,8 @@ namespace TEngine
|
||||
public T LoadAsset<T>(string location, Transform parent, out AssetOperationHandle handle,
|
||||
bool needCache = false, string customPackageName = "") where T : UnityEngine.Object
|
||||
{
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, out handle, needCache, packageName: customPackageName);
|
||||
return m_ResourceManager.LoadAsset<T>(location, parent, out handle, needCache,
|
||||
packageName: customPackageName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -673,7 +676,8 @@ namespace TEngine
|
||||
/// <typeparam name="T">要加载资源的类型。</typeparam>
|
||||
/// <returns>异步资源实例。</returns>
|
||||
public async UniTask<T> LoadAssetAsync<T>(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<T>(location, cancellationToken, needInstance, needCache,
|
||||
packageName: customPackageName);
|
||||
@@ -720,7 +724,8 @@ namespace TEngine
|
||||
public async UniTask<RawFileOperationHandle> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Reference in New Issue
Block a user