From 2eea496c4bc50103d3966f5b0afbac2ecd1563b6 Mon Sep 17 00:00:00 2001 From: Ding Yuntian <1491671119@qq.com> Date: Sat, 18 Jul 2026 23:59:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20=E6=94=AF=E6=8C=81=E5=9C=A8?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E9=9D=A2=E6=9D=BF=E4=B8=8A=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E6=8E=A8=E8=BF=9B=E5=AF=B9=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 AllowDialogueAdvanceOnPointer 标记组件,IsPointerOverUI 命中 带该标记的 UI 时不再阻止对话推进;同时缓存 PointerEventData 与 射线结果列表,避免每次检测分配。Play Tool 与 Screen Transition 面板挂上该组件。 --- .../Prefabs/Old/Play Tool Panel.prefab | 13 +++++++++ .../Prefabs/Screen Transition Panel.prefab | 13 +++++++++ .../AllowDialogueAdvanceOnPointer.cs | 13 +++++++++ .../AllowDialogueAdvanceOnPointer.cs.meta | 11 ++++++++ Assets/Scripts/UI/UIManager.cs | 28 ++++++++++++++----- 5 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 Assets/Scripts/UI/Components/AllowDialogueAdvanceOnPointer.cs create mode 100644 Assets/Scripts/UI/Components/AllowDialogueAdvanceOnPointer.cs.meta diff --git a/Assets/GameContent/Feature_MainUI/Prefabs/Old/Play Tool Panel.prefab b/Assets/GameContent/Feature_MainUI/Prefabs/Old/Play Tool Panel.prefab index 8584806b3..8dbf17a90 100644 --- a/Assets/GameContent/Feature_MainUI/Prefabs/Old/Play Tool Panel.prefab +++ b/Assets/GameContent/Feature_MainUI/Prefabs/Old/Play Tool Panel.prefab @@ -575,6 +575,7 @@ GameObject: - component: {fileID: 5358297362873264388} - component: {fileID: 800920753307466051} - component: {fileID: 3111013239647254375} + - component: {fileID: 4229759771866720546} m_Layer: 5 m_Name: Play Tool Panel m_TagString: Untagged @@ -630,6 +631,18 @@ MonoBehaviour: m_EditorClassIdentifier: objWidth: 700 objHeight: 550 +--- !u!114 &4229759771866720546 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7548078866038160482} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bbcc87c8e6df4cee9aeb124c57ede070, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &5111124973336394898 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/GameContent/Feature_MainUI/Prefabs/Screen Transition Panel.prefab b/Assets/GameContent/Feature_MainUI/Prefabs/Screen Transition Panel.prefab index 60f49686b..e04928f82 100644 --- a/Assets/GameContent/Feature_MainUI/Prefabs/Screen Transition Panel.prefab +++ b/Assets/GameContent/Feature_MainUI/Prefabs/Screen Transition Panel.prefab @@ -65,6 +65,7 @@ GameObject: - component: {fileID: 200101} - component: {fileID: 200102} - component: {fileID: 200103} + - component: {fileID: 200104} m_Layer: 5 m_Name: Transition Visual Root m_TagString: Untagged @@ -131,6 +132,18 @@ MonoBehaviour: m_FillOrigin: 0 m_UseSpriteMesh: 0 m_PixelsPerUnitMultiplier: 1 +--- !u!114 &200104 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 200100} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: bbcc87c8e6df4cee9aeb124c57ede070, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &300100 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/UI/Components/AllowDialogueAdvanceOnPointer.cs b/Assets/Scripts/UI/Components/AllowDialogueAdvanceOnPointer.cs new file mode 100644 index 000000000..100a5c2cb --- /dev/null +++ b/Assets/Scripts/UI/Components/AllowDialogueAdvanceOnPointer.cs @@ -0,0 +1,13 @@ +using UnityEngine; + +namespace AibisDream.UI +{ + /// + /// Marks this UI hierarchy as allowing pointer-driven dialogue advancement. + /// The UI can still receive raycasts and block interactions behind it. + /// + [DisallowMultipleComponent] + public sealed class AllowDialogueAdvanceOnPointer : MonoBehaviour + { + } +} diff --git a/Assets/Scripts/UI/Components/AllowDialogueAdvanceOnPointer.cs.meta b/Assets/Scripts/UI/Components/AllowDialogueAdvanceOnPointer.cs.meta new file mode 100644 index 000000000..f291630bf --- /dev/null +++ b/Assets/Scripts/UI/Components/AllowDialogueAdvanceOnPointer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bbcc87c8e6df4cee9aeb124c57ede070 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/UIManager.cs b/Assets/Scripts/UI/UIManager.cs index c6142ed5e..992cb530f 100644 --- a/Assets/Scripts/UI/UIManager.cs +++ b/Assets/Scripts/UI/UIManager.cs @@ -23,6 +23,9 @@ namespace AibisDream public RectTransform DialogCanvas { get; private set; } private GraphicRaycaster _raycaster; + private EventSystem _pointerEventSystem; + private PointerEventData _pointerEventData; + private readonly List _pointerRaycastResults = new(); private RecordingToolPanel _recordingToolPanel; #endregion @@ -244,19 +247,30 @@ namespace AibisDream /// public bool IsPointerOverUI(Vector2 screenPosition) { - if (EventSystem.current == null || _raycaster == null) + var eventSystem = EventSystem.current; + if (eventSystem == null || _raycaster == null) { return false; } - var eventData = new PointerEventData(EventSystem.current) + if (_pointerEventData == null || _pointerEventSystem != eventSystem) { - position = screenPosition - }; + _pointerEventSystem = eventSystem; + _pointerEventData = new PointerEventData(eventSystem); + } - var results = new List(); - _raycaster.Raycast(eventData, results); - return results.Count > 0; + _pointerEventData.Reset(); + _pointerEventData.position = screenPosition; + + _pointerRaycastResults.Clear(); + _raycaster.Raycast(_pointerEventData, _pointerRaycastResults); + if (_pointerRaycastResults.Count == 0) + { + return false; + } + + var topResult = _pointerRaycastResults[0]; + return topResult.gameObject.GetComponentInParent() == null; } ///