feat(ui): 支持在指定面板上点击推进对话
新增 AllowDialogueAdvanceOnPointer 标记组件,IsPointerOverUI 命中 带该标记的 UI 时不再阻止对话推进;同时缓存 PointerEventData 与 射线结果列表,避免每次检测分配。Play Tool 与 Screen Transition 面板挂上该组件。
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// Marks this UI hierarchy as allowing pointer-driven dialogue advancement.
|
||||
/// The UI can still receive raycasts and block interactions behind it.
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
public sealed class AllowDialogueAdvanceOnPointer : MonoBehaviour
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bbcc87c8e6df4cee9aeb124c57ede070
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -23,6 +23,9 @@ namespace AibisDream
|
||||
public RectTransform DialogCanvas { get; private set; }
|
||||
|
||||
private GraphicRaycaster _raycaster;
|
||||
private EventSystem _pointerEventSystem;
|
||||
private PointerEventData _pointerEventData;
|
||||
private readonly List<RaycastResult> _pointerRaycastResults = new();
|
||||
private RecordingToolPanel _recordingToolPanel;
|
||||
|
||||
#endregion
|
||||
@@ -244,19 +247,30 @@ namespace AibisDream
|
||||
/// </summary>
|
||||
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<RaycastResult>();
|
||||
_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<AllowDialogueAdvanceOnPointer>() == null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user