91 lines
2.5 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-30 19:15:34 +08:00
using static OperationController;
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;
2025-01-08 15:11:32 +08:00
IAction curAction;
2024-12-14 18:27:59 +08:00
protected override void OnInit(IUIData uiData = null)
{
mData = uiData as UIHintData ?? new UIHintData();
SetItem(0);
2025-01-09 09:43:15 +08:00
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
2024-12-14 18:27:59 +08:00
}
2024-12-30 19:15:34 +08:00
private void OnStepChanged(StepStatusOnChange change)
{
Hide();
}
2024-12-14 18:27:59 +08:00
protected override void OnOpen(IUIData uiData = null)
{
2025-01-09 13:35:04 +08:00
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged).UnRegisterWhenDisabled(gameObject);
2024-12-14 18:27:59 +08:00
mData = uiData as UIHintData ?? new UIHintData();
2025-01-08 15:11:32 +08:00
if (curAction != null)
{
curAction.Deinit();
curAction = null;
}
2024-12-14 18:27:59 +08:00
Icon.gameObject.SetActive(mData.isShowIcon);
Label.text = mData.txt;
SetItem(1);
if (mData.time != -1)
{
2025-01-08 15:11:32 +08:00
curAction = ActionKit.Delay(mData.time, () =>
{
SetItem(0);
});
curAction.Start(this);
2024-12-14 18:27:59 +08:00
}
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);
2025-01-08 11:13:02 +08:00
Icon.gameObject.SetActive(alph == 1);
2024-12-14 18:27:59 +08:00
}
protected override void OnShow()
{
}
protected override void OnHide()
{
2024-12-17 10:00:33 +08:00
AudioKit.StopVoice();
2024-12-14 18:27:59 +08:00
}
protected override void OnClose()
{
SetItem(0);
2024-12-17 09:49:59 +08:00
loader.Recycle2Cache();
2024-12-14 18:27:59 +08:00
}
}
}