Progress
This commit is contained in:
@@ -12,16 +12,41 @@ public class SoundManager : UdonSharpBehaviour
|
||||
[SerializeField] private AudioClip pacStart;
|
||||
[SerializeField] private AudioClip pacDot1;
|
||||
[SerializeField] private AudioClip pacDot2;
|
||||
[SerializeField] private AudioClip pacDie1;
|
||||
[SerializeField] private AudioClip pacFruit;
|
||||
[SerializeField] private AudioClip pacCoin;
|
||||
[SerializeField] private AudioClip pacGhostEat;
|
||||
[SerializeField] private AudioClip pacGhost1;
|
||||
[SerializeField] private AudioClip pacGhostBlue;
|
||||
[SerializeField] private AudioClip pacGhostRetreat;
|
||||
|
||||
private AudioClip nextDotSound;
|
||||
private AudioClip _nextDotSound;
|
||||
private bool _isRetreating;
|
||||
private bool _isBlue;
|
||||
|
||||
private bool _suppress;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
nextDotSound = pacDot2;
|
||||
Reset();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_nextDotSound = pacDot2;
|
||||
_isRetreating = false;
|
||||
_isBlue = false;
|
||||
_suppress = false;
|
||||
}
|
||||
|
||||
public void SuppressSound(bool suppress)
|
||||
{
|
||||
_suppress = suppress;
|
||||
|
||||
if (suppress)
|
||||
{
|
||||
StopAllSound();
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayGameStartSound()
|
||||
@@ -31,8 +56,13 @@ public class SoundManager : UdonSharpBehaviour
|
||||
|
||||
public void PlayPelletSound()
|
||||
{
|
||||
PlaySound(audioSourcePlayer, nextDotSound);
|
||||
nextDotSound = nextDotSound == pacDot1 ? pacDot2 : pacDot1;
|
||||
PlaySound(audioSourcePlayer, _nextDotSound);
|
||||
_nextDotSound = _nextDotSound == pacDot1 ? pacDot2 : pacDot1;
|
||||
}
|
||||
|
||||
public void PlayDeathSound()
|
||||
{
|
||||
PlaySound(audioSourcePlayer, pacDie1);
|
||||
}
|
||||
|
||||
public void PlayFruitSound()
|
||||
@@ -50,9 +80,36 @@ public class SoundManager : UdonSharpBehaviour
|
||||
PlaySound(audioSourcePlayer, pacGhostEat);
|
||||
}
|
||||
|
||||
public void StartGhostSound()
|
||||
public void StartGhostSound(bool isBlue)
|
||||
{
|
||||
PlaySound(audioSourceGhosts, pacGhost1, true);
|
||||
_isBlue = isBlue;
|
||||
|
||||
if (_isRetreating)
|
||||
{
|
||||
// Retreating overrides other ghost sound
|
||||
return;
|
||||
}
|
||||
|
||||
var sound = _isBlue ? pacGhostBlue : pacGhost1;
|
||||
PlaySound(audioSourceGhosts, sound, true);
|
||||
}
|
||||
|
||||
public void StartGhostRetreat()
|
||||
{
|
||||
_isRetreating = true;
|
||||
PlaySound(audioSourceGhosts, pacGhostRetreat, true);
|
||||
}
|
||||
|
||||
public void EndGhostRetreat()
|
||||
{
|
||||
if (!_isRetreating)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isRetreating = false;
|
||||
|
||||
StartGhostSound(_isBlue);
|
||||
}
|
||||
|
||||
public void StopAllSound()
|
||||
@@ -63,6 +120,17 @@ public class SoundManager : UdonSharpBehaviour
|
||||
|
||||
private void PlaySound(AudioSource audioSource, AudioClip audioClip, bool loop = false)
|
||||
{
|
||||
if (_suppress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (loop && audioSource.clip == audioClip)
|
||||
{
|
||||
// Don't restart a looping sound
|
||||
return;
|
||||
}
|
||||
|
||||
audioSource.clip = audioClip;
|
||||
audioSource.Play();
|
||||
audioSource.loop = loop;
|
||||
|
||||
Reference in New Issue
Block a user