#if UNITY_EDITOR using System.IO; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; using UnityEngine.Rendering.Universal; public static class TestRealtimeShadowCapture { const string ScenePath = "Assets/Bundles/Scenes/Town/HomeCamp/HomeCamp.unity"; public static string Run() { var scene = EditorSceneManager.OpenScene(ScenePath, OpenSceneMode.Additive); try { var root = scene.GetRootGameObjects()[0]; var sun = root.transform.Find("HomeCampSun")?.GetComponent(); if (sun != null) { sun.lightmapBakeType = LightmapBakeType.Realtime; sun.shadows = LightShadows.Soft; sun.shadowStrength = 0.85f; sun.shadowBias = 0.05f; sun.shadowNormalBias = 0.3f; sun.intensity = 1.8f; } var cam = root.transform.Find("HomeCampCamera")?.GetComponent(); if (cam == null) return "Camera missing"; var uacd = cam.GetComponent(); if (uacd == null) uacd = cam.gameObject.AddComponent(); uacd.renderShadows = true; int w = 720, h = 1280; var rt = new RenderTexture(w, h, 24, RenderTextureFormat.ARGB32) { name = "ShadowTestRT" }; rt.Create(); cam.targetTexture = rt; cam.Render(); var old = RenderTexture.active; 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 = old; cam.targetTexture = null; rt.Release(); Object.DestroyImmediate(rt); string outPath = Path.Combine(Application.dataPath, "../../Tools/output/shadow_test.png"); File.WriteAllBytes(outPath, tex.EncodeToPNG()); Object.DestroyImmediate(tex); return "Rendered to " + outPath; } finally { EditorSceneManager.CloseScene(scene, true); } } } #endif