2024-12-14 18:27:59 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using QFramework;
|
2024-12-17 09:39:38 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using TMPro;
|
2024-12-18 09:48:53 +08:00
|
|
|
using System.Text.RegularExpressions;
|
2025-01-09 10:22:06 +08:00
|
|
|
using static OperationController;
|
|
|
|
|
using System;
|
2024-12-14 18:27:59 +08:00
|
|
|
|
|
|
|
|
namespace QFramework.Example
|
|
|
|
|
{
|
2024-12-17 09:39:38 +08:00
|
|
|
public class UITextTipData : UIPanelData
|
|
|
|
|
{
|
|
|
|
|
public string text;
|
2024-12-17 09:49:59 +08:00
|
|
|
public string audio;
|
2024-12-17 09:39:38 +08:00
|
|
|
public List<string> btns;
|
|
|
|
|
}
|
|
|
|
|
public partial class UITextTip : UIPanel
|
|
|
|
|
{
|
2024-12-17 09:49:59 +08:00
|
|
|
ResLoader loader;
|
2024-12-17 09:39:38 +08:00
|
|
|
protected override void OnInit(IUIData uiData = null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
mData = uiData as UITextTipData ?? new UITextTipData();
|
2025-01-09 09:43:15 +08:00
|
|
|
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
|
2024-12-17 09:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-01-09 10:22:06 +08:00
|
|
|
private void OnStepChanged(StepStatusOnChange change)
|
|
|
|
|
{
|
|
|
|
|
Hide();
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-17 09:39:38 +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-17 09:39:38 +08:00
|
|
|
mData = uiData as UITextTipData ?? new UITextTipData();
|
2024-12-18 09:48:53 +08:00
|
|
|
Des.text = Regex.Replace(mData.text, @"\\n", "\n");
|
2024-12-17 09:39:38 +08:00
|
|
|
BtnContent.RemoveAllChildren();
|
|
|
|
|
foreach (var item in mData.btns)
|
|
|
|
|
{
|
|
|
|
|
GameObject btn = GameObject.Instantiate(Btn.gameObject, BtnContent);
|
|
|
|
|
btn.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = item;
|
|
|
|
|
btn.name = item;
|
|
|
|
|
btn.GetComponent<Button>().onClick.AddListener(() =>
|
|
|
|
|
{
|
|
|
|
|
Hide();
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-12-17 09:49:59 +08:00
|
|
|
if (string.IsNullOrEmpty(mData.audio) == false)
|
|
|
|
|
{
|
|
|
|
|
string path = Global.audioPath + mData.audio;
|
|
|
|
|
loader = ResLoader.Allocate();
|
|
|
|
|
loader.Add2Load(path.ToLocalAudioResName(), (success, res) =>
|
|
|
|
|
{
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
AudioKit.PlayVoice(res.Asset.As<AudioClip>(), false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
loader.LoadAsync();
|
|
|
|
|
}
|
2024-12-17 09:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnShow()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHide()
|
|
|
|
|
{
|
2024-12-17 10:00:33 +08:00
|
|
|
AudioKit.StopVoice();
|
2024-12-17 09:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnClose()
|
|
|
|
|
{
|
2024-12-17 09:49:59 +08:00
|
|
|
loader.Recycle2Cache();
|
2024-12-17 09:39:38 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-12-14 18:27:59 +08:00
|
|
|
}
|