Project_WL/AgentScripts/WL816h_Rollback.cs

132 lines
6.8 KiB
C#
Raw Normal View History

// WL-816h — ⑤ 되돌리기 실측 (SO 스위치 하나로 100 % 복귀)
// R1 = waterMode 0 + skyScopeEnabled 0 → 816f 상태(FarmingIsland 물 · 스코프 없음)
// R2 = enabled_ 0 → 섬 룩 전체 off (816e/816f 가 쓰던 스위치)
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor;
public static class WL816h_Rollback
{
const string SO = "Assets/WL/Look/Farm/Resources/WL/WLIslandLookSettings.asset";
const string Dir = "Screenshots_WL/WL816h/";
public static void SetR1() { Set(1, 0, 0); } // 섬 룩은 그대로 · 물/스코프만 끈다
public static void SetR2() { Set(0, 0, 0); } // 전부 off
public static void SetOn() { Set(1, 1, 1); } // 채택 상태로 복귀
static void Set(int enabled_, int sky, int water)
{
var so = AssetDatabase.LoadAssetAtPath<WL.Look.Farm.WLIslandLookSettings>(SO);
if (so == null) { Debug.Log("[816h] SO 없음"); return; }
so.enabled_ = enabled_; so.skyScopeEnabled = sky; so.waterMode = water;
EditorUtility.SetDirty(so); AssetDatabase.SaveAssets();
WL.Look.Farm.WLIslandLookSettings.Invalidate();
Debug.Log("[816h] SO enabled_=" + enabled_ + " skyScope=" + sky + " waterMode=" + water);
UnityEditor.SceneManagement.EditorSceneManager.OpenScene(
"Assets/Scenes/InGame.unity", UnityEditor.SceneManagement.OpenSceneMode.Single);
}
public static void Start()
{
var go = GameObject.Find("~WL816hRollback");
if (go != null) Object.DestroyImmediate(go);
go = new GameObject("~WL816hRollback");
go.AddComponent<WL816h_RollbackRunner>();
}
}
/// <summary>run_script 는 파일 하나만 컴파일한다 → 도우미를 여기에 그대로 둔다.</summary>
public static class RB
{
public const int W = 1080, H = 1920;
public static string Sky()
{
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 : "없음");
}
static string F(Color c) { return "(" + c.r.ToString("F3") + "," + c.g.ToString("F3") + "," + c.b.ToString("F3") + ")"; }
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 pT = cam.targetTexture; var pA = 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 = pA; cam.targetTexture = pT;
System.IO.File.WriteAllBytes(path, tex.EncodeToPNG());
var px = tex.GetPixels32(); long r = 0, g = 0, b = 0;
for (int i = 0; i < px.Length; i += 7) { r += px[i].r; g += px[i].g; b += px[i].b; }
int n = (px.Length + 6) / 7;
string s = "#" + ((int)(r / n)).ToString("X2") + ((int)(g / n)).ToString("X2") + ((int)(b / n)).ToString("X2");
Object.DestroyImmediate(tex); rt.Release(); Object.DestroyImmediate(rt);
return s + " → " + path;
}
}
public class WL816h_RollbackRunner : MonoBehaviour
{
void Start() { StartCoroutine(Co()); }
IEnumerator Co()
{
var sb = new System.Text.StringBuilder();
var cfg = WL.Look.Farm.WLIslandLookSettings.Instance;
string tag = "enabled_=" + (cfg == null ? -1 : cfg.enabled_)
+ " skyScope=" + (cfg == null ? -1 : cfg.skyScopeEnabled)
+ " waterMode=" + (cfg == null ? -1 : cfg.waterMode);
sb.AppendLine("=== 되돌리기 실측 [" + tag + "] ===");
string pristine = RB.Sky();
sb.AppendLine("InGame 원래 하늘 : " + pristine);
var op = SceneManager.LoadSceneAsync("Level01", LoadSceneMode.Additive);
while (op != null && !op.isDone) yield return null;
for (int i = 0; i < 7; i++) yield return new WaitForSeconds(1f);
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;
sb.AppendLine("물 : " + (water == null ? "없음" : water.sharedMaterial.name + " / " + water.sharedMaterial.shader.name));
sb.AppendLine("머티리얼 교체 : 렌더러 " + WL.Look.Farm.WLIslandLook.SwappedRenderers
+ " · 물 " + WL.Look.Farm.WLIslandLook.WaterSwapped);
sb.AppendLine("풀 : " + WL.Look.Farm.WLIslandGrass.LastLog);
sb.AppendLine("RefLook : " + WL.Look.Arena.WLReferenceLook.IsApplied);
sb.AppendLine("SkyScope : held=" + WL.Look.Farm.WLSkyScope.Held
+ " acquires=" + WL.Look.Farm.WLSkyScope.Acquires + " restores=" + WL.Look.Farm.WLSkyScope.Restores);
sb.AppendLine("섬 하늘 : " + RB.Sky());
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("~WL816h")) continue;
if (live == null || c.depth > live.depth) live = c;
}
string shot = "Screenshots_WL/WL816h/z_rollback_" + (cfg != null && cfg.enabled_ == 0 ? "off" : "water_now") + ".png";
sb.AppendLine("화면 : " + RB.Shot(live, shot));
// 섬을 내리고 전투 맵 → 하늘이 원래대로인가
var u = SceneManager.UnloadSceneAsync("Level01");
while (u != null && !u.isDone) yield return null;
yield return new WaitForSeconds(2.5f);
var b = SceneManager.LoadSceneAsync("Map_C01", LoadSceneMode.Additive);
while (b != null && !b.isDone) yield return null;
yield return new WaitForSeconds(1.5f);
string after = RB.Sky();
sb.AppendLine("전투 맵 : " + after);
sb.AppendLine("🔴 원래대로 = " + (after == pristine ? "예" : "🔴 아니오 (전 " + pristine + ")"));
string path = "AgentScripts/WL816h_ROLLBACK_" + (cfg != null && cfg.enabled_ == 0 ? "R2" : "R1") + ".txt";
System.IO.File.WriteAllText(path, sb.ToString());
Debug.Log("[816h rollback]\n" + sb);
}
}