Guest User

Untitled

a guest
Jan 20th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class TimeOfDayManager : MonoBehaviour
  5. {
  6. public TimeOfDayData Data;
  7.  
  8. [Range(0.0f, 1f)] public float currentTimeOfDay;
  9. public FloatVariable CurrentTimeVariable;
  10.  
  11. public float secondsInFullDay = 120f;
  12.  
  13. private float sunInitialIntensity;
  14.  
  15. [HideInInspector] public float timeMultiplier = 1f;
  16.  
  17. #region Curves and Gradients
  18.  
  19. private UltimateBloom ultimateBloom;
  20.  
  21. [Header("Bloom")] public float BloomThreshold;
  22.  
  23. public AnimationCurve BloomThresholdCurve;
  24. public float BloomIntensity;
  25.  
  26. public AnimationCurve BloomIntensityCurve;
  27.  
  28. [Header("Ambience")] public float CurrentAmbientIntensity;
  29. public Color CurrentAmbientColor;
  30.  
  31. public AnimationCurve AmbientCurve;
  32.  
  33. public Gradient AmbientColorCurve;
  34.  
  35. [Header("Reflection")] public float CurrentReflectionIntensity;
  36.  
  37. public AnimationCurve ReflectionIntensityCurve;
  38.  
  39. [Header("Fog")] public float FogIntensity;
  40. public float FogDistance;
  41. public float FogStartDistance;
  42. public Color CurrentFogColor;
  43.  
  44. public Gradient FogColorGradient;
  45.  
  46. public AnimationCurve FogColorCurve;
  47. public AnimationCurve FogIntensityCurve;
  48. public AnimationCurve FogDistanceCurve;
  49.  
  50. [Header("Sun")] public Light sun;
  51. public AnimationCurve SunLightIntensityCurve;
  52. public Gradient SunLightColorGradient;
  53.  
  54. #endregion
  55.  
  56. private void Start()
  57. {
  58. ApplyData(Data);
  59. sunInitialIntensity = sun.intensity;
  60.  
  61. Camera playercam = FindObjectOfType<Camera>();
  62. if (playercam)
  63. {
  64. ultimateBloom = Camera.main.GetComponent<UltimateBloom>();
  65. BloomIntensity = Camera.main.GetComponent<UltimateBloom>().m_BloomIntensity;
  66. BloomThreshold = ultimateBloom.m_BloomThreshhold;
  67. }
  68. }
  69.  
  70. private void ApplyData(TimeOfDayData data)
  71. {
  72. secondsInFullDay = data.secondsInFullDay;
  73. currentTimeOfDay = data.currentTimeOfDay;
  74. BloomThreshold = data.BloomThreshold;
  75. BloomThresholdCurve = data.BloomThresholdCurve;
  76. BloomIntensity = data.BloomIntensity;
  77. BloomIntensityCurve = data.BloomIntensityCurve;
  78.  
  79. CurrentAmbientIntensity = data.CurrentAmbientIntensity;
  80. CurrentAmbientColor = data.CurrentAmbientColor;
  81. AmbientCurve = data.AmbientCurve;
  82. AmbientColorCurve = data.AmbientColorCurve;
  83.  
  84. CurrentReflectionIntensity = data.CurrentReflectionIntensity;
  85. ReflectionIntensityCurve = data.ReflectionIntensityCurve;
  86.  
  87. FogIntensity = data.FogIntensity;
  88. FogIntensityCurve = data.FogIntensityCurve;
  89. CurrentFogColor = data.CurrentFogColor;
  90. FogColorGradient = data.FogColorGradient;
  91. FogColorCurve = data.FogColorCurve;
  92. FogIntensityCurve = data.FogIntensityCurve;
  93. FogDistanceCurve = data.FogDistanceCurve;
  94.  
  95. SunLightIntensityCurve = data.SunLightIntensityCurve;
  96. SunLightColorGradient = data.SunLightColorGradient;
  97. }
  98.  
  99.  
  100. private void Update()
  101. {
  102. UpdateSun();
  103. }
  104.  
  105. private void UpdateSunRotation()
  106. {
  107. sun.transform.localRotation =
  108. Quaternion.Euler((float)(currentTimeOfDay * 360.0 - 90.0), 170f, 0.0f);
  109. }
  110.  
  111. private void UpdateSun()
  112. {
  113. UpdateSunRotation();
  114. UpdateRenderSettings();
  115. currentTimeOfDay += Time.deltaTime / secondsInFullDay * timeMultiplier;
  116. if (currentTimeOfDay >= 1.0)
  117. currentTimeOfDay = 0.0f;
  118. if (currentTimeOfDay <= 0.0)
  119. currentTimeOfDay = 0.0f;
  120. CurrentTimeVariable.Value = currentTimeOfDay;
  121. }
  122.  
  123. private void UpdateRenderSettings()
  124. {
  125. sun.intensity = SunLightIntensityCurve.Evaluate(currentTimeOfDay);
  126. sun.color = SunLightColorGradient.Evaluate(currentTimeOfDay);
  127. FogIntensity = FogIntensityCurve.Evaluate(currentTimeOfDay);
  128. RenderSettings.ambientIntensity = AmbientCurve.Evaluate(currentTimeOfDay);
  129. RenderSettings.fogStartDistance = FogStartDistance;
  130. RenderSettings.fogColor = FogColorGradient.Evaluate(currentTimeOfDay);
  131. RenderSettings.fogDensity = FogIntensityCurve.Evaluate(currentTimeOfDay);
  132. RenderSettings.fogEndDistance = FogDistanceCurve.Evaluate(currentTimeOfDay);
  133. RenderSettings.ambientSkyColor = AmbientColorCurve.Evaluate(currentTimeOfDay);
  134. RenderSettings.reflectionIntensity = ReflectionIntensityCurve.Evaluate(currentTimeOfDay);
  135. if (ultimateBloom != null)
  136. {
  137. ultimateBloom.m_BloomThreshhold = BloomThresholdCurve.Evaluate(currentTimeOfDay);
  138. BloomThreshold = ultimateBloom.m_BloomThreshhold;
  139.  
  140. ultimateBloom.m_BloomIntensity = BloomIntensityCurve.Evaluate(currentTimeOfDay);
  141. BloomIntensity = ultimateBloom.m_BloomIntensity;
  142. }
  143. else
  144. {
  145. ultimateBloom = FindObjectOfType<UltimateBloom>();
  146. }
  147.  
  148. CurrentReflectionIntensity = RenderSettings.reflectionIntensity;
  149. CurrentAmbientColor = RenderSettings.ambientSkyColor;
  150. CurrentFogColor = RenderSettings.fogColor;
  151. CurrentAmbientIntensity = RenderSettings.ambientIntensity;
  152. }
  153.  
  154.  
  155. }
Add Comment
Please, Sign In to add comment