From 34cf55155c2b27a3a21deb8e07d7a31600076cf9 Mon Sep 17 00:00:00 2001
From: JA <1323160571@qq.com>
Date: Mon, 6 Jul 2026 00:56:32 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95=E7=82=B9?=
=?UTF-8?q?=E5=87=BB=E6=8C=89=E9=92=AE=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
unity/Assets/Scenes/Gameplay.unity | 2 +-
unity/Assets/Scenes/MainMenu.unity | 24 +++---
unity/Assets/UI/MainMenuUIController.cs | 96 ++++++++++++++----------
unity/Assets/UI/PersistentEventSystem.cs | 37 ++++-----
unity/Assets/UI/SceneLoader.cs | 43 ++---------
5 files changed, 88 insertions(+), 114 deletions(-)
diff --git a/unity/Assets/Scenes/Gameplay.unity b/unity/Assets/Scenes/Gameplay.unity
index fc2d259..680d3e1 100644
--- a/unity/Assets/Scenes/Gameplay.unity
+++ b/unity/Assets/Scenes/Gameplay.unity
@@ -371,7 +371,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
darknessMaterial: {fileID: 2100000, guid: 6dd18d2379aff3040813ab8005b1898a, type: 2}
- debugShowAll: 1
+ debugShowAll: 0
minBrightness: 0
darknessColor: {r: 0.01, g: 0.01, b: 0.02, a: 1}
lightSoftness: 1
diff --git a/unity/Assets/Scenes/MainMenu.unity b/unity/Assets/Scenes/MainMenu.unity
index 5b1ca31..ecfde39 100644
--- a/unity/Assets/Scenes/MainMenu.unity
+++ b/unity/Assets/Scenes/MainMenu.unity
@@ -885,8 +885,7 @@ Transform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
- m_Children:
- - {fileID: 897692926}
+ m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &574406657
@@ -1355,20 +1354,20 @@ RectTransform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 897692925}
- m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+ m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
- m_LocalScale: {x: 0, y: 0, z: 0}
+ m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1022684515}
- {fileID: 1048541269}
- m_Father: {fileID: 574406656}
+ m_Father: {fileID: 1036666439}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
- m_AnchoredPosition: {x: 0, y: 0}
- m_SizeDelta: {x: 0, y: 0}
- m_Pivot: {x: 0, y: 0}
+ m_AnchoredPosition: {x: 960, y: 540}
+ m_SizeDelta: {x: 1920, y: 1080}
+ m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &897692927
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -1918,10 +1917,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: dfb474cbd721479419d2ce88a2701448, type: 3}
m_Name:
m_EditorClassIdentifier:
- titleText: {fileID: 0}
- titleImage: {fileID: 63499461}
startButton: {fileID: 1036827528}
- storyReplayButton: {fileID: 977847656}
+ settingsButton: {fileID: 0}
creditsButton: {fileID: 995992462}
quitButton: {fileID: 0}
settingsPanel: {fileID: 0}
@@ -2006,6 +2003,7 @@ RectTransform:
- {fileID: 1535145891}
- {fileID: 63499463}
- {fileID: 1440709690}
+ - {fileID: 897692926}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
@@ -2344,10 +2342,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: dfb474cbd721479419d2ce88a2701448, type: 3}
m_Name:
m_EditorClassIdentifier:
- titleText: {fileID: 0}
- titleImage: {fileID: 0}
startButton: {fileID: 0}
- storyReplayButton: {fileID: 0}
+ settingsButton: {fileID: 0}
creditsButton: {fileID: 0}
quitButton: {fileID: 0}
settingsPanel: {fileID: 2013394273}
diff --git a/unity/Assets/UI/MainMenuUIController.cs b/unity/Assets/UI/MainMenuUIController.cs
index 2bce3d2..f7355fc 100644
--- a/unity/Assets/UI/MainMenuUIController.cs
+++ b/unity/Assets/UI/MainMenuUIController.cs
@@ -4,22 +4,19 @@ using UnityEngine.UI;
namespace GameFramework
{
///
- /// 主菜单 UI 控制器(游戏封面)。
- /// 包含游戏标题 + 开始游戏/剧情回放/制作人员按钮。
+ /// 主菜单 UI 控制器。
+ /// 支持开始游戏、设置、制作人员、退出游戏。
+ /// 修复:场景重载后自动重新查找 UI 引用,避免 DontDestroyOnLoad 导致的空引用问题。
///
public class MainMenuUIController : MonoBehaviour
{
- [Header("标题")]
- [SerializeField] Text titleText;
- [SerializeField] Image titleImage;
-
[Header("Buttons")]
[SerializeField] Button startButton;
- [SerializeField] Button storyReplayButton;
+ [SerializeField] Button settingsButton;
[SerializeField] Button creditsButton;
[SerializeField] Button quitButton;
- [Header("Settings Panel (placeholder)")]
+ [Header("Settings Panel")]
[SerializeField] GameObject settingsPanel;
[SerializeField] Button settingsBackButton;
@@ -29,23 +26,38 @@ namespace GameFramework
void Start()
{
- Debug.Log("[MainMenu] creditsButton=" + (creditsButton != null ? creditsButton.name : "NULL") + " creditsPanel=" + (creditsPanel != null ? creditsPanel.name : "NULL"));
+ // 自动查找(解决场景重载后引用失效问题)
+ if (startButton == null)
+ startButton = FindButton("StartButton");
+ if (settingsButton == null)
+ settingsButton = FindButton("SettingsButton");
+ if (creditsButton == null)
+ creditsButton = FindButton("CreditsButton");
+ if (quitButton == null)
+ quitButton = FindButton("QuitButton");
+
+ if (settingsPanel == null)
+ settingsPanel = GameObject.Find("SettingsPanel");
+ if (settingsBackButton == null && settingsPanel != null)
+ settingsBackButton = settingsPanel.GetComponentInChildren