54 lines
1.3 KiB
C#
54 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using QFramework;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
using TMPro;
|
|
|
|
namespace QFramework.Example
|
|
{
|
|
public class UIRightMenuData : UIPanelData
|
|
{
|
|
public List<string> btns;
|
|
public Action<string> OnBtnClick;
|
|
}
|
|
public partial class UIRightMenu : UIPanel
|
|
{
|
|
protected override void OnInit(IUIData uiData = null)
|
|
{
|
|
// please add init code here
|
|
}
|
|
|
|
protected override void OnOpen(IUIData uiData = null)
|
|
{
|
|
mData = uiData as UIRightMenuData ?? new UIRightMenuData();
|
|
MenuContent.transform.RemoveAllChildren();
|
|
foreach (var item in mData.btns)
|
|
{
|
|
Button btn = GameObject.Instantiate(BtnPrefab, MenuContent.transform);
|
|
btn.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = item;
|
|
btn.name = item;
|
|
btn.onClick.AddListener(() =>
|
|
{
|
|
mData.OnBtnClick?.Invoke(item);
|
|
Hide();
|
|
});
|
|
}
|
|
|
|
MenuContent.transform.position = Input.mousePosition;
|
|
}
|
|
|
|
protected override void OnShow()
|
|
{
|
|
}
|
|
|
|
protected override void OnHide()
|
|
{
|
|
}
|
|
|
|
protected override void OnClose()
|
|
{
|
|
}
|
|
}
|
|
}
|