2025-02-14 16:10:58 +08:00

75 lines
2.1 KiB
C#

using UnityEngine;
using DG.Tweening;
namespace QFramework.Example
{
public class UIImageTipData : UIPanelData
{
public bool isDrag = true;
public Vector2 size;
public string imgPath;
public Vector2 position;
}
public partial class UIImageTip : UIPanel
{
DOTweenAnimation loadingAnim;
protected override void OnInit(IUIData uiData = null)
{
loadingAnim = Loading.GetComponent<DOTweenAnimation>();
CloseBtn.onClick.AddListener(() =>
{
Hide();
});
}
protected override void OnOpen(IUIData uiData = null)
{
mData = uiData as UIImageTipData ?? new UIImageTipData();
Loading.gameObject.SetActive(true);
loadingAnim.DOPlay();
Img.gameObject.SetActive(false);
Img.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
ResLoader loader = ResLoader.Allocate();
var localImageUrl = Global.imagePath + mData.imgPath;
loader.Add2Load(localImageUrl.ToNetImageResName(),
(bool success, IRes res) =>
{
if (success)
{
Img.sprite = Utility.GetSprite(res.Asset as Texture2D);
if (mData.size == default)
{
Img.SetNativeSize();
}
else
{
Img.rectTransform.sizeDelta = mData.size;
}
Img.gameObject.SetActive(true);
loadingAnim.DOPause();
Loading.gameObject.SetActive(false);
}
});
Img.GetComponent<UIDragItem>().enabled = mData.isDrag;
Img.rectTransform.anchoredPosition = mData.position;
loader.LoadAsync();
}
protected override void OnShow()
{
}
protected override void OnHide()
{
}
protected override void OnClose()
{
}
}
}