106 lines
5.6 KiB
C#
106 lines
5.6 KiB
C#
|
|
// WL-816r 최종 — 적용 후 PD 구도 캡처 + 띠/초록 비 재측정 + 풀밭(초록) 무변경 확인.
|
||
|
|
public static class WL816r_Final
|
||
|
|
{
|
||
|
|
public static void Start()
|
||
|
|
{
|
||
|
|
var go = UnityEngine.GameObject.Find("~WL816rFin");
|
||
|
|
if (go != null) UnityEngine.Object.DestroyImmediate(go);
|
||
|
|
go = new UnityEngine.GameObject("~WL816rFin");
|
||
|
|
go.AddComponent<WL816r_Fin>();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public class WL816r_Fin : UnityEngine.MonoBehaviour
|
||
|
|
{
|
||
|
|
static System.Text.StringBuilder sb;
|
||
|
|
const int W = 1080, H = 1920;
|
||
|
|
static string Dir = "Screenshots_WL/WL816r";
|
||
|
|
|
||
|
|
void Start() { StartCoroutine(Co()); }
|
||
|
|
|
||
|
|
System.Collections.IEnumerator Co()
|
||
|
|
{
|
||
|
|
sb = new System.Text.StringBuilder();
|
||
|
|
System.IO.Directory.CreateDirectory(Dir);
|
||
|
|
if (UnityEngine.SceneManagement.SceneManager.sceneCount < 2)
|
||
|
|
{
|
||
|
|
var op = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync("Level01", UnityEngine.SceneManagement.LoadSceneMode.Additive);
|
||
|
|
while (op != null && !op.isDone) yield return null;
|
||
|
|
}
|
||
|
|
for (int i = 0; i < 7; i++) yield return new UnityEngine.WaitForSeconds(1f);
|
||
|
|
|
||
|
|
var cfg = WL.Look.Farm.WLIslandLookSettings.Instance;
|
||
|
|
var topMat = cfg.islandTopMaterial;
|
||
|
|
L("적용 확인 — islandTopMaterial=" + (topMat ? topMat.name : "-")
|
||
|
|
+ " tex=" + (topMat && topMat.GetTexture("_BaseMap") ? topMat.GetTexture("_BaseMap").name : "-")
|
||
|
|
+ " · soilTargetEnabled=" + cfg.soilTargetEnabled
|
||
|
|
+ " · 밭 재도색=" + WL.Look.Farm.WLIslandLook.SoilTilesRepainted + "타일/" + WL.Look.Farm.WLIslandLook.SoilFarmsToned + "Farm");
|
||
|
|
UnityEngine.Material road = null;
|
||
|
|
foreach (var t in UnityEngine.Object.FindObjectsByType<UnityEngine.Transform>(UnityEngine.FindObjectsInactive.Include, UnityEngine.FindObjectsSortMode.None))
|
||
|
|
if (t.name == "Road")
|
||
|
|
foreach (var r in t.GetComponentsInChildren<UnityEngine.Renderer>(true))
|
||
|
|
foreach (var m in r.sharedMaterials)
|
||
|
|
if (m != null && m.shader != null && m.shader.name.Contains("Toon") && road == null) road = m;
|
||
|
|
if (road != null) L("길 머티리얼 " + road.name + " Dif=" + Hx(road.GetColor("_DiffuseColor").gamma) + " Shd=" + Hx(road.GetColor("_ShadowDiffuseColor").gamma));
|
||
|
|
|
||
|
|
var topR = new System.Collections.Generic.List<UnityEngine.Renderer>();
|
||
|
|
foreach (var r in UnityEngine.Object.FindObjectsByType<UnityEngine.Renderer>(UnityEngine.FindObjectsSortMode.None))
|
||
|
|
foreach (var m in r.sharedMaterials) if (m != null && m == topMat) { topR.Add(r); break; }
|
||
|
|
|
||
|
|
var cam = MakePd();
|
||
|
|
var tex = Grab(cam, W, H);
|
||
|
|
System.IO.File.WriteAllBytes(Dir + "/after_pd.png", UnityEngine.ImageConversion.EncodeToPNG(tex));
|
||
|
|
var px = tex.GetPixels32();
|
||
|
|
long gr = 0, gg = 0, gb = 0; int gn = 0;
|
||
|
|
long br = 0, bg = 0, bb = 0; int bn = 0;
|
||
|
|
for (int i = 0; i < px.Length; i++)
|
||
|
|
{
|
||
|
|
var p = px[i];
|
||
|
|
if (p.g > p.r + 20 && p.g > p.b + 20 && p.g > 90) { gr += p.r; gg += p.g; gb += p.b; gn++; }
|
||
|
|
else if (p.r > 150 && p.g > 140 && p.b < p.g && p.b > 90) { br += p.r; bg += p.g; bb += p.b; bn++; }
|
||
|
|
}
|
||
|
|
if (gn > 0 && bn > 0)
|
||
|
|
{
|
||
|
|
float[] g = { gr / (float)gn, gg / (float)gn, gb / (float)gn };
|
||
|
|
float[] b = { br / (float)bn, bg / (float)bn, bb / (float)bn };
|
||
|
|
L(string.Format("[후] 초록={0} 띠={1} · 비={2:F4},{3:F4},{4:F4} (데모 목표 1.0861,0.8660,1.0530)",
|
||
|
|
Hx2(g), Hx2(b), b[0] / g[0], b[1] / g[1], b[2] / g[2]));
|
||
|
|
}
|
||
|
|
UnityEngine.Object.DestroyImmediate(tex);
|
||
|
|
Flush();
|
||
|
|
}
|
||
|
|
|
||
|
|
static string Hx(UnityEngine.Color c)
|
||
|
|
{ return string.Format("#{0:X2}{1:X2}{2:X2}", (int)(UnityEngine.Mathf.Clamp01(c.r) * 255), (int)(UnityEngine.Mathf.Clamp01(c.g) * 255), (int)(UnityEngine.Mathf.Clamp01(c.b) * 255)); }
|
||
|
|
static string Hx2(float[] c) { return string.Format("#{0:X2}{1:X2}{2:X2}", (int)c[0], (int)c[1], (int)c[2]); }
|
||
|
|
|
||
|
|
static UnityEngine.Camera MakePd()
|
||
|
|
{
|
||
|
|
UnityEngine.Vector3 tgt = UnityEngine.Vector3.zero;
|
||
|
|
var pc = UnityEngine.GameObject.FindGameObjectWithTag("Player"); if (pc != null) tgt = pc.transform.position;
|
||
|
|
var go = UnityEngine.GameObject.Find("~816rFPd"); if (go == null) go = new UnityEngine.GameObject("~816rFPd");
|
||
|
|
var c = go.GetComponent<UnityEngine.Camera>(); if (c == null) c = go.AddComponent<UnityEngine.Camera>();
|
||
|
|
c.orthographic = false; c.fieldOfView = 60f; c.nearClipPlane = 0.1f; c.farClipPlane = 300f;
|
||
|
|
c.transform.rotation = UnityEngine.Quaternion.Euler(45f, 45f, 0f);
|
||
|
|
c.transform.position = tgt - c.transform.forward * 12f;
|
||
|
|
c.enabled = false; return c;
|
||
|
|
}
|
||
|
|
static UnityEngine.Texture2D Grab(UnityEngine.Camera cam, int w, int h)
|
||
|
|
{
|
||
|
|
var rt = new UnityEngine.RenderTexture(w, h, 24, UnityEngine.RenderTextureFormat.ARGB32, UnityEngine.RenderTextureReadWrite.sRGB);
|
||
|
|
rt.Create(); cam.targetTexture = rt; cam.Render();
|
||
|
|
var prev = UnityEngine.RenderTexture.active; 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 = prev; cam.targetTexture = null;
|
||
|
|
rt.Release(); UnityEngine.Object.DestroyImmediate(rt);
|
||
|
|
return tex;
|
||
|
|
}
|
||
|
|
static void L(string s) { sb.AppendLine(s); Flush(); }
|
||
|
|
static void Flush()
|
||
|
|
{
|
||
|
|
System.IO.File.WriteAllText("AgentScripts/WL816r_FINAL.txt", sb.ToString());
|
||
|
|
UnityEngine.Debug.Log("[816r final]\n" + sb.ToString());
|
||
|
|
}
|
||
|
|
}
|