ThreeKingdomsSlingshot/Assets/Scripts/OutGame/TitleCaptureDriver.cs

173 lines
9.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace TKS.OutGame
{
/// <summary>
/// 타이틀 화면 검증 캡처(PD 2026-11-13 · 에디터 TKS.EditorTools.TitleCapture.Capture 가 SessionState 로 출력 폴더를 넘기면 생성 · 메모리 세이브).
/// 등장 연출(연출 시계를 정해 찍음) · 끝 모습 1080×1920 · 화면비 1080×2400 · 1536×2048 · 대기 움직임 연속(실시간) · 누름 → 로비 확인 · 끝나면 스스로 종료.
/// UICaptureDriver(다른 세션 작업 중)와 따로 둔다.
/// </summary>
public class TitleCaptureDriver : MonoBehaviour
{
public const string DirKey = "TKS_TITLE_CAPTURE_DIR";
public string OutputDir;
readonly List<string> log = new List<string>();
#if UNITY_EDITOR
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
static void AutoSpawn()
{
string dir = UnityEditor.SessionState.GetString(DirKey, "");
if (string.IsNullOrEmpty(dir)) return;
UnityEditor.SessionState.EraseString(DirKey);
TitleSceneBoot.SuppressAutoShow = true; // 타이틀은 이 드라이버가 띄움(Title 씬 자동 표시 끔)
TitleScreen.IgnoreInput = true; // 캡처 창이 받은 키 입력으로 먼저 닫히지 않게(누름 = Press())
var go = new GameObject("TitleCaptureDriver");
DontDestroyOnLoad(go); // 누름 → Battle 씬 · Splash → Title 씬을 지나며 계속 찍음
go.AddComponent<TitleCaptureDriver>().OutputDir = dir;
}
#endif
IEnumerator Start()
{
Directory.CreateDirectory(OutputDir);
yield return null;
yield return null;
var cam = Camera.main;
if (cam == null)
{
Log("FAIL: 카메라 없음");
Finish(1);
yield break;
}
bool started = false;
TitleScreen.ForceShow = true;
TitleScreen.FixedClock = true; // 정지 장면 = 표기 시각 그대로(Update 가 실시간을 더하지 않음 · 7~9차 등장이 1.55 초로 짧아 0.1 초 어긋남이 큼)
var ts = TitleScreen.Show(cam, () => started = true);
Log("heroes=" + ts.Heroes.Count + " introEnd=" + ts.IntroEnd.ToString("0.00") + " provider=" + (BootFlow.TitleProvider != null));
// 등장 연출 — 연출 시계를 정해 한 장씩(캡처 시간에 흔들리지 않게)
float[] at = { 0.2f, 0.4f, 0.55f, 0.65f, 0.7f, 0.8f, 0.9f, 1.0f, 1.05f, 1.12f, 1.2f, 1.3f, 1.45f, 1.9f }; // 10차 Fable 시안 — 0.65 청룡·백호 부딪힘 → 판이 밀어냄 → 1.05 박힘·제목 쾅·번쩍임 → 장수 쑥 → 끝 ≈ 1.51 s
int i = 1;
foreach (var t in at)
{
ts.SetTime(t);
yield return null;
yield return CaptureUtil.Capture(cam, 1080, 1920, Path.Combine(OutputDir, "intro_" + (i++).ToString("00") + "_" + t.ToString("0.00") + ".png"));
}
ts.SetTime(ts.IntroEnd + 1.2f);
TitleScreen.FixedClock = false; // 구조 측정·대기·실시간 영상 = 실제 시계
yield return null;
yield return UiLayerProbe.Measure("title", Log, OutputDir);
yield return CaptureUtil.Capture(cam, 1080, 1920, Path.Combine(OutputDir, "title_1080x1920.png"));
yield return CaptureUtil.Capture(cam, 1080, 2400, Path.Combine(OutputDir, "title_1080x2400.png"));
yield return CaptureUtil.Capture(cam, 1536, 2048, Path.Combine(OutputDir, "title_1536x2048.png"));
// 대기 움직임(실시간 · 약 0.12 초 간격) — 실제 간격을 로그에 남김
float t0 = Time.unscaledTime;
for (int k = 0; k < 24; k++)
{
yield return CaptureUtil.Capture(cam, 540, 960, Path.Combine(OutputDir, "idle_" + k.ToString("00") + ".png"));
Log("idle " + k + " t=" + (Time.unscaledTime - t0).ToString("0.000"));
float w = Time.unscaledTime + 0.12f;
while (Time.unscaledTime < w) yield return null;
}
// 확인 영상(고정 시계 30fps · 원본 크기) — 연출 시계를 1/30 초씩 정해 찍음(캡처가 느려도 끊기지 않음 · 대기·먼지도 같은 시계)
ts.Close();
yield return null;
TitleScreen.FixedClock = true;
ts = TitleScreen.Show(cam, () => started = true);
string fdir = Path.Combine(OutputDir, "video30");
Directory.CreateDirectory(fdir);
int fn = Mathf.CeilToInt((ts.IntroEnd + 3f) * 30f);
for (int k = 0; k <= fn; k++)
{
ts.SetTime(k / 30f);
yield return null;
yield return CaptureUtil.Capture(cam, 1080, 1920, Path.Combine(fdir, "f" + k.ToString("000") + ".png"));
}
TitleScreen.FixedClock = false;
Log("video30 frames=" + (fn + 1) + " seconds=" + (fn / 30f).ToString("0.00"));
// 확인 영상용 실시간 연속(처음부터 다시 띄워 등장 → 대기 약 4 초 · 원본 크기 · 찍힌 실제 시각을 로그에 = 영상 프레임 길이)
ts.Close();
yield return null;
ts = TitleScreen.Show(cam, () =>
{
started = true;
TitleSceneBoot.GoToGame(); // 실제 흐름 = 검정에서 Battle 씬(본영 로비)
});
string vdir = Path.Combine(OutputDir, "video");
Directory.CreateDirectory(vdir);
float v0 = Time.unscaledTime;
var vlog = new List<string>();
for (int k = 0; Time.unscaledTime - v0 < ts.IntroEnd + 4f && k < 400; k++)
{
float vt = Time.unscaledTime - v0;
yield return CaptureUtil.Capture(cam, 1080, 1920, Path.Combine(vdir, "v" + k.ToString("000") + ".png"));
vlog.Add(k + "," + vt.ToString("0.000", System.Globalization.CultureInfo.InvariantCulture));
}
File.WriteAllLines(Path.Combine(vdir, "times.csv"), vlog.ToArray());
Log("video frames=" + vlog.Count + " seconds=" + (Time.unscaledTime - v0).ToString("0.00"));
if (ts == null)
{
Log("FAIL: 누르기 전에 타이틀이 닫힘(외부 입력?)");
Finish(1);
yield break;
}
ts.SkipIntro();
float ready = Time.unscaledTime + 2f;
while (!ts.PressReady && Time.unscaledTime < ready) yield return null;
// 누름 → 페이드 → 로비
ts.Press();
float until = Time.unscaledTime + 4f;
while (!started && Time.unscaledTime < until) yield return null;
// 누름 → 타이틀 페이드(검정) → Battle 씬 → 페이드 인(씬 바꿈 덮개가 사라질 때까지)
until = Time.unscaledTime + 10f;
while ((SceneSwitch.Current != null || SceneManager.GetActiveScene().name != BootScenes.Game) && Time.unscaledTime < until) yield return null;
bool inGame = SceneManager.GetActiveScene().name == BootScenes.Game;
Log("pressed → started=" + started + " titleGone=" + (TitleScreen.Current == null) + " scene=" + SceneManager.GetActiveScene().name);
yield return new WaitForSecondsRealtime(0.3f);
cam = Camera.main;
if (cam != null) yield return CaptureUtil.Capture(cam, 1080, 1920, Path.Combine(OutputDir, "after_press.png"));
// 시작 흐름 확인: Splash 씬(회사 CI · CDN 확인) → Title 씬(자동 표시)
TitleSceneBoot.SuppressAutoShow = false;
TitleScreen.ForceShow = false;
SceneManager.LoadScene(BootScenes.Splash);
until = Time.unscaledTime + 6f;
while ((SplashBoot.Current == null || SplashBoot.Current.CiPeak < 0.999f) && Time.unscaledTime < until) yield return null;
bool ciShown = SplashBoot.Current != null && SplashBoot.Current.CiPeak >= 0.999f;
if (ciShown && Camera.main != null) yield return CaptureUtil.Capture(Camera.main, 1080, 1920, Path.Combine(OutputDir, "splash_ci.png"));
until = Time.unscaledTime + 10f;
while ((SceneManager.GetActiveScene().name != BootScenes.Title || TitleScreen.Current == null || SceneSwitch.Current != null) && Time.unscaledTime < until) yield return null;
bool titleScene = SceneManager.GetActiveScene().name == BootScenes.Title && TitleScreen.Current != null;
Log("splash → ciShown=" + ciShown + " → titleScene=" + titleScene);
Finish(started && inGame && ciShown && titleScene ? 0 : 1);
}
void Log(string s)
{
log.Add(s);
Debug.Log("[TitleCapture] " + s);
try
{
File.WriteAllLines(Path.Combine(OutputDir, "capture_log.txt"), log.ToArray());
}
catch
{
}
}
void Finish(int code)
{
Log("finish code=" + code);
#if UNITY_EDITOR
UnityEditor.EditorApplication.Exit(code);
#else
Application.Quit(code);
#endif
}
}
}