Project_WL/AgentScripts/WL816h_Probe2.cs

144 lines
7.1 KiB
C#
Raw Normal View History

// WL-816h — ② 「쨍한 파란 하늘」의 정체 + 섬에서 나간 뒤 하늘 오염 실측 (지금 상태 = 고치기 전)
using System.Collections;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.SceneManagement;
public static class WL816h_Probe2
{
public const string Dir = "Screenshots_WL/WL816h/";
public const int W = 1080, H = 1920;
public static void Start()
{
var go = GameObject.Find("~WL816hProbe2");
if (go != null) Object.DestroyImmediate(go);
go = new GameObject("~WL816hProbe2");
go.AddComponent<WL816h_Probe2Runner>();
Debug.Log("[816h p2] 러너 시작");
}
public static string SkyLine()
{
return "amb=" + RenderSettings.ambientMode + " light=" + F(RenderSettings.ambientLight)
+ " skySrc=" + F(RenderSettings.ambientSkyColor) + " I=" + RenderSettings.ambientIntensity
+ " skybox=" + (RenderSettings.skybox ? RenderSettings.skybox.name : "없음")
+ " fog=" + RenderSettings.fog + " refl=" + RenderSettings.defaultReflectionMode + "/" + RenderSettings.reflectionIntensity
+ " sun=" + (RenderSettings.sun ? RenderSettings.sun.name : "없음");
}
public static string F(Color c) { return "(" + c.r.ToString("F3") + "," + c.g.ToString("F3") + "," + c.b.ToString("F3") + ")"; }
public static Camera SkyCam()
{
var go = GameObject.Find("~WL816hSkyCam2");
if (go == null) { go = new GameObject("~WL816hSkyCam2"); go.hideFlags = HideFlags.DontSave; }
var c = go.GetComponent<Camera>(); if (c == null) c = go.AddComponent<Camera>();
c.orthographic = false; c.fieldOfView = 50f; c.nearClipPlane = 0.3f; c.farClipPlane = 2000f;
c.clearFlags = CameraClearFlags.Skybox; c.cullingMask = ~0; c.depth = -100f;
go.transform.position = new Vector3(0f, 40f, 0f);
go.transform.rotation = Quaternion.Euler(-16f, 30f, 0f);
if (go.GetComponent<UniversalAdditionalCameraData>() == null) go.AddComponent<UniversalAdditionalCameraData>();
return c;
}
public static string Shot(Camera cam, string path)
{
if (cam == null) return "카메라 없음";
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path));
var rt = new RenderTexture(W, H, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
rt.antiAliasing = 1; rt.Create();
var prevT = cam.targetTexture; var prevA = RenderTexture.active;
cam.targetTexture = rt; cam.Render(); RenderTexture.active = rt;
var tex = new Texture2D(W, H, TextureFormat.RGB24, false);
tex.ReadPixels(new Rect(0, 0, W, H), 0, 0); tex.Apply();
RenderTexture.active = prevA; cam.targetTexture = prevT;
System.IO.File.WriteAllBytes(path, tex.EncodeToPNG());
// 위 10 % · 아래 10 % 평균
string s = "";
s += "상단10%=" + Band(tex, 0.90f, 1.00f) + " 하단10%=" + Band(tex, 0.00f, 0.10f);
Object.DestroyImmediate(tex); rt.Release(); Object.DestroyImmediate(rt);
return s + " → " + path;
}
static string Band(Texture2D t, float y0, float y1)
{
int a = Mathf.RoundToInt(y0 * (t.height - 1)), b = Mathf.RoundToInt(y1 * (t.height - 1));
long r = 0, g = 0, bl = 0; int n = 0;
var px = t.GetPixels32();
for (int y = a; y < b; y += 4)
for (int x = 0; x < t.width; x += 4) { var c = px[y * t.width + x]; r += c.r; g += c.g; bl += c.b; n++; }
if (n == 0) return "-";
return "#" + ((int)(r / n)).ToString("X2") + ((int)(g / n)).ToString("X2") + ((int)(bl / n)).ToString("X2");
}
}
public class WL816h_Probe2Runner : MonoBehaviour
{
static System.Text.StringBuilder sb;
static void L(string s) { sb.AppendLine(s); }
void Start() { StartCoroutine(Co()); }
IEnumerator Co()
{
sb = new System.Text.StringBuilder();
L("=== ② 「파란 하늘」의 정체 + 섬 나간 뒤 오염 (고치기 전) ===");
Camera live = null;
foreach (var c in Object.FindObjectsByType<Camera>(FindObjectsInactive.Exclude, FindObjectsSortMode.None))
{
if (!c.gameObject.activeInHierarchy || !c.enabled || c.targetTexture != null) continue;
if (live == null || c.depth > live.depth) live = c;
}
L("보이는 카메라 = " + (live == null ? "없음" : live.name + " fov=" + live.fieldOfView
+ " euler=" + live.transform.eulerAngles.ToString("F0") + " pos=" + live.transform.position.ToString("F1")));
Renderer water = null;
foreach (var r in Object.FindObjectsByType<Renderer>(FindObjectsInactive.Exclude, FindObjectsSortMode.None))
if (r != null && r.gameObject.scene.name == "Level01" && r.name == "Water") water = r;
L("물 렌더러 = " + (water == null ? "없음" : water.name + " mat=" + water.sharedMaterial.name
+ " shader=" + water.sharedMaterial.shader.name));
L("물 ON = " + WL816h_Probe2.Shot(live, WL816h_Probe2.Dir + "a1_water_on.png"));
if (water != null) water.enabled = false;
yield return null;
L("물 OFF = " + WL816h_Probe2.Shot(live, WL816h_Probe2.Dir + "a2_water_off.png"));
if (water != null) water.enabled = true;
yield return null;
L("");
L("섬 내리기 전 : " + WL816h_Probe2.SkyLine());
var op = SceneManager.UnloadSceneAsync("Level01");
while (op != null && !op.isDone) yield return null;
yield return new WaitForSeconds(1.5f);
L("섬 내린 뒤 : " + WL816h_Probe2.SkyLine());
L("InGame 원본 : amb=Skybox light=(0.212,0.227,0.259) skybox=Default-Skybox fog=False refl=Skybox/1 sun=없음 (씬 파일 실측)");
L("🔴 오염 = " + Diff());
var op2 = SceneManager.LoadSceneAsync("Map_C01", LoadSceneMode.Additive);
while (op2 != null && !op2.isDone) yield return null;
yield return new WaitForSeconds(1.5f);
L("");
L("전투 맵(Map_C01) 올린 뒤 : " + WL816h_Probe2.SkyLine());
L("🔴 오염 = " + Diff());
L("전투맵 하늘 = " + WL816h_Probe2.Shot(WL816h_Probe2.SkyCam(), WL816h_Probe2.Dir + "f0_before_battle_sky.png"));
System.IO.File.WriteAllText("AgentScripts/WL816h_PROBE2.txt", sb.ToString());
Debug.Log("[816h p2 완료]\n" + sb);
}
static string Diff()
{
string d = "";
if (RenderSettings.ambientMode != AmbientMode.Skybox) d += "ambientMode=" + RenderSettings.ambientMode + "(원본 Skybox) · ";
var a = RenderSettings.ambientLight;
if (Mathf.Abs(a.r - 0.212f) > 0.004f || Mathf.Abs(a.g - 0.227f) > 0.004f || Mathf.Abs(a.b - 0.259f) > 0.004f)
d += "ambientLight=" + WL816h_Probe2.F(a) + "(원본 (0.212,0.227,0.259)) · ";
if (RenderSettings.fog) d += "fog on · ";
if (RenderSettings.sun != null) d += "sun=" + RenderSettings.sun.name + "(원본 없음) · ";
if (RenderSettings.skybox == null || RenderSettings.skybox.name != "Default-Skybox")
d += "skybox=" + (RenderSettings.skybox ? RenderSettings.skybox.name : "없음") + " · ";
return d.Length == 0 ? "없음(오염 0)" : d;
}
}