Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class TimeOfDayManager : MonoBehaviour
- {
- public TimeOfDayData Data;
- [Range(0.0f, 1f)] public float currentTimeOfDay;
- public FloatVariable CurrentTimeVariable;
- public float secondsInFullDay = 120f;
- private float sunInitialIntensity;
- [HideInInspector] public float timeMultiplier = 1f;
- #region Curves and Gradients
- private UltimateBloom ultimateBloom;
- [Header("Bloom")] public float BloomThreshold;
- public AnimationCurve BloomThresholdCurve;
- public float BloomIntensity;
- public AnimationCurve BloomIntensityCurve;
- [Header("Ambience")] public float CurrentAmbientIntensity;
- public Color CurrentAmbientColor;
- public AnimationCurve AmbientCurve;
- public Gradient AmbientColorCurve;
- [Header("Reflection")] public float CurrentReflectionIntensity;
- public AnimationCurve ReflectionIntensityCurve;
- [Header("Fog")] public float FogIntensity;
- public float FogDistance;
- public float FogStartDistance;
- public Color CurrentFogColor;
- public Gradient FogColorGradient;
- public AnimationCurve FogColorCurve;
- public AnimationCurve FogIntensityCurve;
- public AnimationCurve FogDistanceCurve;
- [Header("Sun")] public Light sun;
- public AnimationCurve SunLightIntensityCurve;
- public Gradient SunLightColorGradient;
- #endregion
- private void Start()
- {
- ApplyData(Data);
- sunInitialIntensity = sun.intensity;
- Camera playercam = FindObjectOfType<Camera>();
- if (playercam)
- {
- ultimateBloom = Camera.main.GetComponent<UltimateBloom>();
- BloomIntensity = Camera.main.GetComponent<UltimateBloom>().m_BloomIntensity;
- BloomThreshold = ultimateBloom.m_BloomThreshhold;
- }
- }
- private void ApplyData(TimeOfDayData data)
- {
- secondsInFullDay = data.secondsInFullDay;
- currentTimeOfDay = data.currentTimeOfDay;
- BloomThreshold = data.BloomThreshold;
- BloomThresholdCurve = data.BloomThresholdCurve;
- BloomIntensity = data.BloomIntensity;
- BloomIntensityCurve = data.BloomIntensityCurve;
- CurrentAmbientIntensity = data.CurrentAmbientIntensity;
- CurrentAmbientColor = data.CurrentAmbientColor;
- AmbientCurve = data.AmbientCurve;
- AmbientColorCurve = data.AmbientColorCurve;
- CurrentReflectionIntensity = data.CurrentReflectionIntensity;
- ReflectionIntensityCurve = data.ReflectionIntensityCurve;
- FogIntensity = data.FogIntensity;
- FogIntensityCurve = data.FogIntensityCurve;
- CurrentFogColor = data.CurrentFogColor;
- FogColorGradient = data.FogColorGradient;
- FogColorCurve = data.FogColorCurve;
- FogIntensityCurve = data.FogIntensityCurve;
- FogDistanceCurve = data.FogDistanceCurve;
- SunLightIntensityCurve = data.SunLightIntensityCurve;
- SunLightColorGradient = data.SunLightColorGradient;
- }
- private void Update()
- {
- UpdateSun();
- }
- private void UpdateSunRotation()
- {
- sun.transform.localRotation =
- Quaternion.Euler((float)(currentTimeOfDay * 360.0 - 90.0), 170f, 0.0f);
- }
- private void UpdateSun()
- {
- UpdateSunRotation();
- UpdateRenderSettings();
- currentTimeOfDay += Time.deltaTime / secondsInFullDay * timeMultiplier;
- if (currentTimeOfDay >= 1.0)
- currentTimeOfDay = 0.0f;
- if (currentTimeOfDay <= 0.0)
- currentTimeOfDay = 0.0f;
- CurrentTimeVariable.Value = currentTimeOfDay;
- }
- private void UpdateRenderSettings()
- {
- sun.intensity = SunLightIntensityCurve.Evaluate(currentTimeOfDay);
- sun.color = SunLightColorGradient.Evaluate(currentTimeOfDay);
- FogIntensity = FogIntensityCurve.Evaluate(currentTimeOfDay);
- RenderSettings.ambientIntensity = AmbientCurve.Evaluate(currentTimeOfDay);
- RenderSettings.fogStartDistance = FogStartDistance;
- RenderSettings.fogColor = FogColorGradient.Evaluate(currentTimeOfDay);
- RenderSettings.fogDensity = FogIntensityCurve.Evaluate(currentTimeOfDay);
- RenderSettings.fogEndDistance = FogDistanceCurve.Evaluate(currentTimeOfDay);
- RenderSettings.ambientSkyColor = AmbientColorCurve.Evaluate(currentTimeOfDay);
- RenderSettings.reflectionIntensity = ReflectionIntensityCurve.Evaluate(currentTimeOfDay);
- if (ultimateBloom != null)
- {
- ultimateBloom.m_BloomThreshhold = BloomThresholdCurve.Evaluate(currentTimeOfDay);
- BloomThreshold = ultimateBloom.m_BloomThreshhold;
- ultimateBloom.m_BloomIntensity = BloomIntensityCurve.Evaluate(currentTimeOfDay);
- BloomIntensity = ultimateBloom.m_BloomIntensity;
- }
- else
- {
- ultimateBloom = FindObjectOfType<UltimateBloom>();
- }
- CurrentReflectionIntensity = RenderSettings.reflectionIntensity;
- CurrentAmbientColor = RenderSettings.ambientSkyColor;
- CurrentFogColor = RenderSettings.fogColor;
- CurrentAmbientIntensity = RenderSettings.ambientIntensity;
- }
- }
Add Comment
Please, Sign In to add comment