feat(Cycle):实现循环提前检测,修复交互提示消失,按键绑定的事件在重启的时候没能正确,触发循环的提前检测有错误

This commit is contained in:
2025-10-27 10:31:01 +08:00
parent e8b9f47067
commit 9646483fa6
36 changed files with 6743 additions and 5221 deletions

View File

@@ -5,6 +5,7 @@ using Script.Gameplay.Connect;
using Script.Gameplay.Interface;
using Script.Gameplay.Input;
using System;
using UnityEngine.InputSystem;
namespace Script.Gameplay.Player
{
@@ -66,10 +67,10 @@ namespace Script.Gameplay.Player
void Start()
{
inputManager = InputManager.Instance;
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.SetOutput.performed += OnSetOutputOnperformed;
inputManager.Input.Player.SetInput.performed += OnSetInputOnperformed;
inputManager.Input.Player.Connect.performed += OnConnectOnperformed;
inputManager.Input.Player.CutLine.performed += OnCutLineOnperformed;
if (raycaster == null)
raycaster = GetComponent<FirstPersonRaycaster>() ?? GetComponentInChildren<FirstPersonRaycaster>();
@@ -81,6 +82,26 @@ namespace Script.Gameplay.Player
ControllerLocator.Instance.Register(this);
}
private void OnCutLineOnperformed(InputAction.CallbackContext ctx)
{
CutConnectLine(CurrentTarget);
}
private void OnConnectOnperformed(InputAction.CallbackContext ctx)
{
CreateConnection();
}
private void OnSetInputOnperformed(InputAction.CallbackContext ctx)
{
SetPointB(CurrentTarget);
}
private void OnSetOutputOnperformed(InputAction.CallbackContext ctx)
{
SetPointA(CurrentTarget);
}
void Update()
{
DetectConnectable();
@@ -147,7 +168,17 @@ namespace Script.Gameplay.Player
Debug.Log("Cannot create connection: invalid targets.");
}
}
private void OnDestroy()
{
ControllerLocator.Instance.Unregister(this);
inputManager.Input.Player.SetOutput.performed -= OnSetOutputOnperformed;
inputManager.Input.Player.SetInput.performed -= OnSetInputOnperformed;
inputManager.Input.Player.Connect.performed -= OnConnectOnperformed;
inputManager.Input.Player.CutLine.performed -= OnCutLineOnperformed;
}
void OnDrawGizmos()
{
// 射线可视化交由 FirstPersonRaycaster 处理

View File

@@ -7,6 +7,7 @@ using UnityEngine.Events;
using Script.Gameplay.Interface;
using Script.Gameplay.Input;
using UI;
using UnityEngine.InputSystem;
namespace Script.Gameplay.Player
{
@@ -60,24 +61,28 @@ namespace Script.Gameplay.Player
inputManager = InputManager.Instance;
var input = inputManager.Input;
input.Player.Read.performed += ctx =>
{
if (!isEnablePlayerDialogue) return;
if (CurrentDialogueTarget == null) return;
if (isReadingDialogue) return;
BeginDialogue();
};
input.Player.ShowNextDialogue.performed += ctx =>
{
if (!isEnablePlayerDialogue) return;
if (CurrentDialogueTarget == null) return;
if (!isReadingDialogue) return;
PassNextDialogue();
};
input.Player.Read.performed += OnReadOnperformed;
input.Player.ShowNextDialogue.performed += OnShowNextDialogueOnperformed;
ControllerLocator.Instance.Register(this);
}
private void OnShowNextDialogueOnperformed(InputAction.CallbackContext ctx)
{
if (!isEnablePlayerDialogue) return;
if (CurrentDialogueTarget == null) return;
if (!isReadingDialogue) return;
PassNextDialogue();
}
private void OnReadOnperformed(InputAction.CallbackContext ctx)
{
if (!isEnablePlayerDialogue) return;
if (CurrentDialogueTarget == null) return;
if (isReadingDialogue) return;
BeginDialogue();
}
void Update()
{
DetectDialogue();
@@ -159,5 +164,17 @@ namespace Script.Gameplay.Player
CurrentDialogueTarget = null;
}
}
private void OnDestroy()
{
ControllerLocator.Instance.Unregister<PlayerDialogueController>(this);
if (inputManager != null)
{
var input = inputManager.Input;
input.Player.Read.performed -= OnReadOnperformed;
input.Player.ShowNextDialogue.performed -= OnShowNextDialogueOnperformed;
}
}
}
}

View File

@@ -5,6 +5,7 @@ using Script.Gameplay.Input;
using System;
using System.Collections.Generic;
using Script.Gameplay.Global;
using UnityEngine.InputSystem;
namespace Script.Gameplay.Player
{
@@ -48,7 +49,7 @@ namespace Script.Gameplay.Player
void Start()
{
inputManager = InputManager.Instance;
inputManager.Input.Player.Edit.performed += context => EditTarget();
inputManager.Input.Player.Edit.performed += OnEditOnperformed;
timePauseManager = TimePauseManager.Instance;
if (raycaster == null)
raycaster = GetComponent<FirstPersonRaycaster>() ?? GetComponentInChildren<FirstPersonRaycaster>();
@@ -59,6 +60,11 @@ namespace Script.Gameplay.Player
ControllerLocator.Instance.Register(this);
}
private void OnEditOnperformed(InputAction.CallbackContext context)
{
EditTarget();
}
void Update()
{
DetectInteractable();
@@ -110,6 +116,15 @@ namespace Script.Gameplay.Player
}
}
private void OnDestroy()
{
if (inputManager != null)
{
inputManager.Input.Player.Edit.performed -= OnEditOnperformed;
}
ControllerLocator.Instance.Unregister(this);
}
void OnDrawGizmos()
{
// 交由 FirstPersonRaycaster 绘制射线

View File

@@ -3,6 +3,7 @@ using Script.Gameplay.Interface;
using System;
using Core;
using Script.Gameplay.Input;
using UnityEngine.InputSystem;
namespace Script.Gameplay.Player
{
@@ -46,16 +47,19 @@ namespace Script.Gameplay.Player
Debug.LogWarning("FirstPersonRaycaster not found! Please assign or add it to the player.");
var input = InputManager.Instance.Input;
input.Player.Interact.performed += ctx =>
{
if(CurrentTarget == null) return;
if (!CurrentTarget.IsEnableInteract) return;
CurrentTarget.Interact(this.gameObject);
};
input.Player.Interact.performed += OnInteractOnperformed;
ControllerLocator.Instance.Register(this);
}
private void OnInteractOnperformed(InputAction.CallbackContext ctx)
{
if (CurrentTarget == null) return;
if (!CurrentTarget.IsEnableInteract) return;
CurrentTarget.Interact(this.gameObject);
}
void Update()
{
DetectInteractable();
@@ -81,6 +85,14 @@ namespace Script.Gameplay.Player
}
}
private void OnDestroy()
{
ControllerLocator.Instance.Unregister<PlayerInteractorController>(this);
var input = InputManager.Instance.Input;
input.Player.Interact.performed -= OnInteractOnperformed;
}
void OnDrawGizmos()
{
// 交由 FirstPersonRaycaster 绘制射线

View File

@@ -122,8 +122,11 @@ namespace Script.Gameplay.Player
{
ControllerLocator.Instance.Unregister<PlayerWatchModeController>(this);
var input = inputManager.Input;
input.Player.SwitchWatchMode.performed -= RegisterInput;
if (inputManager != null)
{
var input = inputManager.Input;
input.Player.SwitchWatchMode.performed -= RegisterInput;
}
}
}
}