feat(): 完成将Manager从Gameplay转移到Core,实现循环次数持久化,实现设置面板

This commit is contained in:
2025-10-26 09:32:28 +08:00
parent c1f7418ffa
commit 95616f8c10
20 changed files with 6630 additions and 5767 deletions

View File

@@ -0,0 +1,27 @@
using Core;
using Script.Gameplay.Input;
using UnityEngine;
namespace Script.Gameplay.Global
{
public class GameDataManager : MonoSingleton<GameDataManager>
{
private const string LoopCountKey = "TotalLoopCount";
public int TotalLoopCount { get; private set; }
private void Start()
{
GameManager.Instance.OnGameStart += AddLoop;
// 读取已保存的循环次数
TotalLoopCount = PlayerPrefs.GetInt(LoopCountKey, 0);
Debug.Log("目前循环次数:" + TotalLoopCount);
}
public void AddLoop()
{
TotalLoopCount++;
PlayerPrefs.SetInt(LoopCountKey, TotalLoopCount);
PlayerPrefs.Save();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a768588a5a1e4d7f8d54f8d16b0f4bb0
timeCreated: 1761362127

View File

@@ -19,23 +19,24 @@ namespace Script.Gameplay.Global
public class GameFlowManager : MonoSingleton<GameFlowManager>
{
public bool IsOpenRestartGameOnCountdownFinish = true;
private GameCountdownManager _gameCountdownManager;
private void Start()
{
GameCountdownManager.Instance.StartLevelTimer();
GameCountdownManager.Instance.OnFinish.AddListener(() =>
_gameCountdownManager = GameCountdownManager.Instance;
_gameCountdownManager.StartLevelTimer();
_gameCountdownManager.OnFinish.AddListener(() =>
{
if (IsOpenRestartGameOnCountdownFinish)
StartCoroutine(RestartGame());
StartCoroutine(OnCountDown());
}
);
}
public IEnumerator RestartGame()
public IEnumerator OnCountDown()
{
StartCoroutine(ScreenGlitchManager.Instance.TriggerGlitchEffect());
yield return new WaitForSeconds(1.0f);
GameManager.Instance.ReStartGame();
GameManager.Instance.ReStartGameplay();
}
}
}

View File

@@ -57,10 +57,6 @@ namespace Script.Gameplay.Input
Input.Player.Edit.performed += ctx => EditPressed = true;
Input.Player.Edit.canceled += ctx => EditPressed = false;
SetCursorState(false, CursorLockMode.Locked);
SetInputForLook(true);
SetInputForMove(true);
UIManager.Instance.RegisterInputManager(this);
}
@@ -118,13 +114,13 @@ namespace Script.Gameplay.Input
{
_hasFocus = hasFocus;
// 失去焦点视为系统级暂停
if (_hasFocus)
if (_hasFocus && ScenesManager.Instance.IsInGameplay)
{
SetCursorState(_hasFocus, CursorLockMode.Locked);
SetCursorState(false, CursorLockMode.Locked);
}
else
{
SetCursorState(_hasFocus, CursorLockMode.None);
SetCursorState(true, CursorLockMode.None);
}
}
}

View File

@@ -145,6 +145,15 @@ namespace Script.Gameplay.Input
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
},
{
""name"": ""Setting"",
""type"": ""Button"",
""id"": ""0e4b0859-2f31-413a-a14c-87333e2f63b4"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
}
],
""bindings"": [
@@ -334,6 +343,17 @@ namespace Script.Gameplay.Input
""action"": ""Read"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""257ce27b-6b51-4716-8b94-abbe05c2eaf9"",
""path"": ""<Keyboard>/escape"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Setting"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
}
@@ -355,6 +375,7 @@ namespace Script.Gameplay.Input
m_Player_CutLine = m_Player.FindAction("CutLine", throwIfNotFound: true);
m_Player_ShowNextDialogue = m_Player.FindAction("ShowNextDialogue", throwIfNotFound: true);
m_Player_Read = m_Player.FindAction("Read", throwIfNotFound: true);
m_Player_Setting = m_Player.FindAction("Setting", throwIfNotFound: true);
}
~@PlayerInputActions()
@@ -434,6 +455,7 @@ namespace Script.Gameplay.Input
private readonly InputAction m_Player_CutLine;
private readonly InputAction m_Player_ShowNextDialogue;
private readonly InputAction m_Player_Read;
private readonly InputAction m_Player_Setting;
public struct PlayerActions
{
private @PlayerInputActions m_Wrapper;
@@ -451,6 +473,7 @@ namespace Script.Gameplay.Input
public InputAction @CutLine => m_Wrapper.m_Player_CutLine;
public InputAction @ShowNextDialogue => m_Wrapper.m_Player_ShowNextDialogue;
public InputAction @Read => m_Wrapper.m_Player_Read;
public InputAction @Setting => m_Wrapper.m_Player_Setting;
public InputActionMap Get() { return m_Wrapper.m_Player; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
@@ -499,6 +522,9 @@ namespace Script.Gameplay.Input
@Read.started += instance.OnRead;
@Read.performed += instance.OnRead;
@Read.canceled += instance.OnRead;
@Setting.started += instance.OnSetting;
@Setting.performed += instance.OnSetting;
@Setting.canceled += instance.OnSetting;
}
private void UnregisterCallbacks(IPlayerActions instance)
@@ -542,6 +568,9 @@ namespace Script.Gameplay.Input
@Read.started -= instance.OnRead;
@Read.performed -= instance.OnRead;
@Read.canceled -= instance.OnRead;
@Setting.started -= instance.OnSetting;
@Setting.performed -= instance.OnSetting;
@Setting.canceled -= instance.OnSetting;
}
public void RemoveCallbacks(IPlayerActions instance)
@@ -574,6 +603,7 @@ namespace Script.Gameplay.Input
void OnCutLine(InputAction.CallbackContext context);
void OnShowNextDialogue(InputAction.CallbackContext context);
void OnRead(InputAction.CallbackContext context);
void OnSetting(InputAction.CallbackContext context);
}
}
}

