75 lines
1.9 KiB
C#
Raw Normal View History

2024-12-14 18:27:59 +08:00
using UnityEngine;
using UnityEngine.UI;
using QFramework;
using DG.Tweening;
2024-12-16 11:28:01 +08:00
using System.Runtime.CompilerServices;
2024-12-14 18:27:59 +08:00
namespace QFramework.Example
{
public class UIHintData : UIPanelData
{
public bool isShowIcon = true;
public string txt;
public float time = -1;
public string audio;
}
public partial class UIHint : UIPanel
{
ResLoader loader;
protected override void OnInit(IUIData uiData = null)
{
mData = uiData as UIHintData ?? new UIHintData();
SetItem(0);
}
protected override void OnOpen(IUIData uiData = null)
{
mData = uiData as UIHintData ?? new UIHintData();
Icon.gameObject.SetActive(mData.isShowIcon);
Label.text = mData.txt;
SetItem(1);
if (mData.time != -1)
{
ActionKit.Delay(mData.time, () =>
{
SetItem(0);
}).Start(this);
}
if (string.IsNullOrEmpty(mData.audio) == false)
{
string path = Global.audioPath + mData.audio;
loader = ResLoader.Allocate();
2024-12-16 11:28:01 +08:00
loader.Add2Load(path.ToLocalAudioResName(), (success, res) =>
2024-12-14 18:27:59 +08:00
{
if (success)
{
2024-12-16 11:28:01 +08:00
AudioKit.PlayVoice(res.Asset.As<AudioClip>(), false);
2024-12-14 18:27:59 +08:00
}
});
2024-12-16 11:28:01 +08:00
loader.LoadAsync();
2024-12-14 18:27:59 +08:00
}
}
public void SetItem(float alph)
{
ItemPrefab.DOFade(alph, 0.5f);
Label.DOFade(alph, 0.5f);
}
protected override void OnShow()
{
}
protected override void OnHide()
{
}
protected override void OnClose()
{
SetItem(0);
2024-12-17 09:49:59 +08:00
loader.Recycle2Cache();
2024-12-14 18:27:59 +08:00
}
}
}