46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using AlicizaX.Resource.Runtime;
|
|
using AlicizaX.Runtime;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public static class SetSpriteExtensions
|
|
{
|
|
/// <summary>
|
|
/// 获取事件组件。
|
|
/// </summary>
|
|
static ResourceExtComponent ResourceExt
|
|
{
|
|
get
|
|
{
|
|
if (_resourceExt == null)
|
|
{
|
|
_resourceExt = GameEntry.GetComponent<ResourceExtComponent>();
|
|
}
|
|
|
|
return _resourceExt;
|
|
}
|
|
}
|
|
|
|
static ResourceExtComponent _resourceExt;
|
|
|
|
/// <summary>
|
|
/// 设置图片。
|
|
/// </summary>
|
|
/// <param name="image">UI/Image。</param>
|
|
/// <param name="location">资源定位地址。</param>
|
|
/// <param name="setNativeSize">是否使用原始分辨率。</param>
|
|
public static void SetSprite(this Image image, string location, bool setNativeSize = false)
|
|
{
|
|
ResourceExt.SetAssetByResources<Sprite>(SetSpriteObject.Create(image, location, setNativeSize)).Forget();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置图片。
|
|
/// </summary>
|
|
/// <param name="spriteRenderer">2D/SpriteRender。</param>
|
|
/// <param name="location">资源定位地址。</param>
|
|
public static void SetSprite(this SpriteRenderer spriteRenderer, string location)
|
|
{
|
|
ResourceExt.SetAssetByResources<Sprite>(SetSpriteObject.Create(spriteRenderer, location)).Forget();
|
|
}
|
|
} |