refactor(UI):完善对于各个界面的管理逻辑,esc可以直接关闭所有的顶层UI

This commit is contained in:
2025-10-27 21:41:25 +08:00
parent 1462f4689e
commit 4951f25187
21 changed files with 18049 additions and 6374 deletions

View File

@@ -20,14 +20,15 @@ namespace Script.Gameplay.Player
public event Action OnPlayerEndDialogue;
public event Action<GameObject> OnGazeEnterDialogue;
public event Action<GameObject> OnGazeExitDialogue;
private InputManager inputManager;
private Queue<string> dialogueQueue = new Queue<string>();
private PlayerDialogueViewer playerDialogueViewer;
private IDialogue previousDialogue;
private IDialogue currentDialogueTarget;
public IDialogue CurrentDialogueTarget
{
get => currentDialogueTarget;
@@ -41,6 +42,7 @@ namespace Script.Gameplay.Player
{
OnGazeEnterDialogue?.Invoke((currentDialogueTarget as MonoBehaviour)?.gameObject);
}
if (previousDialogue != null)
{
OnGazeExitDialogue?.Invoke((previousDialogue as MonoBehaviour)?.gameObject);
@@ -63,10 +65,16 @@ namespace Script.Gameplay.Player
var input = inputManager.Input;
input.Player.Read.performed += OnReadOnperformed;
input.Player.ShowNextDialogue.performed += OnShowNextDialogueOnperformed;
input.Player.Escape.performed += OnEscapeOnperformed;
ControllerLocator.Instance.Register(this);
}
private void OnEscapeOnperformed(InputAction.CallbackContext ctx)
{
EndDialogue();
}
private void OnShowNextDialogueOnperformed(InputAction.CallbackContext ctx)
{
if (!isEnablePlayerDialogue) return;
@@ -104,8 +112,6 @@ namespace Script.Gameplay.Player
OnPlayerBeginDialogue?.Invoke();
CurrentDialogueTarget.OnBeginDialogue?.Invoke(true);
dialogueQueue = SplitDialogue(CurrentDialogueTarget.DialogueContent);
inputManager.SetInputForLook(false);
inputManager.SetInputForMove(false);
PassNextDialogue();
}
}
@@ -135,13 +141,7 @@ namespace Script.Gameplay.Player
isReadingDialogue = false;
OnPlayerEndDialogue?.Invoke();
CurrentDialogueTarget.OnEndDialogue?.Invoke(true);
inputManager.SetInputForLook(true);
inputManager.SetInputForMove(true);
if (playerDialogueViewer != null)
{
playerDialogueViewer.ClosePanel();
}
// 可扩展隐藏UI、恢复输入等
UIManager.Instance.CloseUI<PlayerDialogueViewer>();
}
}
@@ -174,6 +174,7 @@ namespace Script.Gameplay.Player
var input = inputManager.Input;
input.Player.Read.performed -= OnReadOnperformed;
input.Player.ShowNextDialogue.performed -= OnShowNextDialogueOnperformed;
input.Player.Escape.performed -= OnEscapeOnperformed;
}
}
}

View File

@@ -50,6 +50,7 @@ namespace Script.Gameplay.Player
{
inputManager = InputManager.Instance;
inputManager.Input.Player.Edit.performed += OnEditOnperformed;
inputManager.Input.Player.Escape.performed += OnEscapeOnperformed;
timePauseManager = TimePauseManager.Instance;
if (raycaster == null)
raycaster = GetComponent<FirstPersonRaycaster>() ?? GetComponentInChildren<FirstPersonRaycaster>();
@@ -62,7 +63,19 @@ namespace Script.Gameplay.Player
private void OnEditOnperformed(InputAction.CallbackContext context)
{
EditTarget();
if (!isEditing)
{
BeginEdit();
}
else
{
EndEdit();
}
}
private void OnEscapeOnperformed(InputAction.CallbackContext context)
{
EndEdit();
}
void Update()
@@ -85,34 +98,28 @@ namespace Script.Gameplay.Player
}
CurrentTarget = hitEditable;
}
private void EditTarget()
private void BeginEdit()
{
if (isEditing)
if (CurrentTarget == null) return;
if (!IsEnableEditing) return;
if(isEditing) return;
isEditing = true;
OnBeginEditTarget?.Invoke(CurrentTarget);
if (timePauseManager != null)
{
isEditing = false;
OnEndEditTarget?.Invoke(CurrentTarget);
inputManager.SetCursorState(false, CursorLockMode.Locked);
inputManager.SetInputForLook(true);
inputManager.SetInputForMove(true);
if (timePauseManager != null)
{
timePauseManager.SetPaused(false);
}
timePauseManager.SetPaused(true);
}
else
}
private void EndEdit()
{
if (!isEditing) return;
isEditing = false;
OnEndEditTarget?.Invoke(CurrentTarget);
if (timePauseManager != null)
{
if (CurrentTarget == null) return;
if (!IsEnableEditing) return;
isEditing = true;
OnBeginEditTarget?.Invoke(CurrentTarget);
inputManager.SetCursorState(true, CursorLockMode.Confined);
inputManager.SetInputForLook(false);
inputManager.SetInputForMove(false);
if (timePauseManager != null)
{
timePauseManager.SetPaused(true);
}
timePauseManager.SetPaused(false);
}
}
@@ -121,6 +128,7 @@ namespace Script.Gameplay.Player
if (inputManager != null)
{
inputManager.Input.Player.Edit.performed -= OnEditOnperformed;
inputManager.Input.Player.Escape.performed -= OnEscapeOnperformed;
}
ControllerLocator.Instance.Unregister(this);
}

View File

@@ -24,7 +24,7 @@ namespace Script.Gameplay.Player
private CharacterController characterController;
private Vector3 velocity;
private bool isGrounded;
private IInputManager inputManager;
private InputManager inputManager;
private float lastGroundY;
private bool wasGroundedLastFrame;