using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Unity.Profiling;
using UnityEngine;
using UnityEngine.UI;
namespace TKS
{
///
/// UI 층 구조 실측(PD 2026-11-10 캔버스 분할 검증) — 지금 화면의 렌더 통계(배치 · 드로우콜 · SetPass)와
/// 켜진 캔버스마다 그래픽 수 · 등급 · 레이캐스터 · 매 프레임 움직이는 요소(UiPulse · UiPop · 스크롤 내용 · 미니맵 · 커서)를 기록한다.
/// 「매 프레임 재구성 그래픽」 = 움직이는 요소가 든 캔버스들의 그래픽 수 합(캔버스는 자식 하나만 바뀌어도 전체를 다시 묶음).
///
public static class UiLayerProbe
{
static ProfilerRecorder batches;
static ProfilerRecorder draws;
static ProfilerRecorder setPass;
static void Begin()
{
if (!batches.Valid) batches = ProfilerRecorder.StartNew(ProfilerCategory.Render, "Batches Count");
if (!draws.Valid) draws = ProfilerRecorder.StartNew(ProfilerCategory.Render, "Draw Calls Count");
if (!setPass.Valid) setPass = ProfilerRecorder.StartNew(ProfilerCategory.Render, "SetPass Calls Count");
}
/// 몇 프레임 렌더 뒤 측정 → 로그 한 줄 + `ui_layers.csv`(캔버스별 행) 추가.
public static IEnumerator Measure(string shot, System.Action log, string dir)
{
Begin();
for (int i = 0; i < 4; i++) yield return null;
long b = batches.Valid ? batches.LastValue : -1;
long d = draws.Valid ? draws.LastValue : -1;
long sp = setPass.Valid ? setPass.LastValue : -1;
#if UNITY_EDITOR
if (b <= 0) b = UnityEditor.UnityStats.batches;
if (d <= 0) d = UnityEditor.UnityStats.drawCalls;
if (sp <= 0) sp = UnityEditor.UnityStats.setPassCalls;
#endif
var movers = Movers();
var frameCanvases = new HashSet