88 lines
2.6 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using QFramework;
using System.Collections.Generic;
using TMPro;
using System.Text.RegularExpressions;
using static OperationController;
using System;
namespace QFramework.Example
{
public class UITextTipData : UIPanelData
{
public string text;
public string audio;
public string title;
public float alpha = 0;
public List<string> btns;
}
public partial class UITextTip : UIPanel
{
ResLoader loader;
protected override void OnInit(IUIData uiData = null)
{
mData = uiData as UITextTipData ?? new UITextTipData();
loader = ResLoader.Allocate();
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
}
private void OnStepChanged(StepStatusOnChange change)
{
Hide();
}
protected override void OnOpen(IUIData uiData = null)
{
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged).UnRegisterWhenDisabled(gameObject);
mData = uiData as UITextTipData ?? new UITextTipData();
Des.text = Regex.Replace(mData.text, @"\\n", "\n");
BtnContent.RemoveAllChildren();
if (mData.btns != null)
{
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();
});
}
}
if (string.IsNullOrEmpty(mData.audio) == false)
{
string path = Global.audioPath + mData.audio;
loader.Add2Load(path.ToLocalAudioResName(), (success, res) =>
{
if (success)
{
AudioKit.PlayVoice(res.Asset.As<AudioClip>(), false);
}
});
loader.LoadAsync();
}
Title.text = mData.title;
// Color color = Mask.color;
// color.a = mData.alpha;
// Mask.color = color;
}
protected override void OnShow()
{
}
protected override void OnHide()
{
AudioKit.StopVoice();
}
protected override void OnClose()
{
loader.Recycle2Cache();
}
}
}