Project_WL/AgentScripts/WL806_Popup.cs

102 lines
6.1 KiB
C#
Raw Normal View History

// WL806_Popup.cs — 후속 B: SortOrder_5.prefab/PopupUI(공용 Popup 싱글톤) 를 세로 화면에서 터치·가독 가능한 크기로 (에디트 모드 · 프리팹 컨텐츠 · Play 불필요)
// unity command run_script --file AgentScripts/WL806_Popup.cs --entry WL806_Popup.Dump
// unity command run_script --file AgentScripts/WL806_Popup.cs --entry WL806_Popup.Apply
// unity command run_script --file AgentScripts/WL806_Popup.cs --entry WL806_Popup.Revert (2026-09-07 이전 원값)
// 배경(실측 Dump 2026-09-07): 캔버스 1920×1080 Expand → 세로 1080×1920 에서 scaleFactor 0.5625.
// 원값: bg 428×311 · msg 400×165 (0,30) fs20 · btn_ok 116×56 (0,-102) fs20 → 실화면 bg 241×175 px · 글자 11 px · 버튼 65×32 px (터치·가독 미달).
// 목표: TitleInfo 팝업(#794 · 1080 기준 bg 860×520 · msg 780×280 (0,70) · btn_ok 340×130 (0,-150)) 과 같은 실크기 → 1920 기준 유닛 = px / 0.5625.
// 글자: 로딩 화면(#800) 과 같은 실화면 ≈27 px → fs 48.
using System.Text;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
public static class WL806_Popup
{
const string PrefabPath = "Assets/ResWork/UIPrefabs/Title/SortOrder_5.prefab";
// 1920×1080 기준 유닛 (px / 0.5625)
static readonly Vector2 BgSize = new Vector2(1529f, 924f);
static readonly Vector2 MsgSize = new Vector2(1387f, 498f); static readonly Vector2 MsgPos = new Vector2(0f, 124f);
static readonly Vector2 BtnSize = new Vector2(604f, 231f); static readonly Vector2 BtnPos = new Vector2(0f, -267f);
const float FontSize = 48f;
// 원값
static readonly Vector2 BgSize0 = new Vector2(428f, 311f);
static readonly Vector2 MsgSize0 = new Vector2(400f, 165f); static readonly Vector2 MsgPos0 = new Vector2(0f, 30f);
static readonly Vector2 BtnSize0 = new Vector2(116f, 56f); static readonly Vector2 BtnPos0 = new Vector2(0f, -102f);
const float FontSize0 = 20f;
static void Walk(Transform t, string path, StringBuilder sb, int depth)
{
var rt = t as RectTransform;
if (rt != null)
{
var txt = t.GetComponent<Text>();
var tmp = t.GetComponent<TMPro.TextMeshProUGUI>();
string font = txt != null ? (" Text fs=" + txt.fontSize + " bestFit=" + txt.resizeTextForBestFit)
: tmp != null ? (" TMP fs=" + tmp.fontSize + " auto=" + tmp.enableAutoSizing + " wrap=" + tmp.textWrappingMode + " overflow=" + tmp.overflowMode) : "";
var img = t.GetComponent<Image>();
string im = img != null ? (" Image=" + (img.sprite != null ? img.sprite.name : "null") + " type=" + img.type) : "";
var btn = t.GetComponent<Button>();
sb.AppendLine(new string(' ', depth * 2) + path + (t.gameObject.activeSelf ? "" : " (inactive)")
+ " | size=" + rt.sizeDelta + " pos=" + rt.anchoredPosition + " aMin=" + rt.anchorMin + " aMax=" + rt.anchorMax + " pivot=" + rt.pivot
+ (btn != null ? " [Button]" : "") + im + font);
}
for (int i = 0; i < t.childCount; i++) Walk(t.GetChild(i), path + "/" + t.GetChild(i).name, sb, depth + 1);
}
static RectTransform FindPopup(GameObject root)
{
foreach (var rt in root.GetComponentsInChildren<RectTransform>(true)) if (rt.name == "PopupUI") return rt;
return null;
}
public static object Dump()
{
var root = PrefabUtility.LoadPrefabContents(PrefabPath);
try
{
var sb = new StringBuilder();
var scaler = root.GetComponentInChildren<CanvasScaler>(true);
if (scaler != null) sb.AppendLine("CanvasScaler ref=" + scaler.referenceResolution + " mode=" + scaler.uiScaleMode + " match=" + scaler.matchWidthOrHeight + " screenMatch=" + scaler.screenMatchMode);
var popup = FindPopup(root);
if (popup == null) return "PopupUI not found";
Walk(popup, "PopupUI", sb, 0);
return sb.ToString();
}
finally { PrefabUtility.UnloadPrefabContents(root); }
}
static object Set(Vector2 bg, Vector2 msg, Vector2 msgPos, Vector2 btn, Vector2 btnPos, float fs, string tag)
{
var root = PrefabUtility.LoadPrefabContents(PrefabPath);
try
{
var popup = FindPopup(root);
if (popup == null) return "PopupUI not found";
var child = popup.Find("child");
if (child == null) return "PopupUI/child not found";
var bgRt = child.Find("bg") as RectTransform;
var msgRt = child.Find("msg") as RectTransform;
var btnRt = child.Find("btn_ok") as RectTransform;
var nameRt = btnRt != null ? btnRt.Find("btnName") : null;
if (bgRt == null || msgRt == null || btnRt == null) return "bg/msg/btn_ok missing";
var sb = new StringBuilder(tag + "\n");
sb.AppendLine("bg " + bgRt.sizeDelta + " -> " + bg); bgRt.sizeDelta = bg;
sb.AppendLine("msg " + msgRt.sizeDelta + msgRt.anchoredPosition + " -> " + msg + msgPos); msgRt.sizeDelta = msg; msgRt.anchoredPosition = msgPos;
sb.AppendLine("btn " + btnRt.sizeDelta + btnRt.anchoredPosition + " -> " + btn + btnPos); btnRt.sizeDelta = btn; btnRt.anchoredPosition = btnPos;
var msgT = msgRt.GetComponent<TMPro.TextMeshProUGUI>();
if (msgT != null) { sb.AppendLine("msg fs " + msgT.fontSize + " -> " + fs); msgT.fontSize = fs; }
var nameT = nameRt != null ? nameRt.GetComponent<TMPro.TextMeshProUGUI>() : null;
if (nameT != null) { sb.AppendLine("btnName fs " + nameT.fontSize + " -> " + fs); nameT.fontSize = fs; }
PrefabUtility.SaveAsPrefabAsset(root, PrefabPath);
AssetDatabase.SaveAssets();
return sb.ToString();
}
finally { PrefabUtility.UnloadPrefabContents(root); }
}
public static object Apply() { return Set(BgSize, MsgSize, MsgPos, BtnSize, BtnPos, FontSize, "APPLY portrait-size popup"); }
public static object Revert() { return Set(BgSize0, MsgSize0, MsgPos0, BtnSize0, BtnPos0, FontSize0, "REVERT original popup"); }
}