Skip to main content

AtmosphereManager

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

Runs the scene's atmosphere plugins (ambient light, fog, sky, ambient audio) and blends between atmosphere sets as the local player moves between chunks. A single instance in AtmosphereManager.instance; does its visible work on clients.

Constructors​

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

Fields​

MemberWhat it is
static AtmosphereManager instanceThe current manager, set on Awake and Initialize.
9 private and internal fields
MemberWhat it is
private float ambienceLerpTimeBacking field for AmbienceLerpTime.
private AtmospherePlugin[] availablePluginsThe child atmosphere plugins; sets enable or disable them by index.
private AtmosphereSet baseSetThe default atmosphere set used when the chunk has no override.
private int currentPriorityPluginIndex of the plugin that currently has priority, or -1 when none.
private AtmosphereSet currentSetBacking field for CurrentSet.
private static Logger loggerNLog logger for this class.
private float positionLerpSpeedBacking field for PositionLerpSpeed.
private bool saveEditor toggle for saving a new set; it only resets itself in this build.
private string setNameEditor name for a new atmosphere set.

Properties​

MemberWhat it is
LerpingFloatValue AmbienceAudio { get; private set; }Blend value between main (1) and secondary (0) ambient audio.
float AmbienceLerpTime { get; }Seconds to blend ambience when changing sets.
AtmosphereColor AmbientColor { get; private set; }Blended ambient light colour, written to RenderSettings.ambientLight.
AtmospherePlugin[] AtmospherePlugins { get; }The plugin components under the manager.
Color CurrentFogColor { get; }The current RenderSettings.fogColor.
float CurrentFogDensity { get; }The current RenderSettings.fogDensity.
AtmosphereSet CurrentSet { get; }The atmosphere set last applied.
AtmosphereColor FogColor { get; private set; }Blended fog colour, also pushed to the global fog shader colour.
LerpingControlledFloatValue FogDensity { get; private set; }Blended fog density.
AtmospherePlugin MainAudio { get; private set; }Plugin playing the main ambient audio.
float PositionLerpSpeed { get; }Speed plugins use to follow positions.
AtmospherePlugin SecondaryAudio { get; private set; }Plugin whose ambient audio is fading out.

Events​

MemberWhat it is
event AtmosphereManager.ResolveAtmosphere ResolveLets you replace the set chosen for a chunk before it is applied. Pass the set by ref.

Methods​

MemberWhat it is
bool CheckPriority(AtmospherePlugin plugin)Makes a plugin the priority one if it ranks at least as high as the current; returns whether it is.
void ClearPriority(AtmospherePlugin plugin)Clears priority if the given plugin had it.
AtmospherePlugin GetHighestPlugin(AtmosphereSet set)Meant to return the highest priority enabled plugin in a set; in this build it returns the last enabled one.
override void Initialize()Sets up all plugins and blended values and applies the base set.
override void OnConnected(Player player)Passes a new player on to every plugin.
void ReadAtmosphereSet(AtmosphereSet set, Color? overrideAmbience = null)Applies a set: turns plugins on or off and blends ambience, optionally with an ambient colour override.
void ReturnToBase()Applies the local player's chunk override set, or the base set.
void SetAudio(AtmospherePlugin newAudioPlugin, bool isRegularLerping = true)Makes a plugin the main audio and fades the old one out.
void SetBackGroundAudioSet(AtmosphereSet newBackGroundSet)Starts a set's audio plugin as the secondary (background) audio.
protected void Awake()Sets the instance and hooks the local player's spawn and chunk changes.
9 private and internal methods
MemberWhat it is
private void EnsureAtmosphere(LocationChunk chunk)Applies the chunk's override atmosphere set (after Resolve handlers can change it) when the local player changes chunk.
private void InitializeProperties()Creates the lerping ambient colour, fog colour, fog density and ambience volume values that drive render settings, and hooks audio muting.
private void LocalPlayerSet(IPlayer player)Hooks the local player's chunk changes so the atmosphere follows them.
private void OnDestroy()Unhooks the local player events.
private void OnValidate()Collects the child AtmospherePlugin components into availablePlugins.
private void OverrideAtmosphere(PlayerController player)When the local player controller spawns, finds the chunk containing it and applies that chunk's atmosphere.
private void SetupNewMainAudio(AtmospherePlugin newAudioPlugin, bool isRegularLerping)Makes a plugin the main ambience audio, moves the old one to secondary and crossfades between them.
private void ToggleGlobalAmbienceMute(bool isMuted)Mutes or unmutes the main ambience audio when the audio manager's mute changes.
private void Update()Steps the ambient colour, fog and ambience volume lerps each frame.

Used in​

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