This commit is contained in:
陈思海 2025-12-17 13:41:50 +08:00
parent c8bb190c2e
commit 85d9a87ccb

View File

@ -260,10 +260,11 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand
if (EventSystem.current != null)
EventSystem.current.SetSelectedGameObject(gameObject, eventData);
SetLockedButton(this);
UISystemProfilerApi.AddMarker("Button.onClick", this);
m_OnClick?.Invoke();
if (IsStillSelected())
SetLockedButton(this);
}
else
{
@ -279,7 +280,9 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand
{
if (EventSystem.current != null)
EventSystem.current.SetSelectedGameObject(gameObject, eventData);
SetLockedButton(this);
if (IsStillSelected())
SetLockedButton(this);
}
}
}
@ -309,19 +312,19 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand
m_HasExitedWhileDown = false;
ForceSetState(SelectionState.Pressed);
PlayAudio(clickAudioClip);
if (m_Mode == ButtonModeType.Toggle)
{
_resetRoutine = StartCoroutine(SubmitToggleDeferredRoutine());
return;
}
// ① 先执行回调(可能切走焦点)
HandleClick();
if (navigation.mode != UXNavigation.Mode.None)
// ② 只在“焦点仍在自己”时才锁
if (navigation.mode != UXNavigation.Mode.None && IsStillSelected())
SetLockedButton(this);
if (navigation.mode != UXNavigation.Mode.None && m_Mode == ButtonModeType.Normal)
@ -439,23 +442,23 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand
Animator.ResetTrigger(id);
}
SetLockedButton(this);
ApplyVisualState(SelectionState.Selected, false);
if (IsStillSelected())
{
SetLockedButton(this);
ApplyVisualState(SelectionState.Selected, false);
}
_resetRoutine = null;
}
private IEnumerator SubmitToggleDeferredRoutine()
{
yield return null;
yield return _waitFadeDuration;
HandleClick();
if (Animator)
{
foreach (int id in _animTriggerCache.Values)
@ -465,20 +468,19 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand
m_IsDown = false;
m_HasExitedWhileDown = false;
bool stillFocused = EventSystem.current != null && EventSystem.current.currentSelectedGameObject == gameObject;
if (stillFocused || m_IsNavFocused)
bool stillFocused = IsStillSelected();
if (stillFocused)
SetState(SelectionState.Selected);
else
SetState(_mTogSelected ? SelectionState.Selected : SelectionState.Normal);
if (navigation.mode != UXNavigation.Mode.None)
if (navigation.mode != UXNavigation.Mode.None && stillFocused)
SetLockedButton(this);
_resetRoutine = null;
}
private IEnumerator ResetAfterSubmit()
{
yield return _waitFadeDuration;
@ -490,10 +492,11 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand
#region Utility
private void ForceSetState(SelectionState state)
private bool IsStillSelected()
{
// 链接到基类的 ForceSetState
base.ForceSetState(state);
if (EventSystem.current != null)
return EventSystem.current.currentSelectedGameObject == gameObject;
return m_IsNavFocused;
}
#endregion