SHA256
111 lines
4.3 KiB
C#
111 lines
4.3 KiB
C#
using System;
|
|
using System.Text;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace ADOFAIRenderer.Component
|
|
{
|
|
public class DebugMonitorUI : MonoBehaviour
|
|
{
|
|
private Text _text = null!;
|
|
|
|
private void Start()
|
|
{
|
|
// UI 레이어(5) 설정
|
|
gameObject.layer = 5;
|
|
|
|
// Canvas 설정
|
|
var canvas = gameObject.AddComponent<Canvas>();
|
|
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
|
canvas.sortingOrder = 9999;
|
|
|
|
// 해상도 다이내믹 스케일링 설정 (Reference: 1920x1080)
|
|
var scaler = gameObject.AddComponent<CanvasScaler>();
|
|
scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
|
|
scaler.referenceResolution = new Vector2(1920, 1080);
|
|
scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight;
|
|
scaler.matchWidthOrHeight = 0.5f;
|
|
|
|
gameObject.AddComponent<GraphicRaycaster>();
|
|
|
|
// 배경 패널 생성
|
|
GameObject panelObj = new GameObject("BackgroundPanel");
|
|
panelObj.transform.SetParent(transform, false);
|
|
panelObj.layer = 5;
|
|
|
|
var image = panelObj.AddComponent<Image>();
|
|
image.color = new Color(0.08f, 0.08f, 0.1f, 0.88f); // 약간 더 고급스러운 다크톤 아크릴 감성
|
|
|
|
var panelRect = panelObj.GetComponent<RectTransform>();
|
|
panelRect.anchorMin = new Vector2(1, 1);
|
|
panelRect.anchorMax = new Vector2(1, 1);
|
|
panelRect.pivot = new Vector2(1, 1);
|
|
panelRect.anchoredPosition = new Vector2(-30, -30);
|
|
panelRect.sizeDelta = new Vector2(340, 250);
|
|
|
|
// 텍스트 생성
|
|
var textObj = new GameObject("MonitorText");
|
|
textObj.transform.SetParent(panelObj.transform, false);
|
|
textObj.layer = 5;
|
|
|
|
_text = textObj.AddComponent<Text>();
|
|
_text.supportRichText = true;
|
|
_text.fontSize = 13;
|
|
_text.lineSpacing = 1.3f;
|
|
_text.alignment = TextAnchor.UpperLeft;
|
|
|
|
// uGUI 특유의 텍스트 잘림 현상 원천 예방
|
|
_text.horizontalOverflow = HorizontalWrapMode.Wrap;
|
|
_text.verticalOverflow = VerticalWrapMode.Overflow;
|
|
|
|
var font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
|
|
if (font == null)
|
|
{
|
|
font = Resources.GetBuiltinResource<Font>("Arial.ttf");
|
|
}
|
|
if (font == null)
|
|
{
|
|
var fonts = Resources.FindObjectsOfTypeAll<Font>();
|
|
if (fonts.Length > 0) font = fonts[0];
|
|
}
|
|
_text.font = font;
|
|
|
|
RectTransform textRect = textObj.GetComponent<RectTransform>();
|
|
textRect.anchorMin = Vector2.zero;
|
|
textRect.anchorMax = Vector2.one;
|
|
textRect.offsetMin = new Vector2(20, 20); // 좀 더 넉넉하고 아름다운 패딩 여백
|
|
textRect.offsetMax = new Vector2(-20, -20);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!_text) return;
|
|
|
|
var sb = new StringBuilder();
|
|
sb.AppendLine("<b><color=#00ccff>ADOFAI Renderer Realtime Monitor</color></b>");
|
|
sb.AppendLine();
|
|
sb.AppendLine($"• Rendered Progress: <b>{RenderManager.FrameCount}</b> frames");
|
|
|
|
int queueCount;
|
|
lock (RenderManager.ImageQueue)
|
|
{
|
|
queueCount = RenderManager.ImageQueue.Count;
|
|
}
|
|
sb.AppendLine($"• Queued Buffers: <b>{queueCount}</b> / 60 frames");
|
|
|
|
sb.AppendLine(RenderMod.IsThrottling
|
|
? "• Status: <b><color=yellow>THROTTLING (Safe Mode)</color></b>"
|
|
: "• Status: <b><color=green>NORMAL (Encoding)</color></b>");
|
|
sb.AppendLine();
|
|
sb.AppendLine($"• Throttling Controls: {RenderMod.ThrottleCount} times");
|
|
sb.AppendLine($"• Readback Hard Failures: <color=#ff3333>{RenderMod.ReadbackFailureCount}</color> times");
|
|
sb.AppendLine($"• Render Skip-Retry: {RenderMod.SkipCount} / 60");
|
|
|
|
var memoryMb = GC.GetTotalMemory(false) / (1024.0 * 1024.0);
|
|
sb.AppendLine($"• Mono Heap Memory: {memoryMb:F2} MB");
|
|
|
|
_text.text = sb.ToString();
|
|
}
|
|
}
|
|
}
|