88 lines
2.5 KiB
C#
88 lines
2.5 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using QFramework;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using static OperationController;
|
|
|
|
namespace QFramework.Example
|
|
{
|
|
public class UITipWindowData : UIPanelData
|
|
{
|
|
public class ItemData
|
|
{
|
|
public string txt;
|
|
public Action OnClick;
|
|
}
|
|
public string txt;
|
|
public string audio;
|
|
public List<ItemData> btns = new List<ItemData>();
|
|
}
|
|
public partial class UITipWindow : UIPanel
|
|
{
|
|
ResLoader loader;
|
|
protected override void OnInit(IUIData uiData = null)
|
|
{
|
|
mData = uiData as UITipWindowData ?? new UITipWindowData();
|
|
// please add init code here
|
|
|
|
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged);
|
|
}
|
|
|
|
private void OnStepChanged(StepStatusOnChange change)
|
|
{
|
|
Hide();
|
|
}
|
|
|
|
protected override void OnOpen(IUIData uiData = null)
|
|
{
|
|
mData = uiData as UITipWindowData ?? new UITipWindowData();
|
|
Label.text = mData.txt;
|
|
BtnContent.RemoveAllChildren();
|
|
if (mData != null)
|
|
{
|
|
foreach (var item in mData.btns)
|
|
{
|
|
GameObject obj = GameObject.Instantiate(BtnPrefab.gameObject, BtnContent);
|
|
obj.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = item.txt;
|
|
obj.name = item.txt;
|
|
obj.GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
item.OnClick?.Invoke();
|
|
Hide();
|
|
});
|
|
}
|
|
|
|
}
|
|
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();
|
|
}
|
|
}
|
|
|
|
protected override void OnShow()
|
|
{
|
|
}
|
|
|
|
protected override void OnHide()
|
|
{
|
|
AudioKit.StopVoice();
|
|
}
|
|
|
|
protected override void OnClose()
|
|
{
|
|
loader.Recycle2Cache();
|
|
}
|
|
}
|
|
}
|