8170b700b2
Features: Sacrifice-Node, Maintain-Node, Options for screen type, lightcolor and soundvolume, tied in sound effects, game pause when menu is open, visibly open up gate when opening it.
45 lines
1.0 KiB
C#
45 lines
1.0 KiB
C#
using Godot;
|
|
|
|
public partial class SoundManager : Node
|
|
{
|
|
private static SoundManager instance;
|
|
|
|
[Export] private AudioStreamPlayer buttonSound;
|
|
[Export] private AudioStreamPlayer miningSound;
|
|
|
|
public override void _Ready()
|
|
{
|
|
instance = this;
|
|
}
|
|
|
|
public override void _ExitTree()
|
|
{
|
|
if (instance == this)
|
|
{
|
|
instance = null;
|
|
}
|
|
}
|
|
|
|
public static void PlayButton()
|
|
{
|
|
if (instance == null || instance.buttonSound == null) return;
|
|
|
|
instance.buttonSound.Play();
|
|
}
|
|
|
|
public static void PlayMining()
|
|
{
|
|
if (instance == null || instance.miningSound == null) return;
|
|
|
|
instance.miningSound.Play();
|
|
}
|
|
|
|
public static void SetMasterVolume(float percent)
|
|
{
|
|
percent = Mathf.Clamp(percent, 0f, 1f);
|
|
int busIndex = AudioServer.GetBusIndex("Master");
|
|
AudioServer.SetBusVolumeDb(busIndex, Mathf.LinearToDb(percent));
|
|
AudioServer.SetBusMute(busIndex, percent <= 0f);
|
|
}
|
|
}
|