test commit
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
public class DynamicTime : MonoBehaviour
|
||||
{
|
||||
public static DynamicTime Instance;
|
||||
|
||||
public const string PlayerPrefsKey = "SelectedTOD";
|
||||
|
||||
[Serializable]
|
||||
public class TimePreset
|
||||
{
|
||||
[Header("Sky")]
|
||||
public Material Skybox;
|
||||
[Header("Ambient Lighting")]
|
||||
public float AmbientIntensity;
|
||||
public Color AmbientSkyColor;
|
||||
public Color AmbientEquatorColor;
|
||||
public Color AmbientGroundColor;
|
||||
public AmbientMode AmbientMode;
|
||||
[Header("Fog")]
|
||||
public bool Fog;
|
||||
public float FogDensity;
|
||||
public float FogStartDistance;
|
||||
public float FogEndDistance;
|
||||
public Color FogColor;
|
||||
public FogMode FogMode;
|
||||
[Header("Objects")]
|
||||
public GameObject[] ObjectsToEnable;
|
||||
public GameObject[] ObjectsToDisable;
|
||||
|
||||
internal TimeOfDay tod;
|
||||
}
|
||||
|
||||
public enum TimeOfDay
|
||||
{
|
||||
Day,
|
||||
Dusk,
|
||||
Dawn,
|
||||
Night,
|
||||
Nightmare
|
||||
}
|
||||
|
||||
public TimePreset DayPreset = new();
|
||||
public TimePreset DuskPreset = new();
|
||||
public TimePreset DawnPreset = new();
|
||||
public TimePreset NightPreset = new();
|
||||
public TimePreset NightmarePreset = new();
|
||||
|
||||
public TimeOfDay ActiveTOD;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
DayPreset.tod = TimeOfDay.Day;
|
||||
DuskPreset.tod = TimeOfDay.Dusk;
|
||||
DawnPreset.tod = TimeOfDay.Dawn;
|
||||
NightPreset.tod = TimeOfDay.Night;
|
||||
NightmarePreset.tod = TimeOfDay.Nightmare;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (PlayerPrefs.HasKey(PlayerPrefsKey))
|
||||
ActiveTOD = (TimeOfDay)PlayerPrefs.GetInt(PlayerPrefsKey, 0);
|
||||
SetTime(ActiveTOD);
|
||||
}
|
||||
|
||||
private TimePreset GetTimePreset(TimeOfDay tod)
|
||||
{
|
||||
switch (tod)
|
||||
{
|
||||
case TimeOfDay.Day:
|
||||
return DayPreset;
|
||||
case TimeOfDay.Dusk:
|
||||
return DuskPreset;
|
||||
case TimeOfDay.Dawn:
|
||||
return DawnPreset;
|
||||
case TimeOfDay.Night:
|
||||
return NightPreset;
|
||||
case TimeOfDay.Nightmare:
|
||||
return NightmarePreset;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetTime(TimeOfDay tod)
|
||||
{
|
||||
var preset = GetTimePreset(tod);
|
||||
if (preset != null)
|
||||
ApplyTimePreset(preset);
|
||||
}
|
||||
|
||||
private void ApplyTimePreset(TimePreset preset)
|
||||
{
|
||||
RenderSettings.skybox = preset.Skybox;
|
||||
|
||||
RenderSettings.ambientIntensity = preset.AmbientIntensity;
|
||||
RenderSettings.ambientMode = preset.AmbientMode;
|
||||
RenderSettings.ambientSkyColor = preset.AmbientSkyColor;
|
||||
RenderSettings.ambientEquatorColor = preset.AmbientEquatorColor;
|
||||
RenderSettings.ambientGroundColor = preset.AmbientGroundColor;
|
||||
|
||||
RenderSettings.fog = preset.Fog;
|
||||
RenderSettings.fogColor = preset.FogColor;
|
||||
RenderSettings.fogDensity = preset.FogDensity;
|
||||
RenderSettings.fogStartDistance = preset.FogStartDistance;
|
||||
RenderSettings.fogEndDistance = preset.FogEndDistance;
|
||||
RenderSettings.fogMode = preset.FogMode;
|
||||
|
||||
foreach (var obj in preset.ObjectsToEnable)
|
||||
obj.SetActive(true);
|
||||
foreach (var obj in preset.ObjectsToDisable)
|
||||
obj.SetActive(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user