Skip to main content

DayTimeManager

A class in Root.Township, Alta.Environmental.Atmosphere.

Client: the atmosphere plugin for the day and night cycle. Turns the sun and moon and sets sky, ambient light, fog and ambience audio from game time. Follows the server's fixed daytime setting when set.

Constructors​

MemberWhat it is
DayTimeManager()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
float fullCycleEditor readout: position in the full day cycle.
float halfCycleEditor readout: position in the sun's half cycle.
float quarterCycleEditor readout: how high the moon is.
59 private and internal fields
MemberWhat it is
private float androidMoonDistanceDistance the Android moon is drawn from the player.
private Material androidMoonMaterialMaterial for the Android moon quad.
private float androidMoonSizeSize of the Android moon quad.
private AnimationCurve audioSplitTowardsDayShare of ambience volume given to day audio over sun progress; the rest goes to night audio.
private bool btnConvertEditor button field, "Convert Sky Color".
private bool btnStopUpdatingEditor button field, "Stop Updating".
private Gradient cloudsColorOverDayCloud colour over sun progress.
private Color currentAmbienceBacking field for CurrentAmbience.
private float currentVolumeSplitPrivate: current share of volume for day audio.
private float debugDayProgressEditor: day progress used when useDebugValueAtRuntime is set.
private float debugMonthProgressEditor: month progress used when useDebugValueAtRuntime is set.
private float dotMoonUpPrivate: how high the moon is, used for the moon ambience and light curves.
private float fogAndroidMultiplierFog density multiplier on Android.
private Gradient fogColorDuringDayFog colour over the full day cycle.
private AnimationCurve fogDensityDuringDayFog density over the full day cycle.
private GameTimeManager gameTimeManagerSource of day progress, month progress and the day to night ratio.
private AnimationCurve haloInverseSizeOverDaySun halo size value over the full cycle, sent to the skybox.
private Material instantiatedAndroidMoonMaterialPrivate: editor copy of the Android moon material.
private Material instantiatedSkyboxMaterialPrivate: editor copy of the skybox material.
private bool isRenderingGizmosSerialized editor flag. Not read in the server build.
private bool isUpdatingDaytimePrivate: false when the server's FixedDaytime setting is 0 or more, so the sun stays put.
private float lastDayProgressPrivate: full cycle position from the last ambience update, used for fog.
private float lastFixedDaytimePrivate: last fixed daytime seen. Starts at -1 and is not updated in this build.
private LerpingFloatValue LightIntensityModifierPrivate: lerps the sun and moon light strength when the plugin is enabled or disabled.
private static readonly Logger loggerPrivate: logger.
private Gradient moonAmbienceAmbient colour by moon height.
private float moonFadeInTimeSeconds the moonlight takes to fade in after the sun goes off. Defaults to 30.
private LerpingFloatGetValue MoonLerpInModifierPrivate: fades the moonlight in over moonFadeInTime once the sun sets.
private Light moonLightThe moon's directional light.
private AnimationCurve moonLightIntensityCurveMoonlight strength by moon height.
private static Mesh moonMeshPrivate static: the quad drawn as the Android moon.
private Transform moonRotatorTransform turned by month progress to move the moon.
private Vector3 moonSpiningAxisAxis the moon turns around.
private float moonToSunDotShiftSun height (negative, below the horizon) where ambience starts blending from moon to sun.
private Vector3 moonVectorPrivate: direction to the moon.
private AmbienceAudio nightSourceNight ambience audio, mixed against the main source. Destroyed on headless.
private float nightTimeShiftSerialized value, defaults to -0.004. Not read in this build.
private Gradient skyBotcolorBottom sky colour over the full cycle.
private Material skyBoxMaterialThe skybox material this manager drives.
private AnimationCurve skyColorBotBendingBottom sky gradient bend over the full cycle.
private LerpingFloatValue skyColorFadePrivate: lerps the sky in and out when the plugin is enabled or disabled.
private AnimationCurve skyColorMidPointPositionWhere the middle sky colour sits over the full cycle.
private Gradient skyColorRelatedToSunEditor reference gradient only.
private AnimationCurve skyColorTopBendingTop sky gradient bend over the full cycle.
private Gradient skyMidcolorMiddle sky colour over the full cycle.
private Gradient skyTopcolorTop sky colour over the full cycle.
private Gradient sunAmbienceAmbient colour over sun progress.
private Gradient sunColorSun disc colour over sun progress, sent to the skybox.
private AnimationCurve sunInverseSizeOverDaySun disc size value over sun progress, sent to the skybox.
private Light sunLightThe sun's directional light.
private Gradient sunlightDuringDaySunlight colour over sun progress.
private AnimationCurve sunLightIntensityCurveSunlight strength over sun progress.
private float sunProgressPrivate: where the sun is in its half cycle, used by most day curves.
private Transform sunRotatorTransform turned by day progress to move the sun.
private Vector3 sunSpiningAxisAxis the sun turns around.
private float sunUpSkewDegrees added so the sun spends longer above the horizon.
private MethodSync syncFixedDaytimePrivate: message for SyncFixedDaytime, sent on the atmosphere manager's entity.
private bool useDebugValueAtRuntimeEditor: use the debug day and month progress while playing.
private bool wasEnabledPrivate: whether the moonlight is on, so its fade in runs once per night.

