using UnityEngine; public class DayNightCycle_BuiltIn : MonoBehaviour { [Header("Time")] [Range(0f, 1f)] public float time01 = 0.25f; public float dayLengthSeconds = 600f; [Header("Sun (Directional Light)")] public Light sun; public float sunYaw = 170f; public AnimationCurve sunIntensity = AnimationCurve.EaseInOut(0, 0, 1, 1.2f); public Gradient sunColor; [Header("Ambient (Environment Light)")] public AnimationCurve ambientIntensity = AnimationCurve.EaseInOut(0, 0.2f, 1, 1.0f); public Gradient ambientColor; [Header("Fog")] public bool useFog = true; public AnimationCurve fogDensity = AnimationCurve.EaseInOut(0, 0.02f, 1, 0.006f); public Gradient fogColor; void Reset() { sunColor = new Gradient(); sunColor.SetKeys( new[] { new GradientColorKey(new Color(0.25f, 0.35f, 0.55f), 0f), new GradientColorKey(new Color(1.00f, 0.85f, 0.65f), 0.25f), new GradientColorKey(Color.white, 0.5f), new GradientColorKey(new Color(1.00f, 0.55f, 0.35f), 0.75f), }, new[] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 1f) } ); ambientColor = new Gradient(); ambientColor.SetKeys( new[] { new GradientColorKey(new Color(0.08f, 0.10f, 0.18f), 0f), new GradientColorKey(new Color(0.55f, 0.55f, 0.60f), 0.5f), new GradientColorKey(new Color(0.25f, 0.20f, 0.25f), 0.75f) }, new[] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 1f) } ); fogColor = new Gradient(); fogColor.SetKeys( new[] { new GradientColorKey(new Color(0.05f, 0.07f, 0.12f), 0f), new GradientColorKey(new Color(0.65f, 0.75f, 0.85f), 0.5f), new GradientColorKey(new Color(0.40f, 0.25f, 0.20f), 0.75f) }, new[] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 1f) } ); } void Update() { time01 += Time.deltaTime / Mathf.Max(1f, dayLengthSeconds); if (time01 >= 1f) time01 -= 1f; Apply(time01); } void Apply(float t) { // 1) žç ȸÀü if (sun) { float sunAngle = t * 360f - 90f; sun.transform.rotation = Quaternion.Euler(sunAngle, sunYaw, 0f); // 2) ÅÂ¾ç ¹à±â/»ö sun.intensity = sunIntensity.Evaluate(t); if (sunColor != null) sun.color = sunColor.Evaluate(t); } // 3) Ambient(ȯ°æ±¤) - È®½ÇÇÑ ¹æ½Ä RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Flat; Color c = ambientColor.Evaluate(t); float k = ambientIntensity.Evaluate(t); RenderSettings.ambientLight = c * k; // 4) Fog if (useFog) { RenderSettings.fog = true; RenderSettings.fogColor = fogColor.Evaluate(t); RenderSettings.fogDensity = fogDensity.Evaluate(t); } else { RenderSettings.fog = false; } // 5) ȯ°æ °»½Å DynamicGI.UpdateEnvironment(); } }