51 lines
1.3 KiB
C#
Raw Normal View History

2024-12-14 18:27:59 +08:00
using UnityEngine;
using UnityEngine.UI;
using QFramework;
using System.Collections.Generic;
using TMPro;
namespace QFramework.Example
{
public class UIBtnsData : UIPanelData
{
public List<string> btns = new List<string>();
}
public partial class UIBtns : UIPanel
{
protected override void OnInit(IUIData uiData = null)
{
mData = uiData as UIBtnsData ?? new UIBtnsData();
// please add init code here
}
protected override void OnOpen(IUIData uiData = null)
{
mData = uiData as UIBtnsData ?? new UIBtnsData();
BtnContent.RemoveAllChildren();
foreach (var item in mData.btns)
{
GameObject obj = GameObject.Instantiate(BtnPrefab.gameObject, BtnContent);
obj.name = item;
obj.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = item;
obj.GetComponent<Button>().onClick.AddListener(() =>
{
Hide();
});
}
}
protected override void OnShow()
{
}
protected override void OnHide()
{
}
protected override void OnClose()
{
}
}
}