killapp/Assets/Scripts/UI/Components/MutiSelectPage.cs
“虞渠成” a01ff23268 feat: 新增音效资源并优化音效选择功能
1. 新增Arc、Ion、Sonic、Plasma、Quantum、Hardlight共6种音效资源及导入配置
2. 为多选弹窗组件添加点击回调事件,支持选项点击预览音效
3. 为音画设置页面添加音效预览功能,绑定新增的音效资源
4. 修复iOS构建脚本的编译宏条件问题
5. 更新.gitignore忽略灭蚊_mapping.txt文件
2026-07-07 10:32:26 +08:00

92 lines
2.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
public Action<int> onClick;
public Button confirmBtn;
public Button cancelBtn;
public void Init(int selectedIndex, Action<int> onConfirm,Action<int> onClick=null)
{
confirmBtn.onClick.AddListener(() =>
{
Confirm();
});
cancelBtn.onClick.AddListener(() =>
{
Cancel();
});
this.onConfirm = onConfirm;
this.onClick=onClick;
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)
{
onClick?.Invoke(index);
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];
}
}
}
public void Confirm()
{
onConfirm?.Invoke(nowSelectedIndex);
Destroy(gameObject);
}
public void Cancel()
{
Destroy(gameObject);
}
}
}