修改
This commit is contained in:
parent
01c471cb95
commit
6bd66da295
@ -137,7 +137,7 @@ public class UXGroup : UIBehaviour
|
||||
{
|
||||
if (m_Buttons.Count == 0) return;
|
||||
|
||||
int startIndex = _current ? m_Buttons.IndexOf(_current) : 0;
|
||||
int startIndex = _current ? m_Buttons.IndexOf(_current) : -1;
|
||||
int newIndex = FindSelectableIndex(startIndex, 1);
|
||||
|
||||
if (newIndex != -1)
|
||||
@ -147,31 +147,24 @@ public class UXGroup : UIBehaviour
|
||||
}
|
||||
|
||||
|
||||
private int FindSelectableIndex(int startIndex, int direction)
|
||||
{
|
||||
private int FindSelectableIndex(int startIndex, int direction) {
|
||||
if (m_Buttons.Count == 0) return -1;
|
||||
|
||||
startIndex = Mathf.Clamp(startIndex, -1, m_Buttons.Count - 1);
|
||||
// 计算当前有效起点
|
||||
int current = (startIndex == -1)
|
||||
? (direction > 0 ? 0 : m_Buttons.Count - 1)
|
||||
: startIndex;
|
||||
|
||||
int fallback = -1;
|
||||
// 单次简单循环查找
|
||||
for (int i = 0; i < m_Buttons.Count; i++) {
|
||||
int index = (current + direction * i + m_Buttons.Count) % m_Buttons.Count;
|
||||
|
||||
for (int i = 0; i < m_Buttons.Count; i++)
|
||||
{
|
||||
int index = (startIndex + direction + m_Buttons.Count + i * direction) % m_Buttons.Count;
|
||||
|
||||
index = direction < 0 ? (m_Buttons.Count - index - 1) : index;
|
||||
|
||||
var button = m_Buttons[index];
|
||||
|
||||
if (button == null || !button.isActiveAndEnabled || !button.Interactable)
|
||||
continue;
|
||||
|
||||
if (fallback == -1) fallback = index;
|
||||
|
||||
if (_current == null)
|
||||
if (m_Buttons[index] != null &&
|
||||
m_Buttons[index].isActiveAndEnabled &&
|
||||
m_Buttons[index].Interactable) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
return fallback;
|
||||
return -1; // 没有可用按钮
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user