2026-05-11 08:39:33 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
namespace Kill.UI.Components
|
|
|
|
|
|
{
|
|
|
|
|
|
public class MutiSelectPage : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 选项背景颜色 0:未选中 1:已选中
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Color[] bgColors;
|
|
|
|
|
|
public Color[] textColors;
|
|
|
|
|
|
public List<Button> options = new List<Button>();
|
|
|
|
|
|
int nowSelectedIndex = -1;
|
|
|
|
|
|
public Action<int> onConfirm;
|
2026-07-07 10:32:26 +08:00
|
|
|
|
public Action<int> onClick;
|
2026-05-11 08:39:33 +08:00
|
|
|
|
public Button confirmBtn;
|
|
|
|
|
|
public Button cancelBtn;
|
2026-07-07 10:32:26 +08:00
|
|
|
|
public void Init(int selectedIndex, Action<int> onConfirm,Action<int> onClick=null)
|
2026-05-11 08:39:33 +08:00
|
|
|
|
{
|
|
|
|
|
|
confirmBtn.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Confirm();
|
|
|
|
|
|
});
|
|
|
|
|
|
cancelBtn.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Cancel();
|
|
|
|
|
|
});
|
|
|
|
|
|
this.onConfirm = onConfirm;
|
2026-07-07 10:32:26 +08:00
|
|
|
|
this.onClick=onClick;
|
2026-05-11 08:39:33 +08:00
|
|
|
|
nowSelectedIndex = selectedIndex;
|
|
|
|
|
|
for (int i = 0; i < options.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int index = i;
|
|
|
|
|
|
options[i].onClick.RemoveAllListeners();
|
|
|
|
|
|
options[i].onClick.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
OnClickOption(index);
|
|
|
|
|
|
});
|
|
|
|
|
|
if (i == selectedIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
options[i].GetComponentInChildren<Text>().color = textColors[1];
|
|
|
|
|
|
options[i].GetComponent<Image>().color = bgColors[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
options[i].GetComponentInChildren<Text>().color = textColors[0];
|
|
|
|
|
|
options[i].GetComponent<Image>().color = bgColors[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public void OnClickOption(int index)
|
|
|
|
|
|
{
|
2026-07-07 10:32:26 +08:00
|
|
|
|
onClick?.Invoke(index);
|
2026-05-11 08:39:33 +08:00
|
|
|
|
if (nowSelectedIndex == index)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
nowSelectedIndex = index;
|
|
|
|
|
|
}
|
|
|
|
|
|
for (int i = 0; i < options.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (i == nowSelectedIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
options[i].GetComponentInChildren<Text>().color = textColors[1];
|
|
|
|
|
|
options[i].GetComponent<Image>().color = bgColors[1];
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
options[i].GetComponentInChildren<Text>().color = textColors[0];
|
|
|
|
|
|
options[i].GetComponent<Image>().color = bgColors[0];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-07-07 10:32:26 +08:00
|
|
|
|
|
2026-05-11 08:39:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
public void Confirm()
|
|
|
|
|
|
{
|
|
|
|
|
|
onConfirm?.Invoke(nowSelectedIndex);
|
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
public void Cancel()
|
|
|
|
|
|
{
|
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|