fix(): 修复重启后切换模式后相机丢失BUG,修复重启后UI绑定失效的BUG,将GameManager移动到Gameplay

This commit is contained in:
2025-10-26 09:56:23 +08:00
parent 95616f8c10
commit 9094b17a3d
7 changed files with 55 additions and 367 deletions

View File

@@ -23,7 +23,7 @@ namespace Script.Gameplay.Global
private void Start()
{
_gameCountdownManager = GameCountdownManager.Instance;
_gameCountdownManager.StartLevelTimer();
GameManager.Instance.OnGameStart += OnGameStart;
_gameCountdownManager.OnFinish.AddListener(() =>
{
if (IsOpenRestartGameOnCountdownFinish)
@@ -32,11 +32,16 @@ namespace Script.Gameplay.Global
);
}
public void OnGameStart()
{
_gameCountdownManager.StartLevelTimer();
}
public IEnumerator OnCountDown()
{
StartCoroutine(ScreenGlitchManager.Instance.TriggerGlitchEffect());
yield return new WaitForSeconds(1.0f);
GameManager.Instance.ReStartGameplay();
GameManager.Instance.StartGameplay();
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using Core;
namespace Script.Gameplay.Global
{
public class GameManager : MonoSingleton<GameManager>
{
public event Action OnGameStart;
private void Start()
{
ScenesManager.Instance.LoadMainMenu();
}
public void StartGameplay()
{
ScenesManager.Instance.LoadGameplay("Level1");
OnGameStart?.Invoke();
}
public void StartTest()
{
ScenesManager.Instance.LoadGameplay("Test");
OnGameStart?.Invoke();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: db200c814b6e4465843d7ebc113fd9d0
timeCreated: 1760362855

View File

@@ -3,6 +3,7 @@ using Script.Gameplay.Input;
using UnityEngine;
using Core;
using Script.Gameplay.Global;
using UnityEngine.InputSystem;
namespace Script.Gameplay.Player
{
@@ -34,7 +35,7 @@ namespace Script.Gameplay.Player
// 触发退出事件
OnExitWatchMode?.Invoke(previousMode);
OnEnterWatchMode?.Invoke(currentMode);
SwitchWatchMode(currentMode);
}
}
@@ -47,17 +48,19 @@ namespace Script.Gameplay.Player
playerConnectController = GetComponent<PlayerConnectController>();
var input = inputManager.Input;
input.Player.SwitchWatchMode.performed += ctx =>
{
var modeTemp = (WatchMode)(((int)CurrentWatchMode + 1) % Enum.GetNames(typeof(WatchMode)).Length);
CurrentWatchMode = modeTemp;
};
;
input.Player.SwitchWatchMode.performed += RegisterInput
;
ControllerLocator.Instance.Register(this);
OnEnterWatchMode?.Invoke(currentMode);
}
private void RegisterInput(InputAction.CallbackContext ctx)
{
var modeTemp = (WatchMode)(((int)CurrentWatchMode + 1) % Enum.GetNames(typeof(WatchMode)).Length);
CurrentWatchMode = modeTemp;
}
// 实现按Tap键实现在WatchMode 3个模式切换并通过SwitchWatchMode设置正确的相机模式
private void SwitchWatchMode(WatchMode watchMode)
{
@@ -78,6 +81,7 @@ namespace Script.Gameplay.Player
{
playerConnectController.IsEnablePlayerConnecting = false;
}
break;
case WatchMode.Outside:
SetSeeLines(true);
@@ -89,7 +93,7 @@ namespace Script.Gameplay.Player
{
playerInteractorController.SetPlayerInteractionEnabled(true);
}
if (playerConnectController != null)
{
playerConnectController.IsEnablePlayerConnecting = true;
@@ -113,5 +117,13 @@ namespace Script.Gameplay.Player
cam.cullingMask = mask;
}
private void OnDestroy()
{
ControllerLocator.Instance.Unregister<PlayerWatchModeController>(this);
var input = inputManager.Input;
input.Player.SwitchWatchMode.performed -= RegisterInput;
}
}
}

View File

@@ -1,16 +1,20 @@
using UnityEngine;
using Core;
using Script.Gameplay.Input;
using Script.Gameplay.Global;
namespace UI
{
public class StartGameButton : UIBase
{
public string levelName = "Level1";
public void StartGame()
{
ScenesManager.Instance.LoadGameplay(levelName);
InputManager.Instance.SetCursorState(false,CursorLockMode.Locked);
if (levelName == "Level1")
GameManager.Instance.StartGameplay();
else if (levelName == "Test")
GameManager.Instance.StartTest();
InputManager.Instance.SetCursorState(false, CursorLockMode.Locked);
}
}
}