feat(Dialogue): 实现基本的对话系统
This commit is contained in:
@@ -11,27 +11,28 @@ namespace Script.Gameplay.Player
|
||||
[SerializeField] private FirstPersonRaycaster raycaster; // 新增:第一人称射线检测器
|
||||
[SerializeField] private bool isEnablePlayerInteraction = true; // 是否启用玩家交互功能
|
||||
|
||||
private IInteractable previousTarget;
|
||||
private IInteractable currentTarget;
|
||||
private IInteractable CurrentTarget
|
||||
{
|
||||
get => currentTarget;
|
||||
set
|
||||
{
|
||||
previousTarget = currentTarget;
|
||||
currentTarget = value;
|
||||
if (currentTarget != null)
|
||||
if (previousTarget != currentTarget)
|
||||
{
|
||||
// 可以在这里添加一些逻辑,比如显示交互提示UI
|
||||
OnGazeEnter?.Invoke(this.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 可以在这里隐藏交互提示UI
|
||||
OnGazeExit?.Invoke(this.gameObject);
|
||||
if (currentTarget != null)
|
||||
{
|
||||
OnGazeEnter?.Invoke((currentTarget as MonoBehaviour)?.gameObject);
|
||||
}
|
||||
if (previousTarget != null)
|
||||
{
|
||||
OnGazeExit?.Invoke((previousTarget as MonoBehaviour)?.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // 被射线命中的当前可交互对象(用于按键交互)
|
||||
private IInteractable previousGazedTarget; // 上一次注视的对象(用于注视进入/离开事件)
|
||||
|
||||
public event Action<GameObject> OnGazeEnter;
|
||||
public event Action<GameObject> OnGazeExit;
|
||||
|
||||
@@ -68,34 +69,14 @@ namespace Script.Gameplay.Player
|
||||
GameObject lookAtObj = raycaster.CurrentLookAtObject;
|
||||
IInteractable hitInteractable = lookAtObj != null ? lookAtObj.GetComponent<IInteractable>() : null;
|
||||
|
||||
// 如果命中对象与之前注视的不一样,触发进入/离开事件
|
||||
if (hitInteractable != previousGazedTarget)
|
||||
{
|
||||
// if (previousGazedTarget != null)
|
||||
// {
|
||||
// previousGazedTarget.OnGazeExit(this.gameObject);
|
||||
// }
|
||||
//
|
||||
// if (hitInteractable != null)
|
||||
// {
|
||||
// hitInteractable.OnGazeEnter(this.gameObject);
|
||||
// // 这里可以显示交互提示UI,例如 “E - 开门”
|
||||
// //Debug.Log(hitInteractable.GetInteractPrompt());
|
||||
// }
|
||||
|
||||
previousGazedTarget = hitInteractable;
|
||||
}
|
||||
|
||||
CurrentTarget = hitInteractable;
|
||||
}
|
||||
|
||||
public void SetPlayerInteractionEnabled(bool isEnabled)
|
||||
{
|
||||
isEnablePlayerInteraction = isEnabled;
|
||||
if (!isEnabled && previousGazedTarget != null)
|
||||
if (!isEnabled)
|
||||
{
|
||||
// previousGazedTarget.OnGazeExit(this.gameObject);
|
||||
previousGazedTarget = null;
|
||||
CurrentTarget = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user