Project_WL/AgentScripts/WL816j2_Which.cs

112 lines
5.6 KiB
C#

// WL-816j2 — ⑤ 바다의 흰 격자선을 만드는 속성이 무엇인지 **색으로 찍어서** 가려낸다
using System.Collections;
using System.Text;
using UnityEngine;
public static class WL816j2_Which
{
public const string D = "Screenshots_WL/WL816j2/";
public static void Start()
{
var go = GameObject.Find("~WL816j2W");
if (go != null) Object.DestroyImmediate(go);
go = new GameObject("~WL816j2W");
go.AddComponent<WL816j2_WhichRunner>();
}
}
public class WL816j2_WhichRunner : MonoBehaviour
{
static StringBuilder sb;
static void L(string s) { sb.AppendLine(s); }
const string D = WL816j2_Which.D;
const int PW = 1280, PH = 720;
const string C_Light = "Color_1ec6cccf8ead489ebb917674f7e8b3b1";
const string C_FoamShadow = "Color_2323d69962e04c499c5d5f0925432b55";
const string C_Water = "Color_9af4ad59934f40d1ae6565e6ab22c45e";
const string C_Dark = "Color_ca031ae309ff42bdb95f777248fb961d";
const string C_Foam = "Color_e1f155248d144786a62fc1585ca21e9a";
const string R_FoamEdge = "Vector1_34f757bec6b8422b9aef3b9d97117a6e";
const string R_FoamDistance = "Vector1_101dc4546b684d40bc2ff2fc59ab43d5";
const string R_DeepDistance = "Vector1_566e288f42864b8e9432d81fbdb83f38";
const string R_Height = "Vector1_d813b569a4d541d1b2ac4ea9bc66a3b9";
void Start() { StartCoroutine(Co()); }
string Shot(Camera cam, string path)
{
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path));
var rt = new RenderTexture(PW, PH, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
rt.antiAliasing = 1; rt.Create();
var pT = cam.targetTexture; var pA = RenderTexture.active;
cam.targetTexture = rt; cam.Render(); RenderTexture.active = rt;
var t = new Texture2D(PW, PH, TextureFormat.RGB24, false);
t.ReadPixels(new Rect(0, 0, PW, PH), 0, 0); t.Apply();
RenderTexture.active = pA; cam.targetTexture = pT; rt.Release(); Object.DestroyImmediate(rt);
System.IO.File.WriteAllBytes(path, t.EncodeToPNG());
// 바다만 있는 구역에서 가장 밝은/어두운 픽셀의 색
var px = t.GetPixels32();
int bi = 0, di = 0; float bl = -1, dl = 2;
for (int y = 20; y < 320; y += 2)
for (int x = 20; x < 340; x += 2)
{
int k = y * PW + x; var c = px[k];
float l = (0.299f * c.r + 0.587f * c.g + 0.114f * c.b) / 255f;
if (l > bl) { bl = l; bi = k; }
if (l < dl) { dl = l; di = k; }
}
var b2 = px[bi]; var d2 = px[di];
Object.DestroyImmediate(t);
return "밝은점 #" + b2.r.ToString("X2") + b2.g.ToString("X2") + b2.b.ToString("X2")
+ " 어두운점 #" + d2.r.ToString("X2") + d2.g.ToString("X2") + d2.b.ToString("X2") + " → " + path;
}
IEnumerator Co()
{
sb = new StringBuilder();
L("=== WL-816j2 ⑤ 격자선의 정체 (색으로 찍기) ===");
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;
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 (c.name.StartsWith("~WL816")) continue;
if (live == null || c.depth > live.depth) live = c;
}
if (water == null || live == null) { L("🔴 없음"); Done(); yield break; }
var E = UnityEditor.AssetDatabase.LoadAssetAtPath<Material>("Assets/WL/Look/Farm/Materials/Farm_Water_WL_E.mat");
// ① 색 찍기 — LightColor=초록 · FoamShadowColor=파랑 · FoamColor=빨강 · Water=흰 · Dark=검
var m = new Material(E);
m.SetColor(C_Water, Color.white); m.SetColor(C_Dark, Color.black);
m.SetColor(C_Light, Color.green); m.SetColor(C_FoamShadow, Color.blue); m.SetColor(C_Foam, Color.red);
water.sharedMaterial = m; yield return null; yield return new WaitForSeconds(0.3f);
L("1) Light=초록 Shadow=파랑 Foam=빨강 Water=흰 Dark=검 " + Shot(live, D + "k_which_paint.png"));
// ② 하나씩 끄기
var tests = new (string, System.Action<Material>)[]
{
("기준(E 그대로)", mm => { }),
("FoamEdge 100(가장자리 거품 완전 off)", mm => mm.SetFloat(R_FoamEdge, 100f)),
("LightColor = WaterColor", mm => mm.SetColor(C_Light, mm.GetColor(C_Water))),
("FoamShadowColor = 흰색", mm => mm.SetColor(C_FoamShadow, Color.white)),
("셋 다", mm => { mm.SetFloat(R_FoamEdge, 100f); mm.SetColor(C_Light, mm.GetColor(C_Water)); mm.SetColor(C_FoamShadow, Color.white); }),
("셋 다 + Height 0(버텍스 파도 off)", mm => { mm.SetFloat(R_FoamEdge, 100f); mm.SetColor(C_Light, mm.GetColor(C_Water)); mm.SetColor(C_FoamShadow, Color.white); mm.SetFloat(R_Height, 0f); }),
};
for (int i = 0; i < tests.Length; i++)
{
var mm = new Material(E); tests[i].Item2(mm);
water.sharedMaterial = mm; yield return null; yield return new WaitForSeconds(0.25f);
L((i + 2) + ") " + tests[i].Item1 + " " + Shot(live, D + "k_off" + i + ".png"));
}
Done();
}
void Done()
{
System.IO.File.WriteAllText("AgentScripts/WL816j2_WHICH.txt", sb.ToString());
Debug.Log("[816j2 which]\n" + sb);
}
}