feat(Gaze): 实现注视相关提示
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user