修复UI系统BUG
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user