Utils/AmbienceManager.cs
namespace HC3;
public sealed class AmbienceManager : Component
{
public static AmbienceManager Instance { get; private set; }
[ConVar( "mute_ambience", ConVarFlags.UserInfo | ConVarFlags.Saved )]
public static bool Muted { get; set; } = false;
[Property] float MaxHeight { get; set; } = 4096f;
[Property] SoundEvent WindLayer { get; set; }
[Property] SoundEvent ParkLayer { get; set; }
private SoundHandle _windySound;
private SoundHandle _parkSound;
protected override void OnStart()
{
base.OnStart();
Instance = this;
if ( WindLayer.IsValid() )
_windySound = Sound.Play( WindLayer, WorldPosition );
if ( ParkLayer.IsValid() )
_parkSound = Sound.Play( ParkLayer, WorldPosition );
}
protected override void OnUpdate()
{
float height = Scene.Camera.WorldPosition.z;
if ( WindLayer.IsValid() )
{
if ( Muted )
{
_windySound.Volume = 0;
}
else
{
_windySound.Paused = DayNightController.Instance.IsPaused;
_windySound.Volume = height.Remap( 0, MaxHeight, 0.15f, 1f );
}
}
if ( ParkLayer.IsValid() )
{
if ( Muted )
{
_parkSound.Paused = true;
}
else
{
_parkSound.Paused = DayNightController.Instance.IsPaused;
_parkSound.Volume = height.Remap( 0, MaxHeight, 0.15f, 0f );
}
}
}
}