// ───────────────────────────────────────────────────────────────────────────── // WLEventSystemDedup.cs — EventSystem 이 2개 이상 켜지면 1개만 남긴다 (2026-10-12 · PD 「게임 실행 시 왜 자꾸 에러 메시지가」) // // 실측(2026-10-12 Play): 섬 진입 뒤 `InGame` 씬의 EventSystem + 가산 로드된 FarmingIsland `Level01` 씬의 EventSystem 이 // 동시에 켜져 「There are 2 event systems in the scene」 경고가 매 프레임(36 s 동안 1894건) 쌓였다. 장비 화면과 무관(열기 전에도 2개). // 씬이 로드될 때마다 켜진 EventSystem 을 세어, EventSystem.current(없으면 먼저 켜진 것) 하나만 두고 나머지 컴포넌트를 끈다. // UI 입력은 EventSystem 1개가 모든 캔버스를 처리하므로 기능 영향 없음. 원본·섬 코드 수정 0(새 파일 1개). // ───────────────────────────────────────────────────────────────────────────── using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.SceneManagement; namespace WL.UI { public static class WLEventSystemDedup { public static int Disabled { get; private set; } public static string LastLog { get; private set; } = ""; [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)] static void Boot() { SceneManager.sceneLoaded -= OnLoaded; SceneManager.sceneLoaded += OnLoaded; Dedup(); } static void OnLoaded(Scene s, LoadSceneMode m) { Dedup(); } /// 켜진 EventSystem 이 2개 이상이면 하나만 남기고 끈다. 끈 개수를 돌려준다. public static int Dedup() { var all = Object.FindObjectsByType(FindObjectsInactive.Exclude, FindObjectsSortMode.None); int live = 0; for (int i = 0; i < all.Length; i++) if (all[i] != null && all[i].isActiveAndEnabled) live++; if (live <= 1) return 0; EventSystem keep = EventSystem.current != null && EventSystem.current.isActiveAndEnabled ? EventSystem.current : null; for (int i = 0; i < all.Length && keep == null; i++) if (all[i] != null && all[i].isActiveAndEnabled) keep = all[i]; int n = 0; for (int i = 0; i < all.Length; i++) { var e = all[i]; if (e == null || e == keep || !e.isActiveAndEnabled) continue; var mods = e.GetComponents(); for (int k = 0; k < mods.Length; k++) mods[k].enabled = false; e.enabled = false; n++; } Disabled += n; LastLog = "EventSystem " + live + "개 → 1개 (남김 " + (keep != null ? keep.name + "@" + keep.gameObject.scene.name : "-") + ")"; return n; } } }