Project_WL/AgentScripts/WL816j2_Sweep.cs

100 lines
4.6 KiB
C#

// WL-816j2 — ⑥ 격자선 세기를 실제로 낮추는 값 찾기 (PD 구도 · 6단 스윕 · 평균 바다색은 유지)
using System.Collections;
using System.Text;
using UnityEngine;
public static class WL816j2_Sweep
{
public const string D = "Screenshots_WL/WL816j2/";
public static void Start()
{
var go = GameObject.Find("~WL816j2S");
if (go != null) Object.DestroyImmediate(go);
go = new GameObject("~WL816j2S");
go.AddComponent<WL816j2_SweepRunner>();
}
}
public class WL816j2_SweepRunner : MonoBehaviour
{
static StringBuilder sb;
static void L(string s) { sb.AppendLine(s); }
const string D = WL816j2_Sweep.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 R_DeepDistance = "Vector1_566e288f42864b8e9432d81fbdb83f38";
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();
long r = 0, g = 0, b = 0; int n = 0;
for (int y = 20; y < 320; y += 2)
for (int x = 20; x < 340; x += 2) { var c = px[y * PW + x]; r += c.r; g += c.g; b += c.b; n++; }
Object.DestroyImmediate(t);
return "바다 평균 #" + ((int)(r / n)).ToString("X2") + ((int)(g / n)).ToString("X2") + ((int)(b / n)).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");
Color W = E.GetColor(C_Water), Dk = E.GetColor(C_Dark);
L("816h 채택색 WaterColor " + W + " DarkColor " + Dk);
var names = new string[]
{
"0 기준 E",
"1 Shadow=0.30 회색",
"2 Shadow=흰색",
"3 Dark→Water 50%",
"4 Dark→Water 75%",
"5 Dark→Water 75% + Light=Water + Shadow=흰색",
"6 Dark→Water 90% + Light=Water + Shadow=흰색",
};
for (int i = 0; i < names.Length; i++)
{
var m = new Material(E);
if (i == 1) m.SetColor(C_FoamShadow, new Color(0.30f, 0.30f, 0.30f, 1f));
if (i == 2) m.SetColor(C_FoamShadow, Color.white);
if (i == 3) m.SetColor(C_Dark, Color.Lerp(Dk, W, 0.50f));
if (i == 4) m.SetColor(C_Dark, Color.Lerp(Dk, W, 0.75f));
if (i == 5) { m.SetColor(C_Dark, Color.Lerp(Dk, W, 0.75f)); m.SetColor(C_Light, W); m.SetColor(C_FoamShadow, Color.white); }
if (i == 6) { m.SetColor(C_Dark, Color.Lerp(Dk, W, 0.90f)); m.SetColor(C_Light, W); m.SetColor(C_FoamShadow, Color.white); }
water.sharedMaterial = m; yield return null; yield return new WaitForSeconds(0.25f);
L(names[i] + " · " + Shot(live, D + "m_sweep" + i + ".png"));
}
Done();
}
void Done()
{
System.IO.File.WriteAllText("AgentScripts/WL816j2_SWEEP.txt", sb.ToString());
Debug.Log("[816j2 sweep]\n" + sb);
}
}