mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-29 09:32:38 +00:00
Sync jump and footstep sounds
This commit is contained in:
parent
0afb993062
commit
67c199f250
16
QSB/Audio/Messages/PlayerMovementAudioFootstepMessage.cs
Normal file
16
QSB/Audio/Messages/PlayerMovementAudioFootstepMessage.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using QSB.Messaging;
|
||||||
|
using QSB.Player;
|
||||||
|
using QSB.WorldSync;
|
||||||
|
|
||||||
|
namespace QSB.Audio.Messages;
|
||||||
|
|
||||||
|
|
||||||
|
public class PlayerMovementAudioFootstepMessage : QSBMessage<(AudioType audioType, float pitch, uint userID)>
|
||||||
|
{
|
||||||
|
public PlayerMovementAudioFootstepMessage(AudioType audioType, float pitch, uint userID) : base((audioType, pitch, userID)) { }
|
||||||
|
|
||||||
|
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
|
||||||
|
|
||||||
|
public override void OnReceiveRemote() =>
|
||||||
|
QSBPlayerManager.GetPlayer(Data.userID)?.AudioController?.PlayFootstep(Data.audioType, Data.pitch);
|
||||||
|
}
|
16
QSB/Audio/Messages/PlayerMovementAudioJumpMessage.cs
Normal file
16
QSB/Audio/Messages/PlayerMovementAudioJumpMessage.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using QSB.Messaging;
|
||||||
|
using QSB.Player;
|
||||||
|
using QSB.WorldSync;
|
||||||
|
|
||||||
|
namespace QSB.Audio.Messages;
|
||||||
|
|
||||||
|
|
||||||
|
public class PlayerMovementAudioJumpMessage : QSBMessage<(float pitch, uint userID)>
|
||||||
|
{
|
||||||
|
public PlayerMovementAudioJumpMessage(float pitch, uint userID) : base((pitch, userID)) { }
|
||||||
|
|
||||||
|
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
|
||||||
|
|
||||||
|
public override void OnReceiveRemote() =>
|
||||||
|
QSBPlayerManager.GetPlayer(Data.userID)?.AudioController?.OnJump(Data.pitch);
|
||||||
|
}
|
32
QSB/Audio/Patches/PlayerMovementAudioPatches.cs
Normal file
32
QSB/Audio/Patches/PlayerMovementAudioPatches.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using HarmonyLib;
|
||||||
|
using QSB.Audio.Messages;
|
||||||
|
using QSB.Messaging;
|
||||||
|
using QSB.Patches;
|
||||||
|
using QSB.Player;
|
||||||
|
|
||||||
|
namespace QSB.Audio.Patches;
|
||||||
|
|
||||||
|
internal class PlayerMovementAudioPatches : QSBPatch
|
||||||
|
{
|
||||||
|
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(PlayerMovementAudio), nameof(PlayerMovementAudio.PlayFootstep))]
|
||||||
|
public static void PlayerMovementAudio_PlayFootstep(PlayerMovementAudio __instance)
|
||||||
|
{
|
||||||
|
var underwater = !PlayerState.IsCameraUnderwater() && __instance._fluidDetector.InFluidType(FluidVolume.Type.WATER);
|
||||||
|
var audioType = underwater ? AudioType.MovementShallowWaterFootstep : PlayerMovementAudio.GetFootstepAudioType(__instance._playerController.GetGroundSurface());
|
||||||
|
|
||||||
|
if (audioType != AudioType.None)
|
||||||
|
{
|
||||||
|
new PlayerMovementAudioFootstepMessage(audioType, __instance._footstepAudio.pitch, QSBPlayerManager.LocalPlayerId).Send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(PlayerMovementAudio), nameof(PlayerMovementAudio.OnJump))]
|
||||||
|
public static void PlayerMovementAudio_OnJump(PlayerMovementAudio __instance)
|
||||||
|
{
|
||||||
|
new PlayerMovementAudioJumpMessage(__instance._jumpAudio.pitch, QSBPlayerManager.LocalPlayerId).Send();
|
||||||
|
}
|
||||||
|
}
|
@ -27,6 +27,18 @@ public class QSBPlayerAudioController : MonoBehaviour
|
|||||||
public void PlayRemoveSuit()
|
public void PlayRemoveSuit()
|
||||||
=> PlayOneShot(AudioType.PlayerSuitRemoveSuit);
|
=> PlayOneShot(AudioType.PlayerSuitRemoveSuit);
|
||||||
|
|
||||||
public void PlayOneShot(AudioType audioType)
|
public void PlayOneShot(AudioType audioType, float pitch = 1f, float volume = 1f)
|
||||||
=> _oneShotExternalSource?.PlayOneShot(audioType, 1f);
|
{
|
||||||
|
if (_oneShotExternalSource)
|
||||||
|
{
|
||||||
|
_oneShotExternalSource.pitch = pitch;
|
||||||
|
_oneShotExternalSource.PlayOneShot(audioType, volume);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PlayFootstep(AudioType audioType, float pitch) =>
|
||||||
|
PlayOneShot(audioType, pitch, 0.7f);
|
||||||
|
|
||||||
|
public void OnJump(float pitch) =>
|
||||||
|
PlayOneShot(AudioType.MovementJump, pitch, 0.7f);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user