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

@@ -9,11 +9,44 @@ namespace Script.Gameplay.Player
{
public class PlayerConnectController : MonoBehaviour
{
public bool IsEnableConnecting = true; // 是否启用连接功能
private bool isEnableConnecting = false;
public bool IsEnableConnecting
{
get => isEnableConnecting;
set
{
isEnableConnecting = value;
if (isEnableConnecting == false)
{
// 重置当前目标
CurrentTarget = null;
previousGazedTarget = null;
outTarget = null;
inputTarget = null;
}
}
} // 是否启用连接功能
[SerializeField] private FirstPersonRaycaster raycaster; // 第一人称射线检测器
[SerializeField] private float maxConnectDistance = 10f; // 最大连接距离
private IConnectable currentTarget; // 当前注视的可连接对象
private IConnectable currentTarget;
public IConnectable CurrentTarget
{
get => currentTarget;
set
{
if (value != null)
{
currentTarget = value;
OnGazeEnter?.Invoke(currentTarget.GetGameObject());
}
else
{
OnGazeExit?.Invoke(null);
}
}
} // 当前注视的可连接对象
private IConnectable previousGazedTarget; // 上一次注视的 IConnectable用于触发进入/离开)
private InputManager inputManager;
@@ -21,14 +54,16 @@ namespace Script.Gameplay.Player
private IConnectable inputTarget;
public event Action<IConnectable> OnSetPointA;
public event Action<IConnectable> OnSetPointB;
public event Action<GameObject> OnGazeEnter;
public event Action<GameObject> OnGazeExit;
void Start()
{
inputManager = InputManager.Instance;
inputManager.Input.Player.SetOutput.performed += ctx => SetPointA(currentTarget);
inputManager.Input.Player.SetInput.performed += ctx => SetPointB(currentTarget);
inputManager.Input.Player.SetOutput.performed += ctx => SetPointA(CurrentTarget);
inputManager.Input.Player.SetInput.performed += ctx => SetPointB(CurrentTarget);
inputManager.Input.Player.Connect.performed += ctx => CreateConnection();
inputManager.Input.Player.CutLine.performed += ctx => CutConnectLine(currentTarget);
inputManager.Input.Player.CutLine.performed += ctx => CutConnectLine(CurrentTarget);
if (raycaster == null)
raycaster = GetComponent<FirstPersonRaycaster>() ?? GetComponentInChildren<FirstPersonRaycaster>();
@@ -48,6 +83,7 @@ namespace Script.Gameplay.Player
void DetectConnectable()
{
if (raycaster == null) return;
if(!IsEnableConnecting) return;
GameObject lookAtObj = raycaster.CurrentLookAtObject;
IConnectable hitConnectable = lookAtObj != null ? lookAtObj.GetComponent<IConnectable>() : null;
@@ -68,13 +104,13 @@ namespace Script.Gameplay.Player
previousGazedTarget = hitConnectable;
}
currentTarget = hitConnectable;
CurrentTarget = hitConnectable;
}
public IConnectable GetCurrentTarget()
{
return currentTarget;
return CurrentTarget;
}
public void SetPointA(IConnectable target)