게임 진입 지점 UI 추가

This commit is contained in:
aube.lee
2025-01-28 22:13:31 +09:00
parent fa08e676e5
commit 61199eac78
3 changed files with 24 additions and 75 deletions

View File

@@ -1,19 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
namespace TON
{
public class UIBase : MonoBehaviour
{
public Object eventSystem;
private static EventSystem globalEventSystem;
public virtual void Show()
{
// eventSystem이 현재 씬에 존재하지 않는 경우
if (eventSystem == null)
// 🔹 실행 중인 모든 씬에서 EventSystem 확인 (DontDestroyOnLoad 포함)
if (globalEventSystem == null)
{
// UI EventSystem 정상 동작 되도록 GameObject Load
eventSystem = Instantiate(Resources.Load("EventSystem/Prefabs/TON.EventSystem"));
globalEventSystem = FindExistingEventSystem();
if (globalEventSystem == null)
{
// 🔹 없으면 새로운 EventSystem 생성
GameObject obj = Instantiate(Resources.Load<GameObject>("EventSystem/Prefabs/TON.EventSystem"));
globalEventSystem = obj.GetComponent<EventSystem>();
// 🔹 새로 만든 EventSystem을 DontDestroyOnLoad로 유지
DontDestroyOnLoad(obj);
}
}
gameObject.SetActive(true);
@@ -23,5 +33,12 @@ namespace TON
{
gameObject.SetActive(false);
}
private EventSystem FindExistingEventSystem()
{
// 🔹 모든 씬을 포함하여 EventSystem 검색 (씬 이동해도 유지되는 객체 포함)
EventSystem[] eventSystems = Resources.FindObjectsOfTypeAll<EventSystem>();
return eventSystems.Length > 0 ? eventSystems[0] : null;
}
}
}