简单选择列表
This commit is contained in:
@@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 52241bceb69a4f07be09e3dc319276dc
|
||||||
|
timeCreated: 1753341533
|
||||||
Reference in New Issue
Block a user