From ca28bb2c55e382e6106661a065c924325f18a782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=80=9D=E6=B5=B7?= <1464576565@qq.com> Date: Wed, 17 Dec 2025 15:33:10 +0800 Subject: [PATCH] fix --- Runtime/UXComponent/Button/UXButton.cs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/Runtime/UXComponent/Button/UXButton.cs b/Runtime/UXComponent/Button/UXButton.cs index 8666d87..0e1eb97 100644 --- a/Runtime/UXComponent/Button/UXButton.cs +++ b/Runtime/UXComponent/Button/UXButton.cs @@ -343,13 +343,17 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand m_IsNavFocused = true; - if (s_LockedButton != null && s_LockedButton != this) + // 变更:当通过 EventSystem.current.SetSelectedGameObject(...) 选中时, + // 也要像 Focus() 一样将静态锁设置到当前按钮(除非已经是自己)。 + // 这样外部直接调用 EventSystem.current.SetSelectedGameObject(...) 就能生效, + // 无需再调用 Focus(). + if (s_LockedButton != this) { SetLockedButton(this); return; } - // 聚焦时(无论逻辑是否选中),Toggle 显示 Selected + // 如果聚焦时(无论逻辑是否选中),Toggle 显示 Selected if (m_Mode == ButtonModeType.Toggle) { SetState(SelectionState.Selected); @@ -371,7 +375,6 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand private IEnumerator DeferredDeselectCheck() { - // 等一帧,保证 EventSystem 更新 currentSelectedGameObject yield return null; bool selectionIsNull = EventSystem.current == null || EventSystem.current.currentSelectedGameObject == null; @@ -569,19 +572,9 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand public void Focus() { - if (!IsInteractable()) - return; - - if (EventSystem.current != null) + if (gameObject != null && EventSystem.current != null) { - EventSystem.current.SetSelectedGameObject(gameObject, new BaseEventData(EventSystem.current)); - } - - m_IsNavFocused = true; - - if ((s_LockedButton != null && s_LockedButton != this) || s_LockedButton == null) - { - SetLockedButton(this); + EventSystem.current.SetSelectedGameObject(gameObject); } } }