Sound updates

This commit is contained in:
2025-12-13 17:27:04 +01:00
parent 3bc8db347d
commit 42a32f5fe4
8 changed files with 86 additions and 13 deletions

View File

@@ -6,8 +6,9 @@ using VRC.Udon;
public class SoundManager : UdonSharpBehaviour
{
[SerializeField] private AudioSource audioSourcePlayer;
[SerializeField] private AudioSource audioSourcePacMan;
[SerializeField] private AudioSource audioSourceGhosts;
[SerializeField] private AudioSource audioSourceExtraLife;
[SerializeField] private AudioClip pacStart;
[SerializeField] private AudioClip pacDot1;
@@ -19,6 +20,7 @@ public class SoundManager : UdonSharpBehaviour
[SerializeField] private AudioClip pacGhost1;
[SerializeField] private AudioClip pacGhostBlue;
[SerializeField] private AudioClip pacGhostRetreat;
[SerializeField] private AudioClip pacExtraLife;
private AudioClip _nextDotSound;
private bool _isRetreating;
@@ -33,10 +35,12 @@ public class SoundManager : UdonSharpBehaviour
public void Reset()
{
StopAllSound();
_nextDotSound = pacDot2;
_isRetreating = false;
_isBlue = false;
_suppress = false;
_suppress = true;
}
public void SuppressSound(bool suppress)
@@ -51,37 +55,44 @@ public class SoundManager : UdonSharpBehaviour
public void PlayGameStartSound()
{
PlaySound(audioSourcePlayer, pacStart);
PlaySound(audioSourcePacMan, pacStart);
}
public void PlayPelletSound()
{
PlaySound(audioSourcePlayer, _nextDotSound);
PlaySound(audioSourcePacMan, _nextDotSound);
_nextDotSound = _nextDotSound == pacDot1 ? pacDot2 : pacDot1;
}
public void PlayDeathSound()
{
PlaySound(audioSourcePlayer, pacDie1);
PlaySound(audioSourcePacMan, pacDie1);
}
public void PlayFruitSound()
{
PlaySound(audioSourcePlayer, pacFruit);
PlaySound(audioSourcePacMan, pacFruit);
}
public void PlayCoinSound()
{
PlaySound(audioSourcePlayer, pacCoin);
PlaySound(audioSourcePacMan, pacCoin);
}
public void PlayGhostEatSound()
{
PlaySound(audioSourcePlayer, pacGhostEat);
PlaySound(audioSourcePacMan, pacGhostEat);
}
public void PlayExtraLifeSound()
{
PlaySound(audioSourceExtraLife, pacExtraLife);
}
public void StartGhostSound(bool isBlue)
{
Debug.Log($"Start ghost sound, isBlue: {isBlue}, _isRetreating: {_isRetreating}, _suppress: {_suppress}");
_isBlue = isBlue;
if (_isRetreating)
@@ -102,6 +113,8 @@ public class SoundManager : UdonSharpBehaviour
public void EndGhostRetreat()
{
Debug.Log("End ghost retreating");
if (!_isRetreating)
{
return;
@@ -114,18 +127,20 @@ public class SoundManager : UdonSharpBehaviour
public void StopAllSound()
{
audioSourcePlayer.Stop();
audioSourcePacMan.Stop();
audioSourceGhosts.Stop();
// audioSourceExtraLife is not stopped on purpose, this sound is never interrupted
}
private void PlaySound(AudioSource audioSource, AudioClip audioClip, bool loop = false)
{
// Debug.Log($"PlaySound, audioSource: {audioSource}, audioClip: {audioClip}, loop: {loop}, suppress: {_suppress}");
if (_suppress)
{
return;
}
if (loop && audioSource.clip == audioClip)
if (loop && audioSource.clip == audioClip && audioSource.isPlaying)
{
// Don't restart a looping sound
return;