fix(eventsystem): 修复锁定时松手未清理导致光标卡住

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-21 01:16:57 +08:00
co-authored by Cursor
parent 164e3dd50e
commit dc0488f085
2 changed files with 58 additions and 20 deletions
@@ -90,6 +90,20 @@ namespace AibisDream.Framework
#endregion
/// <summary>
/// 兜底:鼠标左键已抬起时强制清空 holding/dragging。
/// 防止 EventTrigger 在 isLocked 时跳过 Up/EndDrag 清理后光标一直停在抓取。
/// </summary>
private void LateUpdate()
{
if (Input.GetMouseButton(0)) return;
if (holdingObjList.Count > 0)
holdingObjList.Clear();
if (draggingObjList.Count > 0)
draggingObjList.Clear();
}
private void HandleDialogueComplete()
{
isLocked = false;
@@ -12,7 +12,18 @@ namespace AibisDream.Framework
public class EventTriggerEx : EventTrigger
{
private IInteraction _interaction;
private IInteraction Interaction
{
get
{
// 惰性获取:bridge 可能在 EventTriggerEx 之后才 AddComponent
if (_interaction == null)
_interaction = GetComponent<IInteraction>();
return _interaction;
}
}
private void Awake()
{
_interaction = GetComponent<IInteraction>();
@@ -73,15 +84,26 @@ namespace AibisDream.Framework
}
}
private bool CanStartInteraction()
{
return Interaction != null
&& Interaction.IsAvailable
&& EventSystemEx.Instance != null
&& !EventSystemEx.Instance.isLocked;
}
public override void OnPointerEnter(PointerEventData data)
{
if (_interaction != null) EventSystemEx.Instance.OnPointerEnter(_interaction);
if (Interaction != null && EventSystemEx.Instance != null)
EventSystemEx.Instance.OnPointerEnter(Interaction);
base.OnPointerEnter(data);
}
public override void OnPointerExit(PointerEventData data)
{
if (_interaction != null) EventSystemEx.Instance.OnPointerExit(_interaction);
// 退出必须始终清理,否则旋转/细长 Collider 丢 Exit 时会卡住光标
if (Interaction != null && EventSystemEx.Instance != null)
EventSystemEx.Instance.OnPointerExit(Interaction);
base.OnPointerExit(data);
}
@@ -89,57 +111,59 @@ namespace AibisDream.Framework
{
// 对话等场景 isLocked 时仍要让 EventTrigger 上注册的回调执行(如塔罗 PointerDown),
// 否则会出现能 Hover、但 Down/Up/Click 全不进组件的问题。
if (_interaction != null && _interaction.IsAvailable && !EventSystemEx.Instance.isLocked)
EventSystemEx.Instance.OnPointerDown(_interaction);
// 仅「开始」交互时受 isLocked / IsAvailable 门控;清理路径见 Up/EndDrag。
if (CanStartInteraction())
EventSystemEx.Instance.OnPointerDown(Interaction);
base.OnPointerDown(eventData);
}
public override void OnPointerUp(PointerEventData eventData)
{
if (_interaction != null && _interaction.IsAvailable && !EventSystemEx.Instance.isLocked)
EventSystemEx.Instance.OnPointerUp(_interaction);
// 松手必须始终清理 holding,否则充能结束开对话把 isLocked 置真后会永远卡在抓取光标
if (Interaction != null && EventSystemEx.Instance != null)
EventSystemEx.Instance.OnPointerUp(Interaction);
base.OnPointerUp(eventData);
}
public override void OnDrag(PointerEventData eventData)
{
if (_interaction != null && _interaction.IsAvailable && !EventSystemEx.Instance.isLocked)
if (CanStartInteraction())
{
EventSystemEx.Instance.OnDrag(_interaction);
EventSystemEx.Instance.OnDrag(Interaction);
base.OnDrag(eventData);
}
}
public override void OnEndDrag(PointerEventData eventData)
{
if (_interaction != null && _interaction.IsAvailable && !EventSystemEx.Instance.isLocked)
{
EventSystemEx.Instance.OnEndDrag(_interaction);
base.OnEndDrag(eventData);
}
// 与 PointerUp 相同:清理不受 isLocked 门控
if (Interaction != null && EventSystemEx.Instance != null)
EventSystemEx.Instance.OnEndDrag(Interaction);
base.OnEndDrag(eventData);
}
public override void OnBeginDrag(PointerEventData eventData)
{
if (_interaction != null && _interaction.IsAvailable && !EventSystemEx.Instance.isLocked)
if (CanStartInteraction())
{
EventSystemEx.Instance.OnBeginDrag(_interaction);
EventSystemEx.Instance.OnBeginDrag(Interaction);
base.OnBeginDrag(eventData);
}
}
public override void OnPointerClick(PointerEventData eventData)
{
if (_interaction != null && _interaction.IsAvailable && !EventSystemEx.Instance.isLocked)
if (CanStartInteraction())
{
// EventSystemEx.Instance.OnPointerClick(_interaction);
// EventSystemEx.Instance.OnPointerClick(Interaction);
}
base.OnPointerClick(eventData);
}
void OnDestroy()
{
EventSystemEx.Instance.UnRegister(_interaction);
if (EventSystemEx.Instance != null && Interaction != null)
EventSystemEx.Instance.UnRegister(Interaction);
}
}
@@ -154,4 +178,4 @@ namespace AibisDream.Framework
// 返回GameObject
public GameObject GetGameObject();
}
}
}