From 7c8a765eb6d9876ff2027886445f1b63097bd146 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 28 Aug 2022 16:43:46 -0400 Subject: [PATCH] Change thruster sounds when underwater --- QSB/Audio/QSBJetpackThrusterAudio.cs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/QSB/Audio/QSBJetpackThrusterAudio.cs b/QSB/Audio/QSBJetpackThrusterAudio.cs index bd21f68c..6a93b311 100644 --- a/QSB/Audio/QSBJetpackThrusterAudio.cs +++ b/QSB/Audio/QSBJetpackThrusterAudio.cs @@ -17,10 +17,31 @@ internal class QSBJetpackThrusterAudio : QSBThrusterAudio // Taken from Player_Body settings private const float maxTranslationalThrust = 6f; + private bool _underwater; + private RemotePlayerFluidDetector _fluidDetector; + public void Init(PlayerInfo player) { _attachedPlayer = player; enabled = true; + + _fluidDetector = player.FluidDetector; + _fluidDetector.OnEnterFluidType += OnEnterExitFluidType; + _fluidDetector.OnExitFluidType += OnEnterExitFluidType; + } + + private void OnDestroy() + { + if (_fluidDetector != null) + { + _fluidDetector.OnEnterFluidType -= OnEnterExitFluidType; + _fluidDetector.OnExitFluidType -= OnEnterExitFluidType; + } + } + + private void OnEnterExitFluidType(FluidVolume.Type type) + { + _underwater = _fluidDetector.InFluidType(FluidVolume.Type.WATER); } private void Update() @@ -37,13 +58,12 @@ internal class QSBJetpackThrusterAudio : QSBThrusterAudio // TODO: Sync var usingBooster = false; var usingOxygen = false; - var underwater = false; float targetVolume = usingBooster ? 0f : thrustFraction; float targetPan = -acc.x / maxTranslationalThrust * 0.4f; - UpdateTranslationalSource(_translationalSource, targetVolume, targetPan, !underwater && !usingOxygen); - UpdateTranslationalSource(_underwaterSource, targetVolume, targetPan, underwater); - UpdateTranslationalSource(_oxygenSource, targetVolume, targetPan, !underwater && usingOxygen); + UpdateTranslationalSource(_translationalSource, targetVolume, targetPan, !_underwater && !usingOxygen); + UpdateTranslationalSource(_underwaterSource, targetVolume, targetPan, _underwater); + UpdateTranslationalSource(_oxygenSource, targetVolume, targetPan, !_underwater && usingOxygen); if (!_wasBoosting && usingBooster) {