简单选择列表

This commit is contained in:
2025-07-24 15:28:26 +08:00
parent 6f8d748a60
commit 4fab84e68f
2 changed files with 48 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
using System;
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;
namespace CreatGame.UI
{
public delegate void OnSelectCallback(int index);
/// <summary>
/// 选中列表
/// </summary>
public class UISelectList : MonoBehaviour
{
public OnSelectCallback onSelectCallback;
private List<Button> m_buttonList = new List<Button>();
private void Awake()
{
m_buttonList = new List<Button>();
}
/// <summary>
///
/// </summary>
private void Start()
{
var childCount= transform.childCount;
for (int i = 0; i < childCount; i++)
{
var button = transform.GetChild(i).GetComponent<Button>();
if (button != null)
{
m_buttonList.Add(button);
button.onClick.AddListener(() => { OnClick(button); });
}
}
}
/// <summary>
///
/// </summary>
/// <param name="btn"></param>
private void OnClick(Button btn)
{
onSelectCallback?.Invoke(m_buttonList.IndexOf(btn));
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 52241bceb69a4f07be09e3dc319276dc
timeCreated: 1753341533