feat(GazeReminder): 实现更多提示

This commit is contained in:
2025-10-26 22:13:15 +08:00
parent 1459c70279
commit e8b9f47067
12 changed files with 920 additions and 104 deletions

View File

@@ -3,6 +3,7 @@ using UnityEngine;
using Script.Gameplay.Interface;
using Script.Gameplay.Input;
using System;
using System.Collections.Generic;
using Script.Gameplay.Global;
namespace Script.Gameplay.Player
@@ -12,11 +13,34 @@ namespace Script.Gameplay.Player
[SerializeField] private FirstPersonRaycaster raycaster; // 新增:第一人称射线检测器
public bool IsEnableEditing = true; // 是否启用编辑功能
private bool isEditing = false; // 当前是否处于编辑状态
public event Action<GameObject> OnGazeEnterEditableComponent;
public event Action<GameObject> OnGazeExitEditableComponent;
public event Action<GameObject> OnBeginEditTarget;
public event Action<GameObject> OnEndEditTarget;
private GameObject previousTarget; // 上一次注视的对象(用于注视进入/离开事件)
private GameObject currentTarget; // 射线命中的当前可编辑对象(用于按键交互)
private GameObject previousGazedTarget; // 上一次注视的对象(用于注视进入/离开事件)
public GameObject CurrentTarget
{
get => currentTarget;
set
{
previousTarget = currentTarget;
currentTarget = value;
if (previousTarget != currentTarget)
{
if (currentTarget != null)
{
OnGazeEnterEditableComponent?.Invoke((currentTarget)?.gameObject);
}
if (previousTarget != null)
{
OnGazeExitEditableComponent?.Invoke((previousTarget)?.gameObject);
}
}
}
}
private InputManager inputManager;
@@ -53,23 +77,7 @@ namespace Script.Gameplay.Player
hitEditable = lookAtObj;
}
}
currentTarget = hitEditable;
// // 如果命中对象与之前注视的不一样,触发进入/离开事件
// if (hitEditable != previousGazedTarget)
// {
// if (previousGazedTarget != null)
// {
// // previousGazedTarget.OnGazeExit(this);
// }
//
// if (hitEditable != null)
// {
// // hitEditable.OnGazeEnter(this);
// }
//
// previousGazedTarget = hitEditable;
// }
CurrentTarget = hitEditable;
}
private void EditTarget()
@@ -77,7 +85,7 @@ namespace Script.Gameplay.Player
if (isEditing)
{
isEditing = false;
OnEndEditTarget?.Invoke(currentTarget);
OnEndEditTarget?.Invoke(CurrentTarget);
inputManager.SetCursorState(false, CursorLockMode.Locked);
inputManager.SetInputForLook(true);
inputManager.SetInputForMove(true);
@@ -88,10 +96,10 @@ namespace Script.Gameplay.Player
}
else
{
if (currentTarget == null) return;
if (CurrentTarget == null) return;
if (!IsEnableEditing) return;
isEditing = true;
OnBeginEditTarget?.Invoke(currentTarget);
OnBeginEditTarget?.Invoke(CurrentTarget);
inputManager.SetCursorState(true, CursorLockMode.Confined);
inputManager.SetInputForLook(false);
inputManager.SetInputForMove(false);