88 lines
2.7 KiB
C#
88 lines
2.7 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using QFramework;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using static OperationController;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace QFramework.Example
|
|
{
|
|
public class UIBtnsData : UIPanelData
|
|
{
|
|
public List<string> btns = new List<string>();
|
|
public string name;
|
|
public string pos;
|
|
public string size;
|
|
public string HieraName;
|
|
}
|
|
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<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 UIBtnsData ?? new UIBtnsData();
|
|
BtnContent.RemoveAllChildren();
|
|
|
|
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;
|
|
GameObject obj = GameObject.Instantiate(BtnPrefab.gameObject, BtnContent);
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//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()
|
|
{
|
|
}
|
|
}
|
|
}
|