diff --git a/unity/Assets/UI/MainMenuUIController.cs b/unity/Assets/UI/MainMenuUIController.cs index 64a00bf..e0eb7a9 100644 --- a/unity/Assets/UI/MainMenuUIController.cs +++ b/unity/Assets/UI/MainMenuUIController.cs @@ -1,5 +1,6 @@ using UnityEngine; using UnityEngine.UI; +using UnityEngine.EventSystems; namespace GameFramework { @@ -7,6 +8,7 @@ namespace GameFramework /// 主菜单 UI 控制器。 /// 支持开始游戏、设置、制作人员、退出游戏。 /// 修复:场景重载后自动重新查找 UI 引用,避免 DontDestroyOnLoad 导致的空引用问题。 + /// 修复:返回主菜单后按钮全部失效(EventSystem/InputModule 状态异常)时主动兜底。 /// public class MainMenuUIController : MonoBehaviour { @@ -34,6 +36,8 @@ namespace GameFramework void Start() { + EnsureEventSystem(); + // 自动查找(解决场景重载后引用失效问题) if (startButton == null) startButton = FindButton("StartButton"); @@ -74,18 +78,47 @@ namespace GameFramework // 绑定按钮事件 if (startButton != null) + { startButton.onClick.AddListener(OnStartClick); + Debug.Log($"[MainMenu] 已绑定 startButton = {startButton.name}"); + } + else + { + Debug.LogError("[MainMenu] startButton 未找到!开始游戏按钮将不可点。"); + } + if (settingsButton != null) + { settingsButton.onClick.AddListener(OnSettingsClick); + Debug.Log($"[MainMenu] 已绑定 settingsButton = {settingsButton.name}"); + } + if (creditsButton != null) + { creditsButton.onClick.AddListener(OnCreditsClick); + Debug.Log($"[MainMenu] 已绑定 creditsButton = {creditsButton.name}"); + } + else + { + Debug.LogError("[MainMenu] creditsButton 未找到!制作人员按钮将不可点。"); + } + if (quitButton != null) + { quitButton.onClick.AddListener(OnQuitClick); + Debug.Log($"[MainMenu] 已绑定 quitButton = {quitButton.name}"); + } + if (storyReplayButton != null) { // 避免 Inspector 中已绑定的事件导致重复触发 storyReplayButton.onClick.RemoveAllListeners(); storyReplayButton.onClick.AddListener(OnStoryReplayClick); + Debug.Log($"[MainMenu] 已绑定 storyReplayButton = {storyReplayButton.name}"); + } + else + { + Debug.LogError("[MainMenu] storyReplayButton 未找到!剧情播放按钮将不可点。"); } if (settingsBackButton != null) @@ -111,8 +144,56 @@ namespace GameFramework return btn != null ? btn.GetComponent