Better Sound Sequences (#190)

* add way of creating sound sequences in inspector

- actually implement GameAction preFunction
- implement sound scheduling for Jukebox and MultiSound

* Dj School: fix turntable effect being parented to root

* Pajama Party: fix sleep action type not carrying over between transitions
This commit is contained in:
minenice55
2023-01-04 23:04:31 -05:00
committed by GitHub
parent 22133a5c54
commit 87d20b8c8f
28 changed files with 392 additions and 108 deletions

View File

@ -22,16 +22,22 @@ namespace HeavenStudio
// Current song position, in seconds
private double songPos; // for Conductor use only
public float songPosition => (float) songPos;
public double songPositionAsDouble => songPos;
// Current song position, in beats
private double songPosBeat; // for Conductor use only
public float songPositionInBeats => (float) songPosBeat;
public double songPositionInBeatsAsDouble => songPosBeat;
// Current time of the song
private double time;
double lastAbsTime;
// the dspTime we started at
private double dspStartTime;
public double dspStartTimeAsDouble => dspStartTime;
// an AudioSource attached to this GameObject that will play the music.
public AudioSource musicSource;
@ -52,6 +58,7 @@ namespace HeavenStudio
// Metronome tick sound enabled
public bool metronome = false;
Util.Sound metronomeSound;
public float timeSinceLastTempoChange = Single.MinValue;
@ -142,6 +149,7 @@ namespace HeavenStudio
}
}
lastAbsTime = Time.realtimeSinceStartupAsDouble;
dspStartTime = AudioSettings.dspTime;
// GameManager.instance.SetCurrentEventToClosest(songPositionInBeats);
}
@ -189,13 +197,21 @@ namespace HeavenStudio
{
if (ReportBeat(ref lastReportedBeat))
{
Util.Jukebox.PlayOneShot("metronome");
metronomeSound = Util.Jukebox.PlayOneShot("metronome", lastReportedBeat + 1f);
}
else if (songPositionInBeats < lastReportedBeat)
{
lastReportedBeat = Mathf.Round(songPositionInBeats);
}
}
else
{
if (metronomeSound != null)
{
metronomeSound.Delete();
metronomeSound = null;
}
}
}
public bool ReportBeat(ref float lastReportedBeat, float offset = 0, bool shiftBeatToOffset = true)