Audio Support, Speed shift music, AudioProvider.Unk/Bunk

Also AudioHelper.SetVolume's
This commit is contained in:
Texel 2020-08-22 07:13:21 -04:00
parent af9d68b631
commit 5c5a9d2993
2 changed files with 43 additions and 4 deletions

View File

@ -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:

View File

@ -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<AudioSource>();
UnkClip = Resources.Load<AudioClip>("Unk");
BunkClip = Resources.Load<AudioClip>("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;