using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; namespace TON { public class UIBase : MonoBehaviour { private static EventSystem globalEventSystem; public virtual void Show() { // ๐Ÿ”น ์‹คํ–‰ ์ค‘์ธ ๋ชจ๋“  ์”ฌ์—์„œ EventSystem ํ™•์ธ (DontDestroyOnLoad ํฌํ•จ) if (globalEventSystem == null) { globalEventSystem = FindExistingEventSystem(); if (globalEventSystem == null) { // ๐Ÿ”น ์—†์œผ๋ฉด ์ƒˆ๋กœ์šด EventSystem ์ƒ์„ฑ GameObject obj = Instantiate(Resources.Load("EventSystem/Prefabs/TON.EventSystem")); globalEventSystem = obj.GetComponent(); // ๐Ÿ”น ์ƒˆ๋กœ ๋งŒ๋“  EventSystem์„ DontDestroyOnLoad๋กœ ์œ ์ง€ DontDestroyOnLoad(obj); } } gameObject.SetActive(true); } public virtual void Hide() { gameObject.SetActive(false); } private EventSystem FindExistingEventSystem() { // ๐Ÿ”น ๋ชจ๋“  ์”ฌ์„ ํฌํ•จํ•˜์—ฌ EventSystem ๊ฒ€์ƒ‰ (์”ฌ ์ด๋™ํ•ด๋„ ์œ ์ง€๋˜๋Š” ๊ฐ์ฒด ํฌํ•จ) EventSystem[] eventSystems = Resources.FindObjectsOfTypeAll(); return eventSystems.Length > 0 ? eventSystems[0] : null; } } }