WorldSceneSettings - jimdroberts/FishMMO GitHub Wiki
MonoBehaviour for configuring world scene settings, including client limits, transition visuals, day/night cycle, and object activations.
-
public int MaxClients
The maximum number of clients allowed in this scene.
-
public Sprite SceneTransitionImage
The image that will be displayed when entering this scene.
-
public RegionChangeFogAction DefaultSceneFog
Delegate for triggering fog changes when the scene loads or transitions.
-
public bool DayNightCycle
True if the day night cycle should run. False if not.
-
public int DayCycleDuration
The duration of the day cycle in seconds.
-
public int NightCycleDuration
The duration of the night cycle in seconds.
-
public Material DaySkyboxMaterial
The skybox material used during the day cycle.
-
public Material NightSkyBoxMaterial
The skybox material used during the night cycle.
-
public List RotateObjects
Objects that will rotate constantly with the day night cycle.
-
public List DayObjects
Objects enabled during the day and disabled at night.
-
public List NightObjects
Objects enabled during the night and disabled during the day.
-
public float FadeThreshold
The time in seconds that objects will take to fade in or out.
-
public List DayFadeObjects
Objects that will fade away during the day.
-
public List NightFadeObjects
Objects that will fade away at night.
-
private bool isDaytime
Returns true if it's currently day time.
-
private float fadeTime
The current fade time.
-
private float lastRotationAngle
Tracks the last applied rotation angle for objects affected by the day/night cycle.
-
private void Awake()
Unity Awake callback. Initializes the day/night cycle, sets the initial skybox, and triggers fog if needed.
-
void Update()
Unity Update callback. Advances the day/night cycle, updates object states, rotations, and fading each frame.
-
private float GetGameTimeOfDay(DateTime now)
Gets the current game time of day in seconds. Parameters:
- DateTime now: The current UTC time. Returns: float (seconds into the current day/night cycle)
-
private void UpdateDayNightState(float currentGameTimeOfDay, bool ignoreCurrentState = false)
Updates the day night state. Switches between day and night, activates/deactivates objects, and resets fade time. Parameters:
- float currentGameTimeOfDay: The current time in the cycle.
- bool ignoreCurrentState: If true, forces state update.
-
private void UpdateDayNightRotation(float currentGameTimeOfDay, List objects)
Rotates objects based on the current game time of day and lerps the skybox between day and night materials. Parameters:
- float currentGameTimeOfDay: The current time in the cycle.
- List objects: Objects to rotate.
-
private void UpdateDayNightActivations(bool enable, List objects)
Enables or disables all GameObjects in the provided list based on the 'enable' parameter. Parameters:
- bool enable: True to enable objects, false to disable.
- List objects: List of GameObjects to activate/deactivate.
-
private void UpdateDayNightFading(float gameTimeOfDay, List dayFadeObjects, List nightFadeObjects)
Fade objects in or out based on day/night status. Parameters:
- float gameTimeOfDay: The current time in the cycle.
- List dayFadeObjects: Objects to fade during the day.
- List nightFadeObjects: Objects to fade during the night.
-
private void SetAlpha(List objects, float alpha)
Sets the alpha of the materials of objects in the list. Parameters:
- List objects: Objects to modify.
- float alpha: Target alpha value.
- Attach this script to a GameObject in your scene.
- Assign skybox materials, object lists, and configure durations and fade thresholds in the Inspector.
- Optionally, assign a delegate to
DefaultSceneFog
for fog transitions. - Ensure all referenced GameObjects and materials are present in the scene.
// Example 1: Setting up the WorldSceneSettings in a scene
// Attach WorldSceneSettings to a GameObject.
// Assign DaySkyboxMaterial and NightSkyBoxMaterial in the Inspector.
// Populate RotateObjects, DayObjects, NightObjects, DayFadeObjects, and NightFadeObjects as needed.
// Set DayCycleDuration and NightCycleDuration for desired cycle lengths.
// Optionally, assign a DefaultSceneFog delegate for fog transitions.
// Example 2: Accessing day/night state in another script
if (worldSceneSettingsInstance.DayNightCycle) {
// The cycle is running; check isDaytime (private) via a public method or event if needed.
}
- Use realistic cycle durations to match your game's pacing and atmosphere.
- Keep object lists organized and avoid null references.
- Use fade transitions for smooth visual changes between day and night.
- Assign skybox materials that visually represent day and night for better immersion.
- Use the
DefaultSceneFog
delegate to synchronize environmental effects with the day/night cycle.