优化一大波

This commit is contained in:
2026-07-05 15:49:57 +08:00
parent 8485743cb7
commit 31cbb580b6
6 changed files with 47 additions and 7 deletions
+13 -2
View File
@@ -41,6 +41,8 @@ namespace GameFramework
private EchoSystem _echoSystem;
private PlayerController _playerController;
private int _maxHealth = 5;
private bool _subscribedScoreEvent = false;
private int _lastSoulCount = -1;
void Start()
{
@@ -64,6 +66,7 @@ namespace GameFramework
if (ScoreManager.Instance != null)
{
ScoreManager.onScoreChanged += UpdateSoulCount;
_subscribedScoreEvent = true;
UpdateSoulCount(ScoreManager.Instance.CurrentScore);
}
@@ -79,7 +82,11 @@ namespace GameFramework
void OnDestroy()
{
ScoreManager.onScoreChanged -= UpdateSoulCount;
if (_subscribedScoreEvent)
{
ScoreManager.onScoreChanged -= UpdateSoulCount;
_subscribedScoreEvent = false;
}
}
void Update()
@@ -96,7 +103,11 @@ namespace GameFramework
if (soulCountText != null)
{
soulCountText.text = count.ToString();
Debug.Log($"[GameHUD] UpdateSoulCount: {count}");
if (count != _lastSoulCount)
{
Debug.Log($"[GameHUD] UpdateSoulCount: {count}");
_lastSoulCount = count;
}
}
else
{
+5 -2
View File
@@ -21,8 +21,8 @@ namespace GameFramework
public static GameState GameState
{
get => Instance.gameState;
set => Instance.gameState = value;
get => Instance != null ? Instance.gameState : GameState.Playing;
set { if (Instance != null) Instance.gameState = value; }
}
[SerializeField] private GameState gameState = GameState.Playing;
@@ -68,6 +68,9 @@ namespace GameFramework
/// </summary>
private IEnumerator DeathTransition()
{
// 确保从暂停状态恢复(玩家可能在暂停时死亡)
Time.timeScale = 1f;
// 等待一帧,让 HUD 先更新血量显示
yield return null;
+10
View File
@@ -95,5 +95,15 @@ namespace GameFramework
Application.Quit();
#endif
}
void OnDestroy()
{
if (startButton != null) startButton.onClick.RemoveAllListeners();
if (storyReplayButton != null) storyReplayButton.onClick.RemoveAllListeners();
if (creditsButton != null) creditsButton.onClick.RemoveAllListeners();
if (quitButton != null) quitButton.onClick.RemoveAllListeners();
if (settingsBackButton != null) settingsBackButton.onClick.RemoveAllListeners();
if (creditsCloseButton != null) creditsCloseButton.onClick.RemoveAllListeners();
}
}
}
+17 -1
View File
@@ -27,7 +27,23 @@ namespace GameFramework
private Color color;
private bool isLoading = false;
public void LoadGameplayScene() => Load(gameplayScene);
public void LoadGameplayScene()
{
// 重置 GameManager 状态
if (GameManager.Instance != null)
{
GameManager.GameState = GameState.Playing;
GameManager.onGameOver = null;
GameManager.onGameWin = null;
}
// 重置 ScoreManager
if (ScoreManager.Instance != null)
ScoreManager.Instance.ResetScore();
// 清理静态事件残留订阅
IndianOceanAssets.Engine2_5D.HealthSystem.onPlayerDamaged = null;
Load(gameplayScene);
}
public void LoadMainMenuScene() => Load(mainMenuScene);
public void LoadScoringScene() => Load(scoringScene);
public void Load(string sceneName)