This commit is contained in:
陈思海 2025-08-08 20:56:31 +08:00
parent 9014787967
commit 01c471cb95
2 changed files with 64 additions and 0 deletions

View File

@ -84,6 +84,11 @@ public class UXButton : UIBehaviour, IButton,
#region Properties
internal bool Interactable
{
get => m_Interactable;
}
internal Animator animator
{
get

View File

@ -31,6 +31,7 @@ public class UXGroup : UIBehaviour
{
if (button) button.IsSelected = false;
}
m_Buttons.Clear();
_registeredButtons.Clear();
base.OnDestroy();
@ -113,6 +114,64 @@ public class UXGroup : UIBehaviour
if (button != exclusion && button.IsSelected)
return true;
}
return false;
}
public void SelectPrevious()
{
if (m_Buttons.Count == 0) return;
int startIndex = _current ? m_Buttons.IndexOf(_current) : -1;
int newIndex = FindSelectableIndex(startIndex, -1);
if (newIndex != -1)
{
SetSelectedButton(m_Buttons[newIndex]);
}
}
public void SelectNext()
{
if (m_Buttons.Count == 0) return;
int startIndex = _current ? m_Buttons.IndexOf(_current) : 0;
int newIndex = FindSelectableIndex(startIndex, 1);
if (newIndex != -1)
{
SetSelectedButton(m_Buttons[newIndex]);
}
}
private int FindSelectableIndex(int startIndex, int direction)
{
if (m_Buttons.Count == 0) return -1;
startIndex = Mathf.Clamp(startIndex, -1, m_Buttons.Count - 1);
int fallback = -1;
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)
return index;
}
return fallback;
}
}