From 5c5a9d299321d8156ca8e94ab974b6858ea8b379 Mon Sep 17 00:00:00 2001 From: Touhexel Date: Sat, 22 Aug 2020 07:13:21 -0400 Subject: [PATCH] Audio Support, Speed shift music, AudioProvider.Unk/Bunk Also AudioHelper.SetVolume's --- Assets/Audio/Resources/BGMMixer.mixer | 7 +++-- Assets/Code/AudioProvider.cs | 40 +++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Assets/Audio/Resources/BGMMixer.mixer b/Assets/Audio/Resources/BGMMixer.mixer index c4ffbe0..cd1a593 100644 --- a/Assets/Audio/Resources/BGMMixer.mixer +++ b/Assets/Audio/Resources/BGMMixer.mixer @@ -15,7 +15,9 @@ AudioMixerController: m_SuspendThreshold: -80 m_EnableSuspend: 1 m_UpdateMode: 0 - m_ExposedParameters: [] + m_ExposedParameters: + - guid: 488bd2ac94838f14cadbca3c4455b0de + name: ShiftPitch m_AudioMixerGroupViews: - guids: - 566c5e0ddf85965418c4e928780bd1c2 @@ -65,7 +67,8 @@ AudioMixerSnapshotController: m_Name: Snapshot m_AudioMixer: {fileID: 24100000} m_SnapshotID: 4117f6b7fd784794ba09e4c024f88699 - m_FloatValues: {} + m_FloatValues: + 488bd2ac94838f14cadbca3c4455b0de: 1 m_TransitionOverrides: {} --- !u!244 &2747661610774394998 AudioMixerEffectController: diff --git a/Assets/Code/AudioProvider.cs b/Assets/Code/AudioProvider.cs index cb9c3bb..bb855d1 100644 --- a/Assets/Code/AudioProvider.cs +++ b/Assets/Code/AudioProvider.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using UnityEngine; +using UnityEngine.Audio; + using EntityNetwork; public class AudioProvider : EntityBase, IAutoRegister @@ -12,14 +14,48 @@ public class AudioProvider : EntityBase, IAutoRegister Instance = this; bgmSrc = GetComponent(); + + UnkClip = Resources.Load("Unk"); + BunkClip = Resources.Load("Bunk"); } public float musicSpeed = 1f; AudioSource bgmSrc; + public bool fastBGM = false; + + [ContextMenu("Speedup Music for 5s")] + public void SpeedupForFiveSeconds() { + Instance.fastBGM = true; + timeUntilSlow = Time.time + 5f; + } + + public static float timeUntilSlow = 0f; + public static void RequestFastMusic() { + Instance.fastBGM = true; + timeUntilSlow = Time.time + 3f; + } + + static AudioClip UnkClip, BunkClip; + + public static void Unk() { + PlaySFX(UnkClip, AudioHelper.AudioCategory.Fx); + } + + public static void Bunk() { + PlaySFX(BunkClip, AudioHelper.AudioCategory.Fx); + } + public void Update() { - // TODO - This is WIP help - //bgmSrc.outputAudioMixerGroup. + bgmSrc.loop = true; + + bgmSrc.volume = AudioHelper.VolumeLevel(AudioHelper.AudioCategory.Music); + + bgmSrc.pitch = fastBGM ? 1.3333f : 1f; + bgmSrc.outputAudioMixerGroup.audioMixer.SetFloat("ShiftPitch", fastBGM ? 0.75f : 1f); + + if (Time.time > timeUntilSlow) + fastBGM = false; } int lastAudioFrame = 0;