feat(Gaze): 实现注视相关提示

This commit is contained in:
2025-10-21 13:07:48 +08:00
parent 4737220e42
commit d3eed0945c
7 changed files with 5827 additions and 5103 deletions

View File

@@ -1,6 +1,7 @@
using UnityEngine;
using Script.Gameplay.Interface;
using System;
using Core;
using Script.Gameplay.Input;
namespace Script.Gameplay.Player
@@ -10,8 +11,29 @@ namespace Script.Gameplay.Player
[SerializeField] private FirstPersonRaycaster raycaster; // 新增:第一人称射线检测器
[SerializeField] private bool isEnablePlayerInteraction = true; // 是否启用玩家交互功能
private IInteractable currentTarget; // 被射线命中的当前可交互对象(用于按键交互)
private IInteractable currentTarget;
private IInteractable CurrentTarget
{
get => currentTarget;
set
{
currentTarget = value;
if (currentTarget != null)
{
// 可以在这里添加一些逻辑比如显示交互提示UI
OnGazeEnter?.Invoke(this.gameObject);
}
else
{
// 可以在这里隐藏交互提示UI
OnGazeExit?.Invoke(this.gameObject);
}
}
} // 被射线命中的当前可交互对象(用于按键交互)
private IInteractable previousGazedTarget; // 上一次注视的对象(用于注视进入/离开事件)
public event Action<GameObject> OnGazeEnter;
public event Action<GameObject> OnGazeExit;
void Start()
{
@@ -25,11 +47,13 @@ namespace Script.Gameplay.Player
var input = InputManager.Instance.Input;
input.Player.Interact.performed += ctx =>
{
if (currentTarget != null)
if (CurrentTarget != null)
{
currentTarget.Interact(this.gameObject);
CurrentTarget.Interact(this.gameObject);
}
};
ControllerLocator.Instance.Register(this);
}
void Update()
@@ -63,7 +87,7 @@ namespace Script.Gameplay.Player
previousGazedTarget = hitInteractable;
}
currentTarget = hitInteractable;
CurrentTarget = hitInteractable;
}
public void SetPlayerInteractionEnabled(bool isEnabled)
@@ -73,7 +97,7 @@ namespace Script.Gameplay.Player
{
previousGazedTarget.OnGazeExit(this.gameObject);
previousGazedTarget = null;
currentTarget = null;
CurrentTarget = null;
}
}