Update UIExtension.cs

This commit is contained in:
ALEXTANG
2023-06-25 15:26:08 +08:00
parent 990e17a6cc
commit b60b9fff42

View File

@@ -7,6 +7,7 @@ using TEngine;
public static class UIExtension
{
#region SetActive
public static void SetActive(this GameObject go, bool value, ref bool cacheValue)
{
if (go != null && value != cacheValue)
@@ -15,8 +16,9 @@ public static class UIExtension
go.SetActive(value);
}
}
#endregion
public static IEnumerator FadeToAlpha(this CanvasGroup canvasGroup, float alpha, float duration,
Action callback = null)
{
@@ -110,4 +112,46 @@ public static class UIExtension
return hadMouseDown;
}
public static void SetSprite(this Image image, string spriteName, UIBase uiBase, bool isSetNativeSize = false)
{
if (image == null)
{
return;
}
if (string.IsNullOrEmpty(spriteName))
{
image.sprite = null;
}
else
{
image.sprite = uiBase.LoadAsset<Sprite>(spriteName);
if (isSetNativeSize)
{
image.SetNativeSize();
}
}
}
public static void SetSprite(this UIBase uiBase, string spriteName, Image image, bool isSetNativeSize = false)
{
if (image == null)
{
return;
}
if (string.IsNullOrEmpty(spriteName))
{
image.sprite = null;
}
else
{
image.sprite = uiBase.LoadAsset<Sprite>(spriteName);
if (isSetNativeSize)
{
image.SetNativeSize();
}
}
}
}