View File

@@ -41,7 +41,7 @@ namespace Script.Gameplay.Player
private void Start()
{
OnDeath += () => StartCoroutine(GameFlowManager.Instance.RestartGame());
OnDeath += () => StartCoroutine(GameFlowManager.Instance.OnCountDown());
}
public void TakeDamage(int damage)

View File

@@ -0,0 +1,48 @@
using System;
using Core;
using Script.Gameplay.Global;
using TMPro;
using UnityEngine;
using Script.Gameplay.Input;
namespace UI
{
public class SettingViewer : UIBase
{
[SerializeField] private TMP_Text TitleText;
[SerializeField] private TMP_Text ContentText;
private InputManager inputManager;
protected override void Awake()
{
base.Awake();
inputManager = InputManager.Instance;
inputManager.Input.Player.Setting.performed+= ctx =>
{
if (!isActiveAndEnabled)
{
Show();
inputManager.SetInputForLook(false);
inputManager.SetInputForMove(false);
}
else
{
Hide();
inputManager.SetInputForLook(true);
inputManager.SetInputForMove(true);
}
};
}
public override void Show()
{
base.Show();
ContentText.text = "循环次数:" + GameDataManager.Instance.TotalLoopCount.ToString();
}
public override void Hide()
{
base.Hide();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4eeaf53256494a5a938c5a3497039772
timeCreated: 1761363001

View File

@@ -1,5 +1,7 @@
using UnityEngine;
using Core;
using Script.Gameplay.Input;
namespace UI
{
public class StartGameButton : UIBase
@@ -8,6 +10,7 @@ namespace UI
public void StartGame()
{
ScenesManager.Instance.LoadGameplay(levelName);
InputManager.Instance.SetCursorState(false,CursorLockMode.Locked);
}
}
}