Fork Lifter: Pea zoom sound lines up (mostly) independent of bpm

This commit is contained in:
Jenny Crowe
2022-02-05 06:08:33 -07:00
parent 217849e666
commit dfed5a879f
5 changed files with 72 additions and 4 deletions

View File

@ -57,6 +57,26 @@ namespace RhythmHeavenMania.Util
GameManager.instance.SoundObjects.Add(oneShot);
}
public static void PlayOneShotScheduled(string name, double targetTime)
{
GameObject oneShot = new GameObject("oneShotScheduled");
var audioSource = oneShot.AddComponent<AudioSource>();
audioSource.playOnAwake = false;
var snd = oneShot.AddComponent<Sound>();
var clip = Resources.Load<AudioClip>($"Sfx/{name}");
audioSource.clip = clip;
snd.clip = clip;
snd.scheduled = true;
snd.scheduledTime = targetTime;
audioSource.PlayScheduled(targetTime);
GameManager.instance.SoundObjects.Add(oneShot);
}
public static void PlayOneShotGame(string name, float beat = -1)
{
if (GameManager.instance.currentGame == name.Split('/')[0])
@ -64,6 +84,14 @@ namespace RhythmHeavenMania.Util
PlayOneShot($"games/{name}", beat);
}
}
public static void PlayOneShotScheduledGame(string name, double targetTime)
{
if (GameManager.instance.currentGame == name.Split('/')[0])
{
PlayOneShotScheduled($"games/{name}", targetTime);
}
}
}
}

View File

@ -9,6 +9,10 @@ namespace RhythmHeavenMania.Util
public AudioClip clip;
public float pitch = 1;
// For use with PlayOneShotScheduled
public bool scheduled;
public double scheduledTime;
private AudioSource audioSource;
private int pauseTimes = 0;
@ -26,7 +30,7 @@ namespace RhythmHeavenMania.Util
audioSource.clip = clip;
audioSource.pitch = pitch;
if (beat == -1)
if (beat == -1 && !scheduled)
{
audioSource.PlayScheduled(Time.time);
playInstant = true;
@ -39,12 +43,21 @@ namespace RhythmHeavenMania.Util
startTime = Conductor.instance.songPosition;
StartCoroutine(NotRelyOnBeatSound());
if (!scheduled)
StartCoroutine(NotRelyOnBeatSound());
}
private void Update()
{
if (!playInstant)
if (scheduled)
{
if (AudioSettings.dspTime > scheduledTime)
{
StartCoroutine(NotRelyOnBeatSound());
playIndex++;
}
}
else if (!playInstant)
{
if (Conductor.instance.songPositionInBeats > beat && playIndex < 1)
{