diff --git a/unity/Assets/UI/GameHUD.cs b/unity/Assets/UI/GameHUD.cs index 68adf53..1416955 100644 --- a/unity/Assets/UI/GameHUD.cs +++ b/unity/Assets/UI/GameHUD.cs @@ -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 { diff --git a/unity/Assets/UI/GameManager.cs b/unity/Assets/UI/GameManager.cs index de39a66..fce6220 100644 --- a/unity/Assets/UI/GameManager.cs +++ b/unity/Assets/UI/GameManager.cs @@ -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 /// private IEnumerator DeathTransition() { + // 确保从暂停状态恢复(玩家可能在暂停时死亡) + Time.timeScale = 1f; + // 等待一帧,让 HUD 先更新血量显示 yield return null; diff --git a/unity/Assets/UI/MainMenuUIController.cs b/unity/Assets/UI/MainMenuUIController.cs index 2365c4b..2bce3d2 100644 --- a/unity/Assets/UI/MainMenuUIController.cs +++ b/unity/Assets/UI/MainMenuUIController.cs @@ -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(); + } } } diff --git a/unity/Assets/UI/SceneLoader.cs b/unity/Assets/UI/SceneLoader.cs index b99594e..4445861 100644 --- a/unity/Assets/UI/SceneLoader.cs +++ b/unity/Assets/UI/SceneLoader.cs @@ -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) diff --git a/unity/Assets/eco/Prefabs/SpiritLantern.prefab b/unity/Assets/eco/Prefabs/SpiritLantern.prefab index a3afcff..b981830 100644 --- a/unity/Assets/eco/Prefabs/SpiritLantern.prefab +++ b/unity/Assets/eco/Prefabs/SpiritLantern.prefab @@ -125,7 +125,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: lifetime: 10 - damageOnContact: 1 + damageOnContact: 3 fadeOutDuration: 2 soulDropPrefab: {fileID: 1000000000000001, guid: 5d3fc7696ceb3a24d9234355fee1c344, type: 3} --- !u!135 &8338025974414621740 diff --git a/unity/Assets/eco/SpiritLantern.cs b/unity/Assets/eco/SpiritLantern.cs index c3df13d..1318f48 100644 --- a/unity/Assets/eco/SpiritLantern.cs +++ b/unity/Assets/eco/SpiritLantern.cs @@ -24,7 +24,7 @@ namespace IndianOceanAssets.Engine2_5D [Header("伤害")] [Tooltip("怪物碰触灵灯时受到的伤害")] - [SerializeField] private int damageOnContact = 1; + [SerializeField] private int damageOnContact = 3; [Header("渐隐")] [Tooltip("碰触后灵灯渐隐消失的时间(秒)")]