This commit is contained in:
陈思海 2025-12-17 14:39:09 +08:00
parent e1020fd308
commit 418db1838e

View File

@ -38,6 +38,7 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand
private bool _mTogSelected;
private Coroutine _resetRoutine;
private Coroutine _deferredDeselectRoutine;
private Coroutine _deferredLockRoutine; // 新增:用于 Focus 延迟锁定的协程
private WaitForSeconds _waitFadeDuration;
// 静态锁(用于 normal 模式点击后的“保持 Selected”并能转移
@ -118,6 +119,10 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand
{
if (_resetRoutine != null)
StopCoroutine(_resetRoutine);
if (_deferredDeselectRoutine != null)
StopCoroutine(_deferredDeselectRoutine);
if (_deferredLockRoutine != null)
StopCoroutine(_deferredLockRoutine);
base.OnDestroy();
}
@ -410,7 +415,6 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand
}
public override void OnDeselect(BaseEventData eventData)
{
base.OnDeselect(eventData);
@ -594,6 +598,7 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand
if (!IsInteractable())
return;
// 先发起选中请求
if (EventSystem.current != null)
{
EventSystem.current.SetSelectedGameObject(gameObject, new BaseEventData(EventSystem.current));
@ -601,9 +606,32 @@ public class UXButton : UXSelectable, IButton, IPointerClickHandler, ISubmitHand
m_IsNavFocused = true;
if ((s_LockedButton != null && s_LockedButton != this) || s_LockedButton == null)
// 停掉已有的延迟锁协程(如果有)
if (_deferredLockRoutine != null)
{
StopCoroutine(_deferredLockRoutine);
_deferredLockRoutine = null;
}
// 如果已经成为 EventSystem 的 selected则立即锁定否则延迟一帧再确认并锁定
if (IsStillSelected())
{
SetLockedButton(this);
}
else
{
_deferredLockRoutine = StartCoroutine(DeferredLockAfterFocus());
}
}
private IEnumerator DeferredLockAfterFocus()
{
// 等一帧,让 EventSystem 完成 selected 的更新和分发OnDeselect/OnSelect 等)
yield return null;
if (IsStillSelected())
SetLockedButton(this);
_deferredLockRoutine = null;
}
}