Server Day Night Worker
Last updated
Last updated
The ServerDayNightWorker
is responsible for managing the day and night cycle within the game environment.
Properties
public static Light sun
: Represents the directional light in the scene that simulates the sun.
public static float secondsInFullDay = 120f
: Represents the length of a full in-game day in seconds.
public static float currentTimeOfDay = 0
: Represents the current time of day within the game, ranging from 0 (midnight) to 1 (midnight of the next day), where 0.5 denotes noon.
public static float timeMultiplier = 1f
: Represents a multiplier used to speed up or slow down the day-night cycle.
public static float sunInitialIntensity
: Represents the initial intensity of the sun at the start of the game.
Constructors
The ServerDayNightWorker
does not have an explicit constructor.
Methods
public static void OnStart()
: Initializes the class by setting the sunInitialIntensity
based on the sun's intensity at the start of the game.
public static void OnUpdate()
: Updates the state of the day-night cycle. This method performs two primary functions: updates the sun's position and intensity based on the current time of day and increments currentTimeOfDay
based on the elapsed real-time, scaled by secondsInFullDay
and timeMultiplier
. If a full day has passed, it resets currentTimeOfDay
to 0.
private static void UpdateSun()
: Manages the sun's rotation and intensity based on currentTimeOfDay
. This method adjusts the sun's rotation to match the current time of day, calculates the sun's intensity multiplier, setting it to 0 during the night, and gradually increasing or decreasing it during dawn and dusk, respectively and applies the calculated intensity multiplier to the sun's intensity, considering the sunInitialIntensity
.