修改
This commit is contained in:
parent
9014787967
commit
01c471cb95
@ -84,6 +84,11 @@ public class UXButton : UIBehaviour, IButton,
|
|||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
|
internal bool Interactable
|
||||||
|
{
|
||||||
|
get => m_Interactable;
|
||||||
|
}
|
||||||
|
|
||||||
internal Animator animator
|
internal Animator animator
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -31,6 +31,7 @@ public class UXGroup : UIBehaviour
|
|||||||
{
|
{
|
||||||
if (button) button.IsSelected = false;
|
if (button) button.IsSelected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Buttons.Clear();
|
m_Buttons.Clear();
|
||||||
_registeredButtons.Clear();
|
_registeredButtons.Clear();
|
||||||
base.OnDestroy();
|
base.OnDestroy();
|
||||||
@ -113,6 +114,64 @@ public class UXGroup : UIBehaviour
|
|||||||
if (button != exclusion && button.IsSelected)
|
if (button != exclusion && button.IsSelected)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user