using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using UnityEngine; using UnityEngine.UI; namespace TKS.OutGame { /// /// 타이틀 화면(PD 2026-11-13 「타이틀 화면이 등장할 때 캐릭터들이 타이틀 화면의 현재 위치로 모이는 연출과 함께 시작 · 이후 대기 애니메이션처럼 움직이는 연출 · /// 꾸미기 요소도 가벼운 애니메이션 · "Press Any Key" 깜박임 · 터치하면 다음 조작으로」). /// 시작 흐름 = BootFlow.TitleProvider(스플래시 → (받기) → 타이틀) → 누르면 검정 페이드 → 본영 로비. /// 값 = 표 Resources/UI/title_screen.csv(LoadingTable 형식) · 꾸미기 = title_ambient.csv(LobbyAmbient · 로비·내정과 같은 규칙) · C45. /// 층(P41): 루트 = Static(배경) → 그림 공간 Ambient(Frame · 뒤 연출 → 햇살·장수·착지 먼지 → 앞 불씨) → Ui(Frame · 로고·반짝이·글자 · 화면 공간). /// public class TitleScreen : MonoBehaviour { public const string TablePath = "UI/title_screen"; public const string AmbientPath = "UI/title_ambient"; public const float ArtW = 1080f; public const float ArtH = 1920f; /// 테스트·검증 캡처가 메모리 세이브에서도 타이틀을 띄울 때(표 skip_memory 무시). public static bool ForceShow; /// 검증 캡처용 고정 시계 — 켜면 Update 가 연출 시간을 더하지 않고(SetTime 만) 대기·먼지도 같은 시계를 씀(정지 장면 시각 = 표기 시각 · 30fps 확인 영상). public static bool FixedClock; float clockNow; /// 검증 캡처용 — 켜면 실제 입력(키·터치)을 무시(캡처 창이 키 입력을 받아 먼저 닫히던 문제 · 2026-11-16 10차 캡처) · 누름은 Press() 로만. public static bool IgnoreInput; public static TitleScreen Current { get; private set; } public class Hero { public string id; public RectTransform rt; public Image img; public Sprite[] frames; public LoadingTable.Row row; public float[] dur; public int blinkFrame = -1; public float blinkMin; public float blinkMax; public float blinkDur; public bool landed; public float idleT0; public float nextBlink; public float blinkEnd = -1f; } class Spark { public RectTransform rt; public Image img; public LoadingTable.Row row; } class Puff { public RectTransform rt; public Image img; public float t0; public float baseW; } public Canvas RootCanvas { get; private set; } /// 그림 공간(1080×1920 · 화면을 꽉 채우게 크기만 바꿈 · 배경·연출·장수의 좌표 = 그림 px). public RectTransform Art { get; private set; } public LobbyAmbient Ambient { get; private set; } /// 무대 층(Frame · 장수·로고·글자) — 안의 StageArt = 그림 좌표 1080×1920 · 화면 안에 다 들어오는 배율(contain). public RectTransform Ui { get; private set; } public RectTransform Stage { get; private set; } public Image Logo { get; private set; } public Image Rays { get; private set; } public Text PressText { get; private set; } public readonly List Heroes = new List(); /// 등장 연출이 끝났는가(로고까지 내려앉음). public bool IntroDone { get; private set; } /// 「Press Any Key」가 떠서 누르면 다음으로 가는가. public bool PressReady { get; private set; } public bool Leaving { get; private set; } /// 등장 연출 시계(초 · 건너뛰면 끝 시각으로). public float Elapsed { get; private set; } public float IntroEnd { get; private set; } Camera cam; Action onStart; List rows; LoadingTable.Row rowRays; LoadingTable.Row rowLogo; LoadingTable.Row rowZoom; LoadingTable.Row rowShake; float RecoilSec = 0.22f; // 부딪힌 뒤 튕겼다 돌아오는 초(표 option recoil f_a · 없으면 6차 값) LoadingTable.Row rowCharge; LoadingTable.Row rowFlash; Image flash; float logoK = 1f; Image fadeIn; float fadeSec; float shakeAt = -10f; class Part { public RectTransform rt; public Image img; public LoadingTable.Row row; public string kind; public float[] args; public Vector2 basePos; public bool landed; public bool hit; // clash 부딪힘 흔들림 1회 } readonly List parts = new List(); /// 로고 부품들의 부모(무대 위 · 둥실). public RectTransform LogoRoot { get; private set; } public int LogoPartCount { get { return parts.Count; } } /// 로고 부품 중 가장 낮은 알파(끝 모습에서 모든 부품이 보이는지 · 테스트 · 1회용 burst 불꽃은 뺌). public float LogoPartMinAlpha { get { float m = 1f; int n = 0; foreach (var pt in parts) { if (pt.kind == "burst") continue; m = Mathf.Min(m, pt.img.color.a); n++; } return n > 0 ? m : 0f; } } /// 1회용 불꽃(burst)이 끝 모습에서 꺼졌는지(테스트). public bool BurstsHidden { get { foreach (var pt in parts) if (pt.kind == "burst" && pt.img.color.a > 0.01f) return false; return true; } } LoadingTable.Row rowPress; LoadingTable.Row rowPuff; readonly List sparks = new List(); readonly List puffs = new List(); Sprite puffSprite; float last; Vector2 lastRoot; [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] static void Register() { BootFlow.TitleProvider = Provide; } /// BootFlow 훅 — 표가 있고(메모리 세이브면 표 skip_memory 에 따라 건너뜀) 타이틀을 띄우면 true. public static bool Provide(Camera cam, Action toLobby) { var list = LoadingTable.Load(TablePath); if (list.Count == 0) return false; var skip = list.Find(x => x.kind == "option" && x.id == "skip_memory"); if (!ForceShow && skip != null && skip.a > 0f && SaveStore.MemoryOnly) return false; Show(cam, toLobby); return true; } /// 타이틀을 띄운다(이미 있으면 닫고 새로) · onStart = 누름 → 페이드 뒤 부름(로비). public static TitleScreen Show(Camera cam, Action onStart) { if (Current != null) Current.Close(); var go = new GameObject("TitleScreen"); var t = go.AddComponent(); Current = t; t.cam = cam; t.onStart = onStart; t.Build(); return t; } LoadingTable.Row Opt(string id) { return rows.Find(x => x.kind == "option" && x.id == id); } LoadingTable.Row First(string kind) { return rows.Find(x => x.kind == kind); } void Build() { rows = LoadingTable.Load(TablePath); var oc = Opt("canvas"); RootCanvas = UiLayer.Root(gameObject, cam, oc != null ? (int)oc.a : 850, oc != null && oc.b > 0f ? oc.b : 0.3f, UiLayer.Reference, UiRate.Static); var root = (RectTransform)transform; HideBelow(RootCanvas.sortingOrder); // 그림 공간(배경 크기 그대로 · 화면을 덮는 배율만 Update 에서) var bgRow = First("bg"); Art = UiKit.Rect("Art", root, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, new Vector2(ArtW, ArtH)); var bg = Art.gameObject.AddComponent(); bg.sprite = bgRow != null ? LoadingTable.Sprite(bgRow.sprite) : null; bg.color = bgRow != null ? bgRow.color : Color.black; bg.raycastTarget = true; // 아래 화면 누름을 막음 FitArt(); // 꾸미기(로비·내정과 같은 LobbyAmbient · Frame 캔버스 1장 · 배경 그림에 붙음 = 배경과 같은 배율) — Back(빛·흙먼지) → Lineup(햇살) → Front(불씨) Ambient = LobbyAmbient.Build(Art, ArtW, ArtH, LobbyScene.Load(AmbientPath)); var lineup = Ambient.Lineup; // 무대(장수·착지 먼지·로고·반짝이·글자) = 그림 좌표 그대로 · 화면 안에 다 들어오는 배율(QA r1 B1~B4: 배경 배율(cover)로 키우면 20:9 = 로고·황충 활 잘림 · 4:3 = 로고가 얼굴을 가리고 관우 하체 잘림) Ui = UiLayer.Group("Stage", root, UiRate.Frame); Stage = UiKit.Rect("StageArt", Ui, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, new Vector2(ArtW, ArtH)); lastRoot = Vector2.zero; FitArt(); var stage = Stage; rowRays = First("rays"); if (rowRays != null) { Rays = ArtImage("Rays", lineup, rowRays.sprite, rowRays.x, rowRays.y, rowRays.w, rowRays.w); Rays.color = WithA(rowRays.color, 0f); } var heroRows = rows.FindAll(x => x.kind == "hero"); heroRows.Sort((p, q) => p.size.CompareTo(q.size)); foreach (var r in heroRows) { var fr = LoadingTable.Frames(r.sprite); if (fr.Length == 0) continue; var h = new Hero { id = r.id, row = r, frames = fr }; h.img = ArtImage("Hero_" + r.id, stage, null, r.x, r.y, r.w, r.h); h.img.sprite = fr[0]; h.rt = (RectTransform)h.img.transform; h.dur = ParseList(r.text); var b = ParseList(r.reference); if (b.Length >= 4 && (int)b[0] < fr.Length) { h.blinkFrame = (int)b[0]; h.blinkMin = b[1]; h.blinkMax = b[2]; h.blinkDur = b[3]; } Heroes.Add(h); } rowPuff = First("puff"); if (rowPuff != null) puffSprite = LoadingTable.Sprite(rowPuff.sprite); // 로고·글자 = 무대 위(장수와 같은 배율 · 로고 f_y = 그림 위에서 · 글자 f_y = 그림 아래에서) rowLogo = First("logo"); if (rowLogo != null) { // 로고 = 부품(7차 = 먹 띠 · 제목 · 청룡 · 부제 판 · 백호 · 부딪힘 불꽃 · 2026-11-16 PD 「바둑알 부딪힘 → 용과 호랑이가 부딪히는 컨셉」) — 부품마다 따로 등장 var box = ParseList(rowLogo.reference.Replace('x', '|')); float bw = box.Length >= 2 ? box[0] : rowLogo.w, bh = box.Length >= 2 ? box[1] : rowLogo.w * 0.63f; logoK = rowLogo.w / Mathf.Max(1f, bw); var rt = UiKit.Rect("Logo", stage, new Vector2(0.5f, 1f), new Vector2(0.5f, 0.5f), new Vector2(rowLogo.x, -rowLogo.y), new Vector2(rowLogo.w, bh * logoK)); LogoRoot = rt; foreach (var r in rows.FindAll(x => x.kind == "logo_part")) { var prt = UiKit.Rect("Part_" + r.id, rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(r.x * logoK, -r.y * logoK), new Vector2(r.w * logoK, r.h * logoK)); var im = prt.gameObject.AddComponent(); im.sprite = LoadingTable.Sprite(r.sprite); im.raycastTarget = false; im.color = WithA(r.color, 0f); var spec = (r.set ?? "").Split(':'); parts.Add(new Part { rt = prt, img = im, row = r, kind = spec[0], args = ParseList(string.Join("|", spec, 1, spec.Length - 1)), basePos = prt.anchoredPosition }); if (r.id == "title") Logo = im; } if (Logo == null && parts.Count > 0) Logo = parts[0].img; foreach (var r in rows.FindAll(x => x.kind == "sparkle")) { var s = UiKit.Rect("Spark_" + r.id, rt, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(r.x, r.y), new Vector2(r.w, r.w)); var im = s.gameObject.AddComponent(); im.sprite = LoadingTable.Sprite(r.sprite); im.raycastTarget = false; im.color = WithA(r.color, 0f); sparks.Add(new Spark { rt = s, img = im, row = r }); } } rowPress = First("press"); if (rowPress != null) { PressText = UiKit.Label(stage, rowPress.text, rowPress.size, rowPress.color, TextAnchor.MiddleCenter, new Vector2(0.5f, 0f), new Vector2(0.5f, 0.5f), new Vector2(rowPress.x, rowPress.y), new Vector2(rowPress.w, rowPress.h)); if (UISkin.TitleFont != null) PressText.font = UISkin.TitleFont; var o = PressText.gameObject.AddComponent(); o.effectColor = new Color(0.12f, 0.06f, 0.03f, 0.95f); o.effectDistance = new Vector2(3f, -3f); var sh = PressText.gameObject.AddComponent(); sh.effectColor = new Color(0f, 0f, 0f, 0.55f); sh.effectDistance = new Vector2(0f, -6f); PressText.color = WithA(rowPress.color, 0f); } // 등장 연출이 끝나는 시각 = 가장 늦은 장수 착지 · 로고 내려앉음 IntroEnd = 0f; var rc = Opt("recoil"); if (rc != null && rc.a > 0f) RecoilSec = rc.a; foreach (var h in Heroes) IntroEnd = Mathf.Max(IntroEnd, h.row.phase + h.row.fps); foreach (var pt in parts) IntroEnd = Mathf.Max(IntroEnd, pt.row.phase + pt.row.fps + ((pt.kind == "knock" || pt.kind == "slide") && pt.args.Length >= 2 ? Mathf.Max(0f, pt.args[0] - pt.row.phase - pt.row.fps) + RecoilSec : 0f)); // 절정 번쩍임(표 option flash · 8차 PD 「차례대로 등장하기만 해서 매력 없음」 → 돌격 착지 = 용호 부딪힘 = 로고 터짐 한 순간) rowCharge = Opt("charge"); rowFlash = Opt("flash"); if (rowFlash != null && rowFlash.b > 0f) { flash = UiKit.Fill("Flash", Ui).gameObject.AddComponent(); flash.color = WithA(rowFlash.color, 0f); flash.raycastTarget = false; } // 시작 = 검정에서 밝아짐(표 option fade_in) · 무대 맨 위 덮개 var fi = Opt("fade_in"); if (fi != null && fi.a > 0f) { fadeIn = UiKit.Fill("FadeIn", Ui).gameObject.AddComponent(); fadeIn.color = fi.color; fadeIn.raycastTarget = false; fadeSec = fi.a; } rowZoom = Opt("zoom"); rowShake = Opt("shake"); Elapsed = 0f; last = Time.unscaledTime; Apply(); } Image ArtImage(string name, Transform parent, string sprite, float x, float y, float w, float h) { // 그림 px(왼쪽 위 0,0 · 아래 +) → 그림 공간(부모 = 그림 크기 그대로 1080×1920) var rt = UiKit.Rect(name, parent, new Vector2(0f, 1f), new Vector2(0.5f, 0.5f), new Vector2(x, -y), new Vector2(w, h)); var img = rt.gameObject.AddComponent(); if (!string.IsNullOrEmpty(sprite)) img.sprite = LoadingTable.Sprite(sprite); img.raycastTarget = false; return img; } static float[] ParseList(string s) { if (string.IsNullOrEmpty(s)) return new float[0]; var parts = s.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); var list = new List(); foreach (var p in parts) { float f; if (float.TryParse(p.Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out f)) list.Add(f); } return list.ToArray(); } static Color WithA(Color c, float a) { c.a = a; return c; } static void SetA(Graphic g, Color baseC, float a01) { var c = g.color; float a = baseC.a * Mathf.Clamp01(a01); if (!Mathf.Approximately(c.a, a)) { c.a = a; g.color = c; } } static float EaseOutCubic(float p) { p = 1f - Mathf.Clamp01(p); return 1f - p * p * p; } static float EaseInOutQuad(float p) { p = Mathf.Clamp01(p); return p < 0.5f ? 2f * p * p : 1f - 2f * (1f - p) * (1f - p); } /// 청룡·백호 부딪힘 → 박힘(clash · 10차) — 값 = 표 s_set 인자 · option clash. void AnimateClash(Part pt, float t) { var r = pt.row; float tc = pt.args[0], ts = pt.args[4], cs = pt.args[3]; Vector2 cp = new Vector2(pt.args[1], -pt.args[2]) * logoK; float over = pt.args[5] * logoK, rise = pt.args[6] * logoK; var oc = Opt("clash"); float squash = oc != null && oc.a > 0f ? oc.a : 0.06f; float pre = oc != null && oc.b > 0f ? oc.b : 1.2f; float stamp = oc != null && oc.c > 0f ? oc.c : 0.12f; Vector2 pos = pt.basePos; float sx = 1f, sy = 1f, rot = 0f, alpha = 1f; if (t < r.phase) { alpha = 0f; pos = cp + new Vector2(r.a, -r.b) * logoK; sx = sy = cs; } else if (t < tc) { float u = Mathf.Clamp01((t - r.phase) / Mathf.Max(0.01f, tc - r.phase)); pos = cp + new Vector2(r.a, -r.b) * logoK * (1f - u * u); // 가속하며 덮쳐 옴 sx = sy = cs; rot = r.c * (1f - u); alpha = Mathf.Clamp01(u * 6f); } else if (t < tc + squash) { float u = (t - tc) / squash; // 멈칫(가로 눌림 · 세로 늘어남 → 원래) pos = cp; sx = cs * Mathf.Lerp(0.88f, 1f, u); sy = cs * Mathf.Lerp(1.08f, 1f, u); } else if (t < ts) { float u = Mathf.Clamp01((t - tc - squash) / Mathf.Max(0.01f, ts - tc - squash)); // 판이 펼쳐지며 밀어냄 float dir = Mathf.Sign(pt.basePos.x - cp.x); float x = u < 0.75f ? Mathf.Lerp(cp.x, pt.basePos.x + dir * over, EaseOutCubic(u / 0.75f)) : Mathf.Lerp(pt.basePos.x + dir * over, pt.basePos.x, EaseInOutQuad((u - 0.75f) / 0.25f)); float y = Mathf.Lerp(cp.y, pt.basePos.y, u) + rise * Mathf.Sin(u * Mathf.PI); pos = new Vector2(x, y); sx = sy = Mathf.Lerp(cs, pre, EaseInOutQuad(u)); } else { float u = (t - ts) / stamp; // 박힘(도장) → 맥동 float s = u < 1f ? Mathf.LerpUnclamped(pre, 1f, EaseOutBack(u, 1.7f)) : 1f; if (u >= 1f && pt.args.Length >= 9 && pt.args[8] > 0f) s *= 1f + pt.args[7] * Mathf.Sin(((t - ts - stamp) / pt.args[8] + (pt.args.Length >= 10 ? pt.args[9] : 0f)) * Mathf.PI * 2f); sx = sy = s; } if (!pt.hit && t >= tc && t - tc < 0.2f) { pt.hit = true; shakeAt = t; } // 부딪힘 흔들림(건너뛰기면 없음) if (!pt.landed && t >= ts) { pt.landed = true; if (t - ts < 0.2f) shakeAt = t; } // 박힘 흔들림 if (pt.rt.anchoredPosition != pos) pt.rt.anchoredPosition = pos; var sv = new Vector3(sx, sy, 1f); if (pt.rt.localScale != sv) pt.rt.localScale = sv; var eul = new Vector3(0f, 0f, rot); if (pt.rt.localEulerAngles != eul) pt.rt.localEulerAngles = eul; SetA(pt.img, r.color, alpha); } static float Num(string s) { float f; return float.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out f) ? f : 0f; } /// /// 로고 부품 등장(s_set): pop = 크기 f_scale→1 · 돌기 f_c→0 · slam = 크게 → 쾅(EaseOutBack · 흔들림) · unfurl = 가로로 펼침 · /// slide = 출발 어긋남(f_a,f_b · 로고 px)에서 빨라지며 와서 멈춤 · knock:시각:px = pop 뒤 그 시각에 왼쪽으로 튕겼다 돌아옴(흑돌에 맞음). /// 7차(PD 2026-11-16 「바둑알 부딪힘 → 용과 호랑이가 부딪히는 컨셉」): sweep = 왼쪽 끝을 붙인 채 오른쪽으로 쓸려 나옴(먹 붓 띠) · /// slide:시각:반동px[:밀기px:주기] = 와서 그 시각에 부딪혀 반동(px + = 왼쪽 · − = 오른쪽) 뒤 밀기px 로 서로 미는 숨(주기 초) · /// pop:맥동[:주기] = 나타난 뒤 크기 1 ± 맥동(부딪힘 불꽃). /// 10차(PD 2026-11-16 · Fable 시안 「용호상박이 현판을 낳는다」): /// clash:부딪힘시각:부딪힘x:부딪힘y:부딪힘배율:박힘시각:넘침px:솟음px[:맥동:주기:위상] = 출발 어긋남(f_a,f_b · 부딪힘 자리 기준 로고 px · 기울기 f_c)에서 /// 가속해 와 부딪힘(배율 고정) → 멈칫(눌림) → 제자리로 밀려남(바깥으로 넘쳤다 돌아옴 · 위로 솟음 · 배율 → 박힘 전 배율) → 박힘(도장 · 흔들림) → 맥동 · /// 멈칫 초 · 박힘 전 배율 · 박힘 초 = 표 option clash f_a · f_b · f_c /// burst = 한 번 터지고 사라지는 불꽃(크기 f_scale → f_a · 돌기 f_c → 0 · 뒤 60 % 동안 사라짐 · 끝나면 안 보임) /// void AnimatePart(Part pt, float t) { var r = pt.row; float p = r.fps > 0f ? (t - r.phase) / r.fps : (t >= r.phase ? 1f : 0f); if (pt.kind == "clash" && pt.args.Length >= 7) { AnimateClash(pt, t); return; } Vector2 pos = pt.basePos; Vector3 sc = Vector3.one; float rot = 0f, alpha = Mathf.Clamp01(p * 4f); if (p <= 0f) alpha = 0f; else if (pt.kind == "burst") { float u = Mathf.Clamp01(p); float s = Mathf.Lerp(r.scale, r.a, EaseOutCubic(u)); sc = new Vector3(s, s, 1f); rot = Mathf.Lerp(r.c, 0f, EaseOutCubic(u)); alpha = p >= 1f ? 0f : (u < 0.4f ? 1f : 1f - (u - 0.4f) / 0.6f); } else if (pt.kind == "unfurl" || pt.kind == "sweep") { float e = EaseOutCubic(p); sc = new Vector3(Mathf.Max(0.001f, e), 1f, 1f); if (pt.kind == "sweep") pos = pt.basePos + new Vector2(-(1f - e) * pt.rt.sizeDelta.x * 0.5f, 0f); // 왼쪽 끝 고정 alpha = Mathf.Clamp01(p * 6f); } else if (pt.kind == "slide") { float e = p * p; // 빨라지며 와서 부딪힘 pos = pt.basePos + new Vector2(r.a, -r.b) * logoK * (1f - Mathf.Clamp01(e)); alpha = Mathf.Clamp01(p * 3f); if (pt.args.Length >= 2) { float u = (t - pt.args[0]) / RecoilSec; // 부딪힌 뒤 튕겼다 돌아옴 if (u > 0f && u < 1f) pos += new Vector2(-pt.args[1] * logoK * Mathf.Sin(u * Mathf.PI), 0f); if (u >= 1f && pt.args.Length >= 4 && pt.args[3] > 0f) // 서로 미는 숨(두 부품이 반대 부호 = 밀고 밀림) pos += new Vector2(-pt.args[2] * logoK * Mathf.Sin((t - pt.args[0] - RecoilSec) / pt.args[3] * Mathf.PI * 2f), 0f); } } else { float e = EaseOutBack(p, pt.kind == "slam" ? 2.2f : 1.7f); float s = Mathf.LerpUnclamped(r.scale, 1f, e); sc = new Vector3(s, s, 1f); rot = Mathf.LerpUnclamped(r.c, 0f, Mathf.Clamp01(EaseOutCubic(p))); if (pt.kind == "knock" && pt.args.Length >= 2) { float u = (t - pt.args[0]) / RecoilSec; // 맞은 뒤 튕겼다 돌아옴 if (u > 0f && u < 1f) pos = pt.basePos + new Vector2(-pt.args[1] * logoK * Mathf.Sin(u * Mathf.PI), 0f); } if (pt.kind == "pop" && pt.args.Length >= 1 && p >= 1f) // 나타난 뒤 맥동(부딪힘 불꽃) { float per = pt.args.Length >= 2 && pt.args[1] > 0f ? pt.args[1] : 0.6f; float k = 1f + pt.args[0] * Mathf.Sin((t - r.phase - r.fps) / per * Mathf.PI * 2f); sc = new Vector3(k, k, 1f); } } if (p >= 1f && !pt.landed) { pt.landed = true; if (pt.kind == "slam" && t - r.phase - r.fps < 0.2f) shakeAt = t; } if (pt.rt.anchoredPosition != pos) pt.rt.anchoredPosition = pos; if (pt.rt.localScale != sc) pt.rt.localScale = sc; var eul = new Vector3(0f, 0f, rot); if (pt.rt.localEulerAngles != eul) pt.rt.localEulerAngles = eul; SetA(pt.img, r.color, alpha); } static float EaseOutBack(float p, float k) { p = Mathf.Clamp01(p) - 1f; return 1f + p * p * ((k + 1f) * p + k); } /// 그림 공간이 화면을 덮게(가로·세로 중 큰 배율 · 화면 밖으로 나가는 쪽은 잘림). void FitArt() { var root = (RectTransform)transform; var sz = root.rect.size; if (sz == lastRoot || sz.x <= 0f || sz.y <= 0f) return; lastRoot = sz; coverS = Mathf.Max(sz.x / ArtW, sz.y / ArtH); // 배경 = 화면을 덮음(cover) Art.localScale = new Vector3(coverS, coverS, 1f); containS = Mathf.Min(sz.x / ArtW, sz.y / ArtH); // 무대 = 화면 안에 다 들어옴(contain · 9:16 이면 배경과 같음) if (Stage != null) Stage.localScale = new Vector3(containS, containS, 1f); } /// 연출 시계를 정함(검증 캡처 · 테스트 · 착지 먼지는 그 순간 착지한 장수만). public void SetTime(float t) { Elapsed = Mathf.Max(0f, t); Apply(); } /// 등장 연출을 끝 모습으로(누름 · 테스트). public void SkipIntro() { if (Elapsed < IntroEnd) Elapsed = IntroEnd; Apply(); } /// 누름 — 등장 중이면 건너뜀(표 skip) · 글자가 떴으면 페이드 뒤 onStart. public void Press() { if (Leaving) return; if (!PressReady) { var sk = Opt("skip"); if (sk == null || sk.a > 0f) SkipIntro(); return; } Leaving = true; var lv = Opt("leave"); float fOut = lv != null ? lv.a : 0.3f, fHold = lv != null ? lv.b : 0.1f, fIn = lv != null ? lv.c : 0.3f; int order = lv != null && lv.size > 0 ? lv.size : 960; var fader = ScreenFader.Create(cam, order, lv != null ? lv.color : Color.black); fader.StartCoroutine(LeaveRoutine(fader, fOut, fHold, fIn)); } IEnumerator LeaveRoutine(ScreenFader fader, float fOut, float fHold, float fIn) { yield return fader.FadeTo(1f, fOut); var cb = onStart; Close(); if (cb != null) cb(); for (float w = 0f; w < fHold; w += Time.unscaledDeltaTime) yield return null; yield return fader.FadeTo(0f, fIn); Destroy(fader.gameObject); } public void Close() { RestoreBelow(); if (Current == this) Current = null; Destroy(gameObject); } void OnDestroy() { RestoreBelow(); if (Current == this) Current = null; } readonly List hidden = new List(); /// 타이틀이 화면을 다 덮는 동안 그 아래 루트 캔버스(로비·재화 바 등)를 끔(QA r1 M5 · 저사양 · 안 보이는 화면을 계속 그림) · 페이드처럼 위 순서는 그대로. void HideBelow(int order) { foreach (var c in FindObjectsByType(FindObjectsSortMode.None)) { if (c == null || !c.isRootCanvas || !c.enabled || c.gameObject == gameObject || c.sortingOrder >= order) continue; c.enabled = false; hidden.Add(c); } } void RestoreBelow() { foreach (var c in hidden) if (c != null) c.enabled = true; hidden.Clear(); } /// 끈 아래 캔버스 수(테스트). public int HiddenCount { get { return hidden.Count; } } static bool AnyInput() { if (Input.anyKeyDown) return true; // 키보드 · 마우스 단추 for (int i = 0; i < Input.touchCount; i++) if (Input.GetTouch(i).phase == TouchPhase.Began) return true; return false; } void Update() { if (rows == null) return; // Play 중 재컴파일 = 직렬화 안 된 값이 비면 멈춤 float now = Time.unscaledTime; float dt = Mathf.Min(0.1f, Mathf.Max(0f, now - last)); last = now; if (!FixedClock) Elapsed += dt; FitArt(); if (!Leaving && !IgnoreInput && AnyInput()) Press(); Apply(); } float coverS = 1f; float containS = 1f; void Apply() { float t = Elapsed; float now = FixedClock ? Elapsed : Time.unscaledTime; clockNow = now; // 시작 = 검정에서 밝아짐 · 배경이 살짝 다가왔다 물러남(zoom) · 큰 착지·제목 쾅 = 짧은 흔들림(shake) if (fadeIn != null) SetA(fadeIn, Opt("fade_in").color, 1f - Mathf.Clamp01(t / Mathf.Max(0.05f, fadeSec))); if (flash != null) { float u = (t - rowFlash.a) / rowFlash.b; // 0 = 가장 밝음 → 1 = 사라짐 SetA(flash, rowFlash.color, u < 0f || u >= 1f ? 0f : rowFlash.c * (1f - u) * (1f - u)); } if (Art != null && rowZoom != null && rowZoom.b > 0f) { float z = Mathf.Lerp(rowZoom.a, 1f, EaseOutCubic(t / rowZoom.b)) * coverS; var zv = new Vector3(z, z, 1f); if (Art.localScale != zv) Art.localScale = zv; } if (Stage != null && Art != null) { Vector2 off = Vector2.zero; if (rowShake != null && rowShake.b > 0f && t >= shakeAt && t < shakeAt + rowShake.b) { float k = 1f - (t - shakeAt) / rowShake.b; off = new Vector2(Mathf.Sin(t * 91f), Mathf.Cos(t * 77f)) * rowShake.a * k; } if (Stage.anchoredPosition != off) Stage.anchoredPosition = off; if (Art.anchoredPosition != off * 0.5f) Art.anchoredPosition = off * 0.5f; } // 햇살 = 천천히 돌며 숨 if (Rays != null && rowRays != null) { Rays.rectTransform.localEulerAngles = new Vector3(0f, 0f, -rowRays.a * now); float breath = 0.5f + 0.5f * Mathf.Sin(now / Mathf.Max(0.1f, rowRays.fps) * Mathf.PI * 2f); float alpha = Mathf.Lerp(rowRays.b, rowRays.c, breath) * Mathf.Clamp01(t / Mathf.Max(0.05f, rowRays.phase + 0.5f)); SetA(Rays, new Color(1f, 1f, 1f, 1f), alpha); } // 장수 = 화면 밖 → 제자리(EaseOutBack) → 착지 먼지 → 대기 프레임 foreach (var h in Heroes) { var r = h.row; float p = r.fps > 0f ? (t - r.phase) / r.fps : (t >= r.phase ? 1f : 0f); if (p <= 0f) { SetA(h.img, r.color, 0f); continue; } // 움직임 종류(s_set · 2026-11-16 PD 「너무 인위적으로 뭉쳐 나옴 → 자연스럽게」): rise = 뒤에서 올라섬 · run:번:높이 = 옆에서 뛰어옴(통통) · leap = 크게 뛰어듦(EaseOutBack) var target = Target(r); var spec = (r.set ?? "").Split(':'); string kind = spec[0]; Vector2 pos; float sc, alpha; if (kind == "rise") { float e = EaseOutCubic(p); pos = target + new Vector2(r.a * (1f - e), -r.b * (1f - e)); sc = Mathf.Lerp(r.scale, 1f, e); alpha = Mathf.Clamp01(p * 1.6f); } else if (kind == "run") { float e = EaseOutCubic(p); int n = spec.Length > 1 ? Mathf.Max(1, (int)Num(spec[1])) : 3; float hgt = spec.Length > 2 ? Num(spec[2]) : 18f; float pc = Mathf.Clamp01(p); // 도착 뒤(p > 1)에는 튐 0 = 제자리 float bob = -Mathf.Abs(Mathf.Sin(pc * n * Mathf.PI)) * hgt * (1f - pc * 0.6f); pos = target + new Vector2(r.a * (1f - e), -r.b * (1f - e) - bob); sc = Mathf.Lerp(r.scale, 1f, e); alpha = Mathf.Clamp01(p * 5f); } else if (kind == "charge") { // 돌격(8차): 성문(option charge f_x,f_y)에서 작게 출발 → 가속하며 다가와 커짐(f_b 지수) · 뛰는 튐 · 거의 동시 출발 float pc = Mathf.Clamp01(p); float e = Mathf.Pow(pc, rowCharge != null && rowCharge.b > 0f ? rowCharge.b : 1.8f); Vector2 vp = rowCharge != null ? new Vector2(rowCharge.x, -rowCharge.y) : target; Vector2 start = Vector2.Lerp(vp, target, rowCharge != null ? rowCharge.a : 0f); int n = spec.Length > 1 ? Mathf.Max(1, (int)Num(spec[1])) : 3; float hgt = spec.Length > 2 ? Num(spec[2]) : 18f; sc = Mathf.Lerp(r.scale, 1f, e); float bob = Mathf.Abs(Mathf.Sin(pc * n * Mathf.PI)) * hgt * sc * (1f - pc); pos = Vector2.Lerp(start, target, e) + new Vector2(0f, bob); alpha = Mathf.Clamp01(p * 5f); } else { float e = EaseOutBack(p, r.c); pos = Vector2.LerpUnclamped(target + new Vector2(r.a, -r.b), target, e); sc = Mathf.LerpUnclamped(r.scale, 1f, e); alpha = Mathf.Clamp01(p * 4f); } if (h.rt.anchoredPosition != pos) h.rt.anchoredPosition = pos; var sv = new Vector3(sc, sc, 1f); if (h.rt.localScale != sv) h.rt.localScale = sv; SetA(h.img, r.color, alpha); if (p >= 1f && !h.landed) { h.landed = true; h.idleT0 = now - UnityEngine.Random.value * Cycle(h); h.nextBlink = now + UnityEngine.Random.Range(h.blinkMin, h.blinkMax); bool fresh = t - r.phase - r.fps < 0.2f; // 건너뛰기로 한꺼번에 착지하면 먼지·흔들림 없음 if (fresh && kind != "rise") SpawnPuff(h); if (fresh && (kind == "charge" || (kind == "leap" && (spec.Length < 2 || Num(spec[1]) > 0f)))) shakeAt = t; // leap:0 = 흔들림 없음(10차 · 관우만 흔들림) } if (h.landed) IdleFrame(h, now); } UpdatePuffs(now); // 로고 부품 = 문장 돌며 나타남 → 제목 쾅 → 부제 판 펼침 → 백돌 → 흑돌이 미끄러져 와 부딪힘(까다) → 백돌 튕김 · 다 모이면 둥실 · 반짝이 if (LogoRoot != null && rowLogo != null) { foreach (var pt in parts) AnimatePart(pt, t); float done = IntroEnd; float fl = t >= done ? rowLogo.a * Mathf.Sin((t - done) / Mathf.Max(0.1f, rowLogo.b) * Mathf.PI * 2f) : 0f; var lp = new Vector2(rowLogo.x, -rowLogo.y + fl); if (LogoRoot.anchoredPosition != lp) LogoRoot.anchoredPosition = lp; foreach (var s in sparks) { bool on = t >= done; float k = on ? Mathf.Repeat((t - done) / Mathf.Max(0.1f, s.row.a) + s.row.phase, 1f) : 0f; float tw = on ? Mathf.Sin(k * Mathf.PI) : 0f; // 0 → 1 → 0 tw = tw * tw; SetA(s.img, s.row.color, tw); var ss = new Vector3(0.4f + 0.6f * tw, 0.4f + 0.6f * tw, 1f); if (s.rt.localScale != ss) s.rt.localScale = ss; s.rt.localEulerAngles = new Vector3(0f, 0f, k * 90f); } } IntroDone = t >= IntroEnd; // 「Press Any Key」 = 등장 연출 끝 + f_phase 초 뒤부터 깜박임 · 그때부터 누르면 다음으로 if (PressText != null && rowPress != null) { float since = t - IntroEnd - rowPress.phase; PressReady = since >= 0f; float blink = 0.5f + 0.5f * Mathf.Cos(Mathf.Max(0f, since) / Mathf.Max(0.1f, rowPress.a) * Mathf.PI * 2f); SetA(PressText, rowPress.color, since < 0f ? 0f : Mathf.Lerp(rowPress.b, 1f, blink) * Mathf.Clamp01(since / 0.25f)); } else PressReady = IntroDone; } /// 장수 제자리(그림 공간) — 폭·높이가 홀수면 반 칸 밀어 모서리가 정수 픽셀에(QA r1 M6 · 선 흐림 방지). public static Vector2 Target(LoadingTable.Row r) { float ox = Mathf.RoundToInt(r.w) % 2 == 1 ? 0.5f : 0f; float oy = Mathf.RoundToInt(r.h) % 2 == 1 ? 0.5f : 0f; return new Vector2(r.x + ox, -(r.y + oy)); } float Cycle(Hero h) { float c = 0f; foreach (var d in h.dur) c += d; return Mathf.Max(0.1f, c); } /// 대기 = 자세 0→1→2→3 한 방향 반복(R22 · 표 유지 초) · 깜빡임 = 쉼 자세(0)일 때만. void IdleFrame(Hero h, float now) { int n = Mathf.Min(h.dur.Length, h.blinkFrame >= 0 ? h.blinkFrame : h.frames.Length); int k = 0; if (n > 1) { float c = Cycle(h); float u = Mathf.Repeat(now - h.idleT0, c); for (k = 0; k < n - 1; k++) { if (u < h.dur[k]) break; u -= h.dur[k]; } } if (h.blinkFrame >= 0) { if (now >= h.blinkEnd && now >= h.nextBlink && k == 0) { h.blinkEnd = now + h.blinkDur; h.nextBlink = now + UnityEngine.Random.Range(h.blinkMin, h.blinkMax); } if (now < h.blinkEnd && k == 0) k = h.blinkFrame; } var sp = h.frames[Mathf.Clamp(k, 0, h.frames.Length - 1)]; if (h.img.sprite != sp) h.img.sprite = sp; } void SpawnPuff(Hero h) { if (puffSprite == null || rowPuff == null) return; var r = h.row; float w = r.w * rowPuff.w; float hh = w * puffSprite.rect.height / puffSprite.rect.width; var img = ArtImage("Puff_" + h.id, Stage, null, r.x, r.y + r.h * rowPuff.c, w, hh); img.sprite = puffSprite; img.color = WithA(rowPuff.color, 0f); img.transform.SetSiblingIndex(h.rt.GetSiblingIndex() + 1); // 그 장수 바로 앞(발을 덮는 먼지 · QA r1 U4 = 뒤에 두면 바닥과 같은 색이라 안 보임) puffs.Add(new Puff { rt = img.rectTransform, img = img, t0 = clockNow, baseW = w }); } void UpdatePuffs(float now) { for (int i = puffs.Count - 1; i >= 0; i--) { var p = puffs[i]; float u = (now - p.t0) / Mathf.Max(0.05f, rowPuff.a); if (u >= 1f || p.img == null) { if (p.img != null) Destroy(p.img.gameObject); puffs.RemoveAt(i); continue; } float s = Mathf.Lerp(0.6f, 1.25f, 1f - (1f - u) * (1f - u)); p.rt.localScale = new Vector3(s, s, 1f); SetA(p.img, rowPuff.color, rowPuff.b * (1f - u)); } } } }