34 lines
1.4 KiB
C#
34 lines
1.4 KiB
C#
using BlockOutReplica.Gameplay;
|
|
using UnityEngine;
|
|
|
|
namespace BlockOutReplica.Presentation
|
|
{
|
|
public sealed class BlockOutGameAudio : MonoBehaviour
|
|
{
|
|
public static bool SoundsEnabled { get; private set; } = true;
|
|
private BlockOutPlayerState player;
|
|
private AudioSource music, effects;
|
|
public void Initialize(BlockOutPlayerState state)
|
|
{
|
|
player = state;
|
|
if (music == null) { music = gameObject.AddComponent<AudioSource>(); music.loop = true; music.volume = .15f; music.playOnAwake = false; }
|
|
if (effects == null) { effects = gameObject.AddComponent<AudioSource>(); effects.volume = .4f; effects.playOnAwake = false; }
|
|
ApplySettings();
|
|
}
|
|
public void ApplySettings()
|
|
{ if (player == null) return; SoundsEnabled = player.Sounds; effects.mute = !player.Sounds; music.mute = !player.Music; }
|
|
public void SetHome(bool home)
|
|
{
|
|
AudioClip clip = Resources.Load<AudioClip>("OriginalInteractions/Audio/" + (home ? "home-music2" : "gameplay-music"));
|
|
if (music.clip == clip) return;
|
|
music.clip = clip; if (clip != null) music.Play();
|
|
}
|
|
public void Play(string name)
|
|
{
|
|
if (!SoundsEnabled) return;
|
|
var clip = Resources.Load<AudioClip>("OriginalInteractions/Audio/" + name);
|
|
if (clip != null) effects.PlayOneShot(clip);
|
|
}
|
|
}
|
|
}
|