2025-01-09 09:43:15 +08:00

60 lines
1.6 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using QFramework;
using System.Collections.Generic;
using TMPro;
using static OperationController;
using System;
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
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged);
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
}
private void OnStepChanged(StepStatusOnChange change)
{
Hide();
}
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()
{
}
}
}