修复UI系统BUG

This commit is contained in:
JA
2026-07-01 02:03:14 +08:00
parent 7f8576d2a6
commit cf9f694615
8 changed files with 170 additions and 20 deletions
+32
View File
@@ -0,0 +1,32 @@
using UnityEngine;
using UnityEngine.EventSystems;
namespace GameFramework
{
/// <summary>
/// 挂到 MainMenu 场景的 EventSystem 上(或和它同一个空物体上),
/// 让 EventSystem 通过 DontDestroyOnLoad 跨场景存活。
/// 这样 Gameplay、Scoring 等场景的按钮都能正常响应点击。
///
/// 如果场景里没有 EventSystem,也可以挂到任意空物体上,
/// 脚本会自动创建一个。
/// </summary>
public class PersistentEventSystem : MonoBehaviour
{
void Awake()
{
// 如果场景里没有 EventSystem,自动创建
if (FindObjectOfType<EventSystem>() == null)
{
var go = new GameObject("EventSystem");
go.AddComponent<EventSystem>();
go.AddComponent<StandaloneInputModule>();
}
// 让 EventSystem 跨场景存活
var eventSystem = FindObjectOfType<EventSystem>();
if (eventSystem != null)
DontDestroyOnLoad(eventSystem.gameObject);
}
}
}