diff --git a/Assets/Scripts/Games/BuiltToScaleDS/BuiltToScaleDS.cs b/Assets/Scripts/Games/BuiltToScaleDS/BuiltToScaleDS.cs index d3ac7540..099eea22 100644 --- a/Assets/Scripts/Games/BuiltToScaleDS/BuiltToScaleDS.cs +++ b/Assets/Scripts/Games/BuiltToScaleDS/BuiltToScaleDS.cs @@ -190,10 +190,7 @@ namespace RhythmHeavenMania.Games.BuiltToScaleDS var pianoPitch = Mathf.Pow(2f, (1f / 12f) * semiTones) *Conductor.instance.musicSource.pitch; var pianoSource = Jukebox.PlayOneShotGame("builtToScaleDS/Piano", -1, pianoPitch, 0.8f, true); - BeatAction.New(gameObject, new List() - { - new BeatAction.Action(beat + length, delegate { Jukebox.KillLoop(pianoSource, 0.1f); }) - }); + Jukebox.SetLoopParams(pianoSource, beat + length, 0.1f); } } } \ No newline at end of file diff --git a/Assets/Scripts/Util/Jukebox.cs b/Assets/Scripts/Util/Jukebox.cs index bb082a71..09d0c5e2 100644 --- a/Assets/Scripts/Util/Jukebox.cs +++ b/Assets/Scripts/Util/Jukebox.cs @@ -107,6 +107,17 @@ namespace RhythmHeavenMania.Util return null; } + // Loops play forever by default unless you set their params via this method. + public static void SetLoopParams(AudioSource source, float endBeat, float fadeTime) + { + if (source == null) + return; + + var snd = source.GetComponent(); + snd.loopEndBeat = endBeat; + snd.fadeTime = fadeTime; + } + public static void KillLoop(AudioSource source, float fadeTime) { // Safeguard against previously-destroyed sounds. diff --git a/Assets/Scripts/Util/Sound.cs b/Assets/Scripts/Util/Sound.cs index 2b6e69c6..6094cfee 100644 --- a/Assets/Scripts/Util/Sound.cs +++ b/Assets/Scripts/Util/Sound.cs @@ -15,6 +15,9 @@ namespace RhythmHeavenMania.Util public double scheduledTime; public bool looping; + public float loopEndBeat = -1; + public float fadeTime; + int loopIndex = 0; private AudioSource audioSource; @@ -73,6 +76,18 @@ namespace RhythmHeavenMania.Util } } } + + if (loopIndex < 1) + { + if (looping && loopEndBeat != -1) + { + if (Conductor.instance.songPositionInBeats > loopEndBeat) + { + KillLoop(fadeTime); + loopIndex++; + } + } + } } IEnumerator NotRelyOnBeatSound()