From 39e14e9e073e6a4671095198f42e60ceeb136b21 Mon Sep 17 00:00:00 2001 From: Jenny Crowe Date: Sat, 5 Feb 2022 06:08:33 -0700 Subject: [PATCH 1/5] Fork Lifter: Pea zoom sound lines up (mostly) independent of bpm --- .../Sfx/games/forkLifter/zoomFast.ogg.meta | 22 +++++++++++++++ Assets/Scripts/Games/ForkLifter/Pea.cs | 7 ++++- Assets/Scripts/Util/Jukebox.cs | 28 +++++++++++++++++++ Assets/Scripts/Util/Sound.cs | 19 +++++++++++-- 4 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 Assets/Resources/Sfx/games/forkLifter/zoomFast.ogg.meta diff --git a/Assets/Resources/Sfx/games/forkLifter/zoomFast.ogg.meta b/Assets/Resources/Sfx/games/forkLifter/zoomFast.ogg.meta new file mode 100644 index 00000000..94fbab57 --- /dev/null +++ b/Assets/Resources/Sfx/games/forkLifter/zoomFast.ogg.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: bae94bedea157574fa32d28216adaf01 +AudioImporter: + externalObjects: {} + serializedVersion: 6 + defaultSettings: + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + preloadAudioData: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Games/ForkLifter/Pea.cs b/Assets/Scripts/Games/ForkLifter/Pea.cs index 20d57a37..c62decbf 100644 --- a/Assets/Scripts/Games/ForkLifter/Pea.cs +++ b/Assets/Scripts/Games/ForkLifter/Pea.cs @@ -19,7 +19,12 @@ namespace RhythmHeavenMania.Games.ForkLifter private void Start() { anim = GetComponent(); - Jukebox.PlayOneShotGame("forkLifter/zoom"); + + // SCHEDULING zoom sound so it lines up with when it meets the fork. + var currentDspTime = AudioSettings.dspTime; + var zoomStartTime = currentDspTime + (double)(Conductor.instance.secPerBeat * 2) - 0.317; + Jukebox.PlayOneShotScheduledGame("forkLifter/zoomFast", (double)zoomStartTime); + GetComponentInChildren().sprite = ForkLifter.instance.peaSprites[type]; for (int i = 0; i < transform.GetChild(0).childCount; i++) diff --git a/Assets/Scripts/Util/Jukebox.cs b/Assets/Scripts/Util/Jukebox.cs index 9bb1cae1..50fa63b7 100644 --- a/Assets/Scripts/Util/Jukebox.cs +++ b/Assets/Scripts/Util/Jukebox.cs @@ -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.playOnAwake = false; + + var snd = oneShot.AddComponent(); + + var clip = Resources.Load($"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); + } + } } } \ No newline at end of file diff --git a/Assets/Scripts/Util/Sound.cs b/Assets/Scripts/Util/Sound.cs index defab47e..cb1b0615 100644 --- a/Assets/Scripts/Util/Sound.cs +++ b/Assets/Scripts/Util/Sound.cs @@ -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) { From 82e53cbb16ef146c2b9e149ed1974fc2253061b6 Mon Sep 17 00:00:00 2001 From: Jenny Crowe Date: Sat, 5 Feb 2022 06:22:18 -0700 Subject: [PATCH 2/5] Fork Lifter: Zoom sound scheduling takes song speed into account. --- Assets/Scripts/Games/ForkLifter/Pea.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Games/ForkLifter/Pea.cs b/Assets/Scripts/Games/ForkLifter/Pea.cs index c62decbf..723e74ff 100644 --- a/Assets/Scripts/Games/ForkLifter/Pea.cs +++ b/Assets/Scripts/Games/ForkLifter/Pea.cs @@ -22,7 +22,8 @@ namespace RhythmHeavenMania.Games.ForkLifter // SCHEDULING zoom sound so it lines up with when it meets the fork. var currentDspTime = AudioSettings.dspTime; - var zoomStartTime = currentDspTime + (double)(Conductor.instance.secPerBeat * 2) - 0.317; + var cond = Conductor.instance; + var zoomStartTime = currentDspTime + (double)(cond.secPerBeat * 2 / cond.musicSource.pitch) - 0.317; Jukebox.PlayOneShotScheduledGame("forkLifter/zoomFast", (double)zoomStartTime); GetComponentInChildren().sprite = ForkLifter.instance.peaSprites[type]; From befa71a1359a468dcfa8ac7b1edb638336e31a53 Mon Sep 17 00:00:00 2001 From: Jenny Crowe Date: Sat, 5 Feb 2022 06:47:47 -0700 Subject: [PATCH 3/5] Editor: Autoplay button updates at start to reflect autoplay status. --- Assets/Scripts/LevelEditor/Timeline/Timeline.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Assets/Scripts/LevelEditor/Timeline/Timeline.cs b/Assets/Scripts/LevelEditor/Timeline/Timeline.cs index f943747b..13ab01b3 100644 --- a/Assets/Scripts/LevelEditor/Timeline/Timeline.cs +++ b/Assets/Scripts/LevelEditor/Timeline/Timeline.cs @@ -189,6 +189,14 @@ namespace RhythmHeavenMania.Editor.Track MetronomeBTN.transform.GetChild(0).GetComponent().color = Color.gray; timelineState.SetState(true, false, false); + + AutoBtnUpdate(); + } + + public void AutoBtnUpdate() + { + var animName = GameManager.instance.autoplay ? "Idle" : "Disabled"; + AutoplayBTN.GetComponent().Play(animName, 0, 0); } public static string RandomID() From 5363eb9ee54b873262496d7dc5ffc5a8233e7661 Mon Sep 17 00:00:00 2001 From: Jenny Crowe Date: Sat, 5 Feb 2022 06:50:18 -0700 Subject: [PATCH 4/5] Music mixer: Removed lowpass filter (music wasn't playing while it was there and active. If it needs to be there pls make sure the music still plays properly by default.) --- Assets/Resources/MainMixer.mixer | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/Assets/Resources/MainMixer.mixer b/Assets/Resources/MainMixer.mixer index e6c544d6..7dd510fa 100644 --- a/Assets/Resources/MainMixer.mixer +++ b/Assets/Resources/MainMixer.mixer @@ -1,23 +1,5 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: ---- !u!244 &-7482437823656399522 -AudioMixerEffectController: - m_ObjectHideFlags: 3 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: - m_EffectID: edde4d902ac6edc4d9d67a8c9e433fb6 - m_EffectName: Lowpass - m_MixLevel: 6a832196d6ceedd48bbde9fbe4177202 - m_Parameters: - - m_ParameterName: Cutoff freq - m_GUID: 911cb1bf4bb1b624ab3a68e1eb57ba29 - - m_ParameterName: Resonance - m_GUID: 1f89dac5f0e643c4ab8774d8ad05e968 - m_SendTarget: {fileID: 0} - m_EnableWetMix: 0 - m_Bypass: 0 --- !u!243 &-7454359775428337364 AudioMixerGroupController: m_ObjectHideFlags: 0 @@ -33,7 +15,6 @@ AudioMixerGroupController: m_Send: 00000000000000000000000000000000 m_Effects: - {fileID: -3827691611382659438} - - {fileID: -7482437823656399522} m_UserColorIndex: 0 m_Mute: 0 m_Solo: 0 From 1ca1177974f71292324e9e5443b3a70ec7645dd1 Mon Sep 17 00:00:00 2001 From: Jenny Crowe Date: Sat, 5 Feb 2022 08:24:07 -0700 Subject: [PATCH 5/5] Forgot a playIndex comparison whoops --- Assets/Scripts/Util/Sound.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/Util/Sound.cs b/Assets/Scripts/Util/Sound.cs index cb1b0615..b4b13799 100644 --- a/Assets/Scripts/Util/Sound.cs +++ b/Assets/Scripts/Util/Sound.cs @@ -51,7 +51,7 @@ namespace RhythmHeavenMania.Util { if (scheduled) { - if (AudioSettings.dspTime > scheduledTime) + if (AudioSettings.dspTime > scheduledTime && playIndex < 1) { StartCoroutine(NotRelyOnBeatSound()); playIndex++;