using UnityEngine; using UnityEngine.UI; namespace TKS.OutGame { /// /// 물리 뒤로 가기 · 앱 전환 처리(PD 2026-11-26 「구글 플레이 피처드 정책 — 물리 백키로 돌아가기 or 취소」) — 게임 내내 1개(씬이 바뀌어도 유지). /// 백키 순서 = 종료 확인창 → OutGameRoot(공용 팝업 → 덮개 UiBack → 전투 중단 팝업 · 결과 확인 → 화면 뒤로 → 로비 = 종료 확인) → (아웃게임 없음) 덮개 UiBack. /// 앱이 백그라운드로 가면 전투 중 = 중단 팝업(일시정지) · 모바일 프레임 = 60(Google Play 핵심 품질 「렌더링 60fps」 · 유니티 모바일 기본 30). /// public class BackKeyRouter : MonoBehaviour { static BackKeyRouter inst; [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)] static void Boot() { if (inst != null) return; var go = new GameObject("BackKeyRouter"); DontDestroyOnLoad(go); inst = go.AddComponent(); if (Application.isMobilePlatform) Application.targetFrameRate = 60; } void Update() { if (Input.GetKeyDown(KeyCode.Escape)) Handle(); } /// 백키 1번 처리(시험에서도 부름). public static void Handle() { if (ExitConfirm.IsOpen) { ExitConfirm.Close(); return; } var root = OutGameRoot.Instance; if (root != null && root.HandleBackKey()) return; UiBack.Handle(); } void OnApplicationPause(bool paused) { if (!paused) return; var root = OutGameRoot.Instance; if (root != null) root.OnAppPause(); } } /// /// 게임 종료 확인창(로비 · 타이틀에서 백키 · PD 2026-11-26) — 모든 화면 위 자기 캔버스(타이틀 850 보다 위) · 백키 = 취소 · 「종료」 = Application.Quit. /// 모양 = 공용 팝업(OutGameRoot.ModalCustom)과 같은 테마 부품(popup · popup_head · 버튼). /// public static class ExitConfirm { const int Order = 900; static GameObject go; public static bool IsOpen { get { return go != null; } } public static void Show() { if (go != null) return; var cam = Camera.main; if (cam == null) return; go = new GameObject("ExitConfirm"); UiLayer.Root(go, cam, Order, 0.2f, UiLayer.Reference, UiRate.Event); go.AddComponent(); Sound.PlayUi(SoundKeys.UiPopup); var root = (RectTransform)go.transform; var dim = UiKit.Fill("Dim", root); UiKit.Paint(dim, UISkin.Col("dim", new Color(0f, 0f, 0f, 0.6f)), false, true); Image panel; if (UISkin.Has("popup")) { panel = UiKit.Skin(UiKit.Rect("Panel", dim, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 20f), new Vector2(860f, 520f)), "popup", UiKit.Paper, true); var head = UiKit.TopBand("Head", panel.transform, 6f, 110f, 7f, 7f); UiKit.Skin(head, "popup_head", UiKit.Col("popup_band", UiKit.Header)); UiKit.Title(UiKit.FillLabel(head, "게임 종료", 44, UiKit.HeaderText, TextAnchor.MiddleCenter, true, 110f), true); } else { panel = UiKit.Box("Panel", dim, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 20f), new Vector2(860f, 520f), UiKit.Paper); panel.raycastTarget = true; UiKit.Border(panel, UiKit.Line, 4f); var head = UiKit.TopBand("Head", panel.transform, 0f, 110f); UiKit.Paint(head, UiKit.Dark); UiKit.FillLabel(head, "게임 종료", 44, UiKit.White); } var body = UiKit.Fill("Content", panel.transform, 40f, 40f, 130f, 160f); UiKit.FillLabel(body, "게임을 종료하시겠습니까?", 38, UiKit.Ink, TextAnchor.MiddleCenter, false, 10f); UiKit.Btn("Cancel", panel.transform, "취소", 34, UiKit.Dark, UiKit.White, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(-200f, 36f), new Vector2(360f, 100f), Close); UiKit.Btn("Quit", panel.transform, "종료", 34, UiKit.Red, UiKit.White, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(200f, 36f), new Vector2(360f, 100f), Quit); } public static void Close() { if (go == null) return; Sound.PlayUi(SoundKeys.UiClose); go.SetActive(false); Object.Destroy(go); go = null; } static void Quit() { Close(); Debug.Log("[ExitConfirm] 종료"); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif } } }