|
|
@@ -16,7 +16,7 @@ namespace DiamondArrow
|
|
|
readonly AudioSource[] voices = new AudioSource[VoiceCount];
|
|
|
readonly float[] lastPlayed = new float[Enum.GetValues(typeof(SoundCue)).Length];
|
|
|
NeonTheme theme;
|
|
|
- bool musicEnabled, effectsEnabled, suspended, gameplay;
|
|
|
+ bool musicEnabled, effectsEnabled, suspended, gameplay, musicStopped;
|
|
|
float duckUntil;
|
|
|
int nextVoice;
|
|
|
|
|
|
@@ -57,6 +57,13 @@ namespace DiamondArrow
|
|
|
|
|
|
public void SetGameplay(bool value) { gameplay = value; }
|
|
|
|
|
|
+ // Keep music stopped for this scene even after updates or application resume.
|
|
|
+ public void StopMusic()
|
|
|
+ {
|
|
|
+ musicStopped = true;
|
|
|
+ if (MusicSource) MusicSource.Stop();
|
|
|
+ }
|
|
|
+
|
|
|
public void SetSuspended(bool value)
|
|
|
{
|
|
|
suspended = value;
|
|
|
@@ -70,7 +77,7 @@ namespace DiamondArrow
|
|
|
|
|
|
void EnsureMusic()
|
|
|
{
|
|
|
- if (!MusicSource || !MusicSource.clip || !musicEnabled || suspended || !isActiveAndEnabled) return;
|
|
|
+ if (!MusicSource || !MusicSource.clip || !musicEnabled || musicStopped || suspended || !isActiveAndEnabled) return;
|
|
|
if (!MusicSource.isPlaying)
|
|
|
{
|
|
|
MusicSource.UnPause();
|
|
|
@@ -82,7 +89,7 @@ namespace DiamondArrow
|
|
|
{
|
|
|
if (!MusicSource) return;
|
|
|
EnsureMusic();
|
|
|
- float target = musicEnabled && !suspended ? theme.musicVolume * (gameplay ? .8f : 1f) : 0;
|
|
|
+ float target = musicEnabled && !musicStopped && !suspended ? theme.musicVolume * (gameplay ? .8f : 1f) : 0;
|
|
|
if (Time.unscaledTime < duckUntil) target *= .45f;
|
|
|
MusicSource.volume = Mathf.MoveTowards(MusicSource.volume, target, Time.unscaledDeltaTime * 1.2f);
|
|
|
if (!musicEnabled && MusicSource.volume == 0 && MusicSource.isPlaying) MusicSource.Pause();
|