fix
This commit is contained in:
parent
c25f3f46d6
commit
ca28bb2c55
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user