88 lines
2.7 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;
2024-12-30 19:15:34 +08:00
using static OperationController;
using System;
using System.Linq;
2024-12-14 18:27:59 +08:00
namespace QFramework.Example
{
public class UIBtnsData : UIPanelData
{
public List<string> btns = new List<string>();
public string name;
public string pos;
public string size;
2025-06-20 18:32:18 +08:00
public string HieraName;
2024-12-14 18:27:59 +08:00
}
public partial class UIBtns : UIPanel
{
protected override void OnInit(IUIData uiData = null)
{
mData = uiData as UIBtnsData ?? new UIBtnsData();
// please add init code here
2025-01-09 09:43:15 +08:00
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
2024-12-30 19:15:34 +08:00
}
private void OnStepChanged(StepStatusOnChange change)
{
Hide();
2024-12-14 18:27:59 +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-14 18:27:59 +08:00
mData = uiData as UIBtnsData ?? new UIBtnsData();
BtnContent.RemoveAllChildren();
2025-06-20 18:32:18 +08:00
List<String> HieraNames = mData.HieraName.Split('|')?.ToList();
List<String> btnnames = mData.name.Split('|')?.ToList();
List<String> pos = mData.pos.Split('|')?.ToList();
List<String> size = mData.size.Split('|')?.ToList();
for (int i = 0; i < btnnames.Count; i++) {
int j = i;
2024-12-14 18:27:59 +08:00
GameObject obj = GameObject.Instantiate(BtnPrefab.gameObject, BtnContent);
2025-06-20 18:32:18 +08:00
obj.name = HieraNames[j];
Vector2 positem = Utility.GetVector2FromStrArray(pos[j]);
Vector2 sizeData = Utility.GetVector2FromStrArray(size[j]);
obj.transform.Find("Label").GetComponent<TextMeshProUGUI>().text= btnnames[j];
obj.GetComponent<RectTransform>().sizeDelta = sizeData;
obj.GetComponent<RectTransform>().localPosition = positem;
2024-12-14 18:27:59 +08:00
}
//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();
// });
//}
2024-12-14 18:27:59 +08:00
}
protected override void OnShow()
{
}
protected override void OnHide()
{
}
protected override void OnClose()
{
}
}
}