Project_WL/AgentScripts/WL816a_PlayCap.cs

73 lines
4.1 KiB
C#

// WL-816a — Play 중 오프스크린 캡처 + 룩 진단 (배치모드 헤드리스에서도 동작)
public static class WL816a_PlayCap
{
const string Dir = "Screenshots_WL/WL816a/";
const int W = 1080, H = 1920;
public static void Run()
{
var sb = new System.Text.StringBuilder();
sb.AppendLine("isPlaying=" + UnityEngine.Application.isPlaying);
sb.AppendLine("FarmLook : mode=" + WL.Look.Farm.WLFarmLook.AppliedMode + " · " + WL.Look.Farm.WLFarmLook.LastLog);
sb.AppendLine("RefLook : applied=" + WL.Look.Arena.WLReferenceLook.IsApplied
+ " · outlined=" + WL.Look.Arena.WLReferenceLook.OutlinedRenderers
+ " · contrastMat=" + WL.Look.Arena.WLReferenceLook.ContrastMaterials
+ " · rim=" + WL.Look.Arena.WLReferenceLook.RimRenderers
+ " · " + WL.Look.Arena.WLReferenceLook.LastLog);
sb.AppendLine("ambient : " + UnityEngine.RenderSettings.ambientMode + " " + UnityEngine.RenderSettings.ambientLight
+ " · skybox=" + (UnityEngine.RenderSettings.skybox != null ? UnityEngine.RenderSettings.skybox.name : "없음"));
var ls = UnityEngine.Object.FindObjectsByType<UnityEngine.Light>(UnityEngine.FindObjectsInactive.Exclude, UnityEngine.FindObjectsSortMode.None);
for (int i = 0; i < ls.Length; i++)
sb.AppendLine("light : " + ls[i].name + " " + ls[i].type + " " + ls[i].color + " I=" + ls[i].intensity + " " + ls[i].shadows);
Shot(FindCam("MainCamera"), Dir + "p_play_main.png");
Shot(DemoAngleCam(), Dir + "p_play_demoangle.png");
sb.AppendLine("캡처 p_play_main.png · p_play_demoangle.png");
UnityEngine.Debug.Log("[WL816a PlayCap]\n" + sb.ToString());
}
static UnityEngine.Camera DemoAngleCam()
{
var go = UnityEngine.GameObject.Find("__WL816aDemoAngle");
if (go == null) { go = new UnityEngine.GameObject("__WL816aDemoAngle"); go.hideFlags = UnityEngine.HideFlags.DontSave; }
var c = go.GetComponent<UnityEngine.Camera>();
if (c == null) c = go.AddComponent<UnityEngine.Camera>();
c.orthographic = true; c.orthographicSize = 10f;
c.nearClipPlane = 0.3f; c.farClipPlane = 500f;
c.clearFlags = UnityEngine.CameraClearFlags.Skybox;
c.backgroundColor = new UnityEngine.Color(0.192f, 0.302f, 0.475f, 0f);
c.depth = -100f;
var rot = UnityEngine.Quaternion.Euler(30f, 60f, 0f);
go.transform.rotation = rot;
go.transform.position = new UnityEngine.Vector3(0f, 0.6f, 0f) - rot * UnityEngine.Vector3.forward * 60f;
if (go.GetComponent<UnityEngine.Rendering.Universal.UniversalAdditionalCameraData>() == null)
go.AddComponent<UnityEngine.Rendering.Universal.UniversalAdditionalCameraData>();
return c;
}
static UnityEngine.Camera FindCam(string name)
{
var cams = UnityEngine.Object.FindObjectsByType<UnityEngine.Camera>(
UnityEngine.FindObjectsInactive.Exclude, UnityEngine.FindObjectsSortMode.None);
for (int i = 0; i < cams.Length; i++) if (cams[i].name == name) return cams[i];
return cams.Length > 0 ? cams[0] : null;
}
static void Shot(UnityEngine.Camera cam, string path)
{
if (cam == null) return;
var rt = new UnityEngine.RenderTexture(W, H, 24, UnityEngine.RenderTextureFormat.ARGB32, UnityEngine.RenderTextureReadWrite.sRGB);
rt.antiAliasing = 1;
var pT = cam.targetTexture; var pA = UnityEngine.RenderTexture.active;
cam.targetTexture = rt; cam.Render();
UnityEngine.RenderTexture.active = rt;
var tex = new UnityEngine.Texture2D(W, H, UnityEngine.TextureFormat.RGB24, false);
tex.ReadPixels(new UnityEngine.Rect(0, 0, W, H), 0, 0); tex.Apply();
UnityEngine.RenderTexture.active = pA; cam.targetTexture = pT;
var d = System.IO.Path.GetDirectoryName(path);
if (!System.IO.Directory.Exists(d)) System.IO.Directory.CreateDirectory(d);
System.IO.File.WriteAllBytes(path, UnityEngine.ImageConversion.EncodeToPNG(tex));
UnityEngine.Object.DestroyImmediate(tex); UnityEngine.Object.DestroyImmediate(rt);
}
}