This commit is contained in:
陈思海 2025-12-17 14:23:24 +08:00
parent 13eb84d289
commit 52deecb22a

View File

@ -374,21 +374,43 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand
// 等一帧,保证 EventSystem 更新 currentSelectedGameObject // 等一帧,保证 EventSystem 更新 currentSelectedGameObject
yield return null; yield return null;
bool selectionIsNull = EventSystem.current == null || EventSystem.current.currentSelectedGameObject == null; // 当前选中对象(可能为 null
var currentSelected = EventSystem.current != null ? EventSystem.current.currentSelectedGameObject : null;
if (selectionIsNull) if (currentSelected == null)
{ {
// 统一走封装入口清理锁 // 没有任何选中对象:清理锁
SetLockedButton(null); SetLockedButton(null);
// 额外保证本实例的本地标志被清掉(以防极端顺序仍然残留)
m_IsFocusLocked = false; m_IsFocusLocked = false;
} }
else
{
// 如果有选中对象,检查它是否属于一个 UXButton可能是子对象
var selectedBtn = currentSelected.GetComponentInParent<UXButton>();
if (selectedBtn == null)
{
// 新选中对象不是 UXButton 的组成部分:清理锁
SetLockedButton(null);
m_IsFocusLocked = false;
}
else if (selectedBtn != this)
{
// 新选中对象属于另一个 UXButton把锁转给那个按钮
// (即便目标的 OnSelect 也可能会做这件事,这里直接转能避免时序问题)
SetLockedButton(selectedBtn);
}
else
{
// selectedBtn == this焦点仍然在自己上不需要清理
}
}
_deferredDeselectRoutine = null; _deferredDeselectRoutine = null;
} }
public override void OnDeselect(BaseEventData eventData) public override void OnDeselect(BaseEventData eventData)
{ {
base.OnDeselect(eventData); base.OnDeselect(eventData);