fix(): 修复重启后切换模式后相机丢失BUG,修复重启后UI绑定失效的BUG,将GameManager移动到Gameplay
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Assets/Script/Gameplay/Global/GameManager.cs
Normal file
26
Assets/Script/Gameplay/Global/GameManager.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Script/Gameplay/Global/GameManager.cs.meta
Normal file
3
Assets/Script/Gameplay/Global/GameManager.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db200c814b6e4465843d7ebc113fd9d0
|
||||
timeCreated: 1760362855
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user