Properties​

MemberWhat it is
override float AmbienceVolume { get; set; }Total ambience volume, split between day and night sources by time of day. 0 on a headless server.
override Color CurrentAmbience { get; }The ambient light colour for the current time.
override Color CurrentFog { get; }The fog colour for the current time.
override float CurrentFogDensity { get; }The fog density for the current time, scaled on Android.
2 private and internal properties
MemberWhat it is
private Material AndroidMoonMaterial { get; }Private: the Android moon material (a copy in the editor).
private Material SkyboxMaterial { get; }Private: the skybox material (a copy in the editor).

Methods​

MemberWhat it is
override void Disable()Fades the lights and sky colour out when another atmosphere takes over.
Color EvaluateFogColor()Fog colour for the last worked out time of day.
float EvaluateFogDensity()Fog density for the last worked out time of day.
override void Initialize(AtmosphereManager manager)Reads the server's fixed daytime (below 0 means the normal cycle) and sets the starting sun and moon.
override void Mute(bool isMuted)Mutes or unmutes the night source as well.
override void OnConnect(Player player)Sends the fixed daytime state to a joining player.
override void StartAudio()Starts the night source as well.
override void StopAudio()Stops the night source as well.
protected override void Enabled()Fades the lights and sky back in when this atmosphere becomes active.
21 private and internal methods
MemberWhat it is
private void Awake()Turns itself and both lights off on a headless server. Otherwise sets up fog, the skybox, the Android moon mesh and the lerpers.
private void CreateMoonMeshIfNeeded()Private: builds the shared quad mesh used to draw the moon on Android.
private void DisableSkyColor()Private: once the sky has faded out, clears the skybox on Android or disables it elsewhere.
private float GetDotProductBetweenSunAndMoonVectors(Vector3 sunVector)Private: how closely the sun and moon line up, sharpened for the skybox shader.
private float GetSunRotation(float dayProgress)Private: sun angle for a day progress, with the day half and night half split by the day to night ratio.
private void LateUpdate()Private: updates the lerpers, ambience audio split, sun and moon rotation (unless daytime is fixed) and ambience.
private void OnDestroy()Private: unhooks the scene change handler.
private void RenderMoon(Vector3 position, float scaleMultiplier)Private: draws the moon quad at a position and scale.
private void RenderMoonOnAndroid()Private: draws the moon around the player's head on Android, pulled inside the camera's far clip if needed.
private void SetLightIntensity(Light light, float intensity)Private: sets a light's intensity, or turns it off when 0.01 or less.
private void SetShaderSunVector(Vector3 sunVector, float sunUp)Private: sends the sun direction and strength to the skybox shader.
private void SetupSceneSkyboxInBuilds()Private: sets the skybox now, or once this object's scene becomes active.
private void SetupSkybox(Scene currentScene, Scene activatingScene)Private: sets RenderSettings.skybox to this manager's material.
private void SetupSkybox()Private: sets RenderSettings.skybox to this manager's material.
private void SetupVariableLerpers()Private: creates the light, moon and sky fade lerpers.
private void SyncFixedDaytime(IPlayer player, Stream stream)Private: syncs whether daytime is fixed and its value from the server settings. Clients move the sun to match.
private void UpdateAmbience()Private: works out sun progress and moon height, then sets ambient, fog, sky colours and light strength from the curves.
private void UpdateLightIntensity(float intensityModifier)Private: sets sun and moon light strength from their curves. The moon only shines when the sun is off.
private void UpdateRotation(float dayProgress, float monthProgress)Private: turns the sun and moon for a day and month progress and updates the skybox vectors.
private void UpdateSettings(ServerSettings settings)Private, server: when the server's FixedDaytime setting changes, switches fixed time on or off and syncs it.
private void UpdateSkyColorFade(float fadeValue)Private: sends the sky fade value to the skybox shader.

Used in​

Members of other types that take, return or hold a DayTimeManager: