Compare commits

...

2 Commits

Author SHA1 Message Date
1252933ca4 Improving sync 2026-06-22 18:31:16 +02:00
d6b870de79 SoundManager sync 2026-06-22 16:03:46 +02:00
8 changed files with 188 additions and 105 deletions

View File

@@ -16,7 +16,6 @@ namespace Marro.PacManUdon
[SerializeField] private GameObject intermissionScreen; [SerializeField] private GameObject intermissionScreen;
[SerializeField] private GameObject pressStartButtonScreen; [SerializeField] private GameObject pressStartButtonScreen;
[SerializeField] private PlayerInput playerInput; [SerializeField] private PlayerInput playerInput;
[SerializeField] private Animator demo;
[SerializeField] private SoundManager soundManager; [SerializeField] private SoundManager soundManager;
[SerializeField] private NetworkManager networkManagerSetup; [SerializeField] private NetworkManager networkManagerSetup;
@@ -143,6 +142,7 @@ namespace Marro.PacManUdon
bonusFruit.Despawn(); bonusFruit.Despawn();
soundManager.Reset(); soundManager.Reset();
collisionManager.Reset(); collisionManager.Reset();
statusDisplay.Reset();
} }
private void PrepareForCutscene() private void PrepareForCutscene()
@@ -263,7 +263,6 @@ namespace Marro.PacManUdon
statusDisplay.SetLevelDisplayVisible(false); statusDisplay.SetLevelDisplayVisible(false);
statusDisplay.SetPlayer1TextVisible(false); statusDisplay.SetPlayer1TextVisible(false);
statusDisplay.SetReadyTextVisible(false); statusDisplay.SetReadyTextVisible(false);
demo.gameObject.SetActive(false);
} }
void SetPelletsActive(bool active) void SetPelletsActive(bool active)
@@ -373,6 +372,27 @@ namespace Marro.PacManUdon
soundManager.PlayExtraLifeSound(); soundManager.PlayExtraLifeSound();
} }
private void SetupInGameState()
{
gameState = PacManGameState.InGame;
attractScreen.gameObject.SetActive(false);
SetPelletsActive(true);
SetMazeVisible(true);
SetGhostsActive(true);
SetPacManActive(true);
statusDisplay.SetExtraLivesDisplayVisible(true);
statusDisplay.SetLevelDisplayVisible(true);
statusDisplay.SetLabel1UPTextBlinking(true);
soundManager.SuppressSound(false);
soundManager.StartGhostSound();
SetFrozen(false);
}
public void SetFrozen(bool frozen, bool ghostIgnoreIfCaught = false, bool ghostKeepAnimating = false) public void SetFrozen(bool frozen, bool ghostIgnoreIfCaught = false, bool ghostKeepAnimating = false)
{ {
// Debug.Log($"{gameObject} Set Frozen: {frozen}"); // Debug.Log($"{gameObject} Set Frozen: {frozen}");
@@ -389,6 +409,12 @@ namespace Marro.PacManUdon
return; return;
} }
data.Append(gameState == PacManGameState.InGame, ref index);
data.AppendAsByte(level, ref index);
data.Append(score, ref index);
data.AppendAsByte(extraLives, ref index);
data.Append(currentlyInTimeSequence, ref index); data.Append(currentlyInTimeSequence, ref index);
if (currentlyInTimeSequence) if (currentlyInTimeSequence)
@@ -397,10 +423,6 @@ namespace Marro.PacManUdon
data.Append(timeSequenceSecondsPassed, ref index); data.Append(timeSequenceSecondsPassed, ref index);
} }
data.AppendAsByte(level, ref index);
data.Append(score, ref index);
data.AppendAsByte(extraLives, ref index);
bonusFruit.CollectSyncedData(data, ref index, eventType); bonusFruit.CollectSyncedData(data, ref index, eventType);
collisionManager.CollectSyncedData(data, ref index, eventType); collisionManager.CollectSyncedData(data, ref index, eventType);
@@ -408,6 +430,8 @@ namespace Marro.PacManUdon
ghostManager.CollectSyncedData(data, ref index, eventType); ghostManager.CollectSyncedData(data, ref index, eventType);
pacMan.CollectSyncedData(data, ref index, eventType); pacMan.CollectSyncedData(data, ref index, eventType);
soundManager.CollectSyncedData(data, ref index, eventType);
} }
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType) public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
@@ -423,22 +447,31 @@ namespace Marro.PacManUdon
return true; return true;
} }
var currentlyInTimeSequence = data.ReadBool(ref index); // If we're currently in-game, we'll need to make sure the state is setup correctly
if (currentlyInTimeSequence) var remoteCurrentlyInGame = data.ReadBool(ref index);
if (remoteCurrentlyInGame)
{ {
var currentTimeSequence = (PacManTimeSequence)data.ReadByte(ref index); currentlyInTimeSequence = false; // Kill the current time sequence, otherwise it might interfere
var timeSequenceSecondsPassed = data.ReadFloat(ref index); // No need to run it to completion since we're overriding all state
TimeSequenceSyncWithRemote(currentTimeSequence, timeSequenceSecondsPassed); SetupInGameState();
}
else
{
TimeSequenceTryEndCurrent();
} }
SetLevel(data.ReadByte(ref index)); SetLevel(data.ReadByte(ref index));
SetScore(data.ReadInt(ref index)); SetScore(data.ReadInt(ref index));
SetExtraLives(data.ReadByte(ref index)); SetExtraLives(data.ReadByte(ref index));
// Sync up with the remote's time sequence
var remoteCurrentlyInTimeSequence = data.ReadBool(ref index);
if (remoteCurrentlyInTimeSequence)
{
var currentTimeSequence = (PacManTimeSequence)data.ReadByte(ref index);
var timeSequenceSecondsPassed = data.ReadFloat(ref index);
TimeSequenceSyncWithRemote(currentTimeSequence, timeSequenceSecondsPassed);
}
// Note that we don't have any logic for if the remote is not in-game and not in a time sequence.
// Such a state should be impossible.
bonusFruit.WriteSyncedData(data, ref index, eventType); bonusFruit.WriteSyncedData(data, ref index, eventType);
collisionManager.WriteSyncedData(data, ref index, eventType); collisionManager.WriteSyncedData(data, ref index, eventType);
@@ -447,6 +480,8 @@ namespace Marro.PacManUdon
pacMan.WriteSyncedData(data, ref index, eventType); pacMan.WriteSyncedData(data, ref index, eventType);
soundManager.WriteSyncedData(data, ref index, eventType);
return true; return true;
} }

View File

@@ -15,6 +15,15 @@ namespace Marro.PacManUdon
Special, Special,
} }
enum PacManGhostAnimatorState
{
Normal,
Caught,
Scared,
ScaredWhite,
Special
}
public enum PacManGhostState public enum PacManGhostState
{ {
Normal, Normal,
@@ -68,6 +77,7 @@ namespace Marro.PacManUdon
// State // State
private PacManGhostState ghostState; private PacManGhostState ghostState;
private bool isScared; private bool isScared;
private bool whiteScared;
private bool scattering; private bool scattering;
private PacManGhostFrozenState frozenState; private PacManGhostFrozenState frozenState;
@@ -540,21 +550,20 @@ namespace Marro.PacManUdon
SetAnimatorDirection((int)targetDirection); SetAnimatorDirection((int)targetDirection);
} }
if (isScared) // Don't update ghost type while scared as this interrupts the white/blue blinking
{
return;
}
PacManGhostType ghostType = this.ghostType; PacManGhostType ghostType = this.ghostType;
if (specialLook) if (isScared)
{ {
ghostType = PacManGhostType.Special; ghostType = whiteScared ? PacManGhostType.ScaredWhite : PacManGhostType.Scared;
} }
else if (ghostState == PacManGhostState.Returning || ghostState == PacManGhostState.Entering) else if (ghostState == PacManGhostState.Returning || ghostState == PacManGhostState.Entering)
{ {
ghostType = PacManGhostType.Caught; ghostType = PacManGhostType.Caught;
} }
else if (specialLook)
{
ghostType = PacManGhostType.Special;
}
SetAnimatorGhostType((int)ghostType); SetAnimatorGhostType((int)ghostType);
} }
@@ -671,13 +680,8 @@ namespace Marro.PacManUdon
private void SetScared(bool scared) private void SetScared(bool scared)
{ {
isScared = scared; isScared = scared;
UpdateAnimator(); SetWhite(false);
UpdateSpeed(); UpdateSpeed();
if (isScared)
{
SetWhite(false);
}
} }
public void SetScattering(bool scattering, bool reverseDirection = true) public void SetScattering(bool scattering, bool reverseDirection = true)
@@ -738,10 +742,8 @@ namespace Marro.PacManUdon
public void SetWhite(bool white) public void SetWhite(bool white)
{ {
if (!isScared || !gameObject.activeInHierarchy) whiteScared = white;
return; UpdateAnimator();
SetAnimatorGhostType(white ? (int)PacManGhostType.ScaredWhite : (int)PacManGhostType.Scared);
} }
public void SetElroy(int elroyLevel) public void SetElroy(int elroyLevel)
@@ -820,6 +822,7 @@ namespace Marro.PacManUdon
data.AppendAsByte((int)ghostState, ref index); data.AppendAsByte((int)ghostState, ref index);
data.Append(isScared, ref index); data.Append(isScared, ref index);
data.Append(whiteScared, ref index);
data.Append(scattering, ref index); data.Append(scattering, ref index);
data.AppendAsByte((int)frozenState, ref index); data.AppendAsByte((int)frozenState, ref index);
@@ -847,6 +850,7 @@ namespace Marro.PacManUdon
ghostState = (PacManGhostState)data.ReadByte(ref index); ghostState = (PacManGhostState)data.ReadByte(ref index);
isScared = data.ReadBool(ref index); isScared = data.ReadBool(ref index);
whiteScared = data.ReadBool(ref index);
scattering = data.ReadBool(ref index); scattering = data.ReadBool(ref index);
frozenState = (PacManGhostFrozenState)data.ReadByte(ref index); frozenState = (PacManGhostFrozenState)data.ReadByte(ref index);
@@ -855,6 +859,8 @@ namespace Marro.PacManUdon
housePelletCounterActive = data.ReadBool(ref index); housePelletCounterActive = data.ReadBool(ref index);
housePelletCounterLimit = data.ReadByte(ref index); housePelletCounterLimit = data.ReadByte(ref index);
UpdateSpeed();
return base.WriteSyncedData(data, ref index, eventType); return base.WriteSyncedData(data, ref index, eventType);
} }
} }

View File

@@ -39,6 +39,34 @@
SubscribeToEvent(NetworkEventType.PacManTurn); SubscribeToEvent(NetworkEventType.PacManTurn);
} }
void Update()
{
if (active)
{
if (Input.GetKeyDown(KeyCode.R))
{
gameManager.ResetButtonPressed();
}
if (Input.GetKeyDown(KeyCode.G))
{
gameManager.networkManager.DoFullSync();
}
if (Input.GetKeyDown(KeyCode.C))
{
gameManager.JumpToTimeSequenceBoardClear();
}
}
else
{
if (Input.GetKeyDown(KeyCode.T))
{
gameManager.ResetButtonPressed();
}
}
}
public void Activate() public void Activate()
{ {
Debug.Log($"{gameObject} got activated, {player} was immobilized"); Debug.Log($"{gameObject} got activated, {player} was immobilized");

View File

@@ -12,6 +12,7 @@ namespace Marro.PacManUdon
// Reset, show maze and score display // Reset, show maze and score display
SetMazeVisible(true); SetMazeVisible(true);
statusDisplay.SetScoreDisplayVisible(true); statusDisplay.SetScoreDisplayVisible(true);
statusDisplay.SetLabel1UPTextBlinking(true);
break; break;
case 1: case 1:
// Increment level, show ready, show pellets, show lives indicators // Increment level, show ready, show pellets, show lives indicators

View File

@@ -43,7 +43,6 @@ namespace Marro.PacManUdon
jumpingToTimeSequence = true; jumpingToTimeSequence = true;
TimeSequenceProgressToTime(100000f); TimeSequenceProgressToTime(100000f);
if (waitingForTimeSequenceFinalize) if (waitingForTimeSequenceFinalize)
{ {
TimeSequenceExecuteFinalize(currentTimeSequence); TimeSequenceExecuteFinalize(currentTimeSequence);
@@ -102,22 +101,23 @@ namespace Marro.PacManUdon
} }
} }
private void TimeSequenceSyncWithRemote(PacManTimeSequence currentTimeSequence, float timeSequenceSecondsPassed) private void TimeSequenceSyncWithRemote(PacManTimeSequence remoteCurrentTimeSequence, float timeSequenceSecondsPassedRemote)
{ {
// If the remote is in a time sequence but we're not, or we're in a different time sequence, or if we're behind, // If our current time sequence state is incompatible with the remote time sequence, kill it
// jump to the remote's time sequence. if (currentlyInTimeSequence && remoteCurrentTimeSequence != currentTimeSequence
if (!currentlyInTimeSequence || timeSequenceSecondsPassedRemote < timeSequenceSecondsPassed)
|| currentTimeSequence != this.currentTimeSequence
|| timeSequenceSecondsPassed < this.timeSequenceSecondsPassed)
{ {
StartTimeSequence(currentTimeSequence); currentlyInTimeSequence = false;
} }
// If we're (now) in a time sequence, jump our progress to match the one on the remote // If we're not/no longer in a time sequence, start the remote's time sequence
if (currentlyInTimeSequence) if (!currentlyInTimeSequence)
{ {
TimeSequenceProgressToTime(timeSequenceSecondsPassed); StartTimeSequence(remoteCurrentTimeSequence);
} }
// Jump our progress to match the one on the remote
TimeSequenceProgressToTime(timeSequenceSecondsPassedRemote);
} }
#region Events #region Events

View File

@@ -1147,19 +1147,25 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: _nextDotSound Data: alternatePelletSound
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 65|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 65|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: _nextDotSound Data: alternatePelletSound
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 7
Data: 17 Data: 66|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Boolean, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 17 Data: 66
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1174,7 +1180,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 66|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 67|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -1195,25 +1201,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: _ghostRetreating Data: ghostRetreating
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 67|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 68|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: _ghostRetreating Data: ghostRetreating
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 9
Data: 68|System.RuntimeType, mscorlib Data: 66
- Name:
Entry: 1
Data: System.Boolean, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 68 Data: 66
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1249,19 +1249,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: _ghostBlue Data: ghostBlue
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 70|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 70|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: _ghostBlue Data: ghostBlue
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 68 Data: 66
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 68 Data: 66
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1297,13 +1297,13 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: _ghostSoundLevel Data: ghostSoundLevel
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 72|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 72|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: _ghostSoundLevel Data: ghostSoundLevel
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 73|System.RuntimeType, mscorlib Data: 73|System.RuntimeType, mscorlib
@@ -1351,19 +1351,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: _currentlyPlayingSiren Data: currentlyPlayingSiren
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 75|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 75|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: _currentlyPlayingSiren Data: currentlyPlayingSiren
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 68 Data: 66
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 68 Data: 66
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1399,19 +1399,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: _suppress Data: suppress
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 77|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 77|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: _suppress Data: suppress
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 68 Data: 66
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 68 Data: 66
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib

View File

@@ -1,4 +1,5 @@
using JetBrains.Annotations;
using Marro.PacManUdon; using Marro.PacManUdon;
using UnityEngine; using UnityEngine;
@@ -27,13 +28,13 @@ public class SoundManager : SyncedObject
[SerializeField] private AudioClip siren3; [SerializeField] private AudioClip siren3;
[SerializeField] private AudioClip siren4; [SerializeField] private AudioClip siren4;
private AudioClip _nextDotSound; private bool alternatePelletSound;
private bool _ghostRetreating; private bool ghostRetreating;
private bool _ghostBlue; private bool ghostBlue;
private int _ghostSoundLevel; private int ghostSoundLevel;
private bool _currentlyPlayingSiren; private bool currentlyPlayingSiren;
private bool _suppress; private bool suppress;
public void Initialize() public void Initialize()
{ {
@@ -44,19 +45,19 @@ public class SoundManager : SyncedObject
{ {
StopAllSound(); StopAllSound();
_nextDotSound = pacDot2; alternatePelletSound = false;
_ghostRetreating = false; ghostRetreating = false;
_ghostBlue = false; ghostBlue = false;
_ghostSoundLevel = 0; ghostSoundLevel = 0;
_currentlyPlayingSiren = false; currentlyPlayingSiren = false;
_suppress = true; suppress = true;
} }
public void SuppressSound(bool suppress) public void SuppressSound(bool suppress)
{ {
_suppress = suppress; this.suppress = suppress;
if (suppress) if (suppress)
{ {
@@ -76,8 +77,8 @@ public class SoundManager : SyncedObject
public void PlayPelletSound() public void PlayPelletSound()
{ {
PlaySound(audioSourcePacMan, _nextDotSound); PlaySound(audioSourcePacMan, alternatePelletSound ? pacDot2 : pacDot1);
_nextDotSound = _nextDotSound == pacDot1 ? pacDot2 : pacDot1; alternatePelletSound = !alternatePelletSound;
} }
public void PlayDeathSound() public void PlayDeathSound()
@@ -112,13 +113,13 @@ public class SoundManager : SyncedObject
public void SetGhostBlue(bool isBlue) public void SetGhostBlue(bool isBlue)
{ {
_ghostBlue = isBlue; ghostBlue = isBlue;
UpdateGhostSound(); UpdateGhostSound();
} }
public void SetGhostRetreat(bool isRetreating) public void SetGhostRetreat(bool isRetreating)
{ {
_ghostRetreating = isRetreating; ghostRetreating = isRetreating;
UpdateGhostSound(); UpdateGhostSound();
} }
@@ -151,19 +152,19 @@ public class SoundManager : SyncedObject
// Debug.Log($"UpdatePelletCount: {pelletCount}, level: {level}"); // Debug.Log($"UpdatePelletCount: {pelletCount}, level: {level}");
if (_ghostSoundLevel >= level) if (ghostSoundLevel >= level)
{ {
return; return;
} }
_ghostSoundLevel = level; ghostSoundLevel = level;
UpdateGhostSound(); UpdateGhostSound();
} }
private void PlaySound(AudioSource audioSource, AudioClip audioClip, bool loop = false) private void PlaySound(AudioSource audioSource, AudioClip audioClip, bool loop = false)
{ {
// Debug.Log($"PlaySound, audioSource: {audioSource}, audioClip: {audioClip}, loop: {loop}, suppress: {_suppress}"); // Debug.Log($"PlaySound, audioSource: {audioSource}, audioClip: {audioClip}, loop: {loop}, suppress: {_suppress}");
if (_suppress) if (suppress)
{ {
return; return;
} }
@@ -181,7 +182,7 @@ public class SoundManager : SyncedObject
private void SwitchSound(AudioSource audioSource, AudioClip audioClip, bool loop) private void SwitchSound(AudioSource audioSource, AudioClip audioClip, bool loop)
{ {
if (_suppress) if (suppress)
{ {
return; return;
} }
@@ -207,22 +208,22 @@ public class SoundManager : SyncedObject
private void UpdateGhostSound() private void UpdateGhostSound()
{ {
if (_ghostRetreating) if (ghostRetreating)
{ {
PlaySound(audioSourceGhosts, pacGhostRetreat, true); PlaySound(audioSourceGhosts, pacGhostRetreat, true);
_currentlyPlayingSiren = false; currentlyPlayingSiren = false;
return; return;
} }
if (_ghostBlue) if (ghostBlue)
{ {
PlaySound(audioSourceGhosts, pacGhostBlue, true); PlaySound(audioSourceGhosts, pacGhostBlue, true);
_currentlyPlayingSiren = false; currentlyPlayingSiren = false;
return; return;
} }
var currentGhostLevelSound = GetSoundForGhostLevel(_ghostSoundLevel); var currentGhostLevelSound = GetSoundForGhostLevel(ghostSoundLevel);
if (_currentlyPlayingSiren) if (currentlyPlayingSiren)
{ {
SwitchSound(audioSourceGhosts, currentGhostLevelSound, true); SwitchSound(audioSourceGhosts, currentGhostLevelSound, true);
} }
@@ -231,7 +232,7 @@ public class SoundManager : SyncedObject
PlaySound(audioSourceGhosts, currentGhostLevelSound, true); PlaySound(audioSourceGhosts, currentGhostLevelSound, true);
} }
_currentlyPlayingSiren = true; currentlyPlayingSiren = true;
} }
private AudioClip GetSoundForGhostLevel(int ghostLevel) private AudioClip GetSoundForGhostLevel(int ghostLevel)
@@ -253,11 +254,23 @@ public class SoundManager : SyncedObject
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType) public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{ {
data.Append(alternatePelletSound, ref index);
data.Append(ghostRetreating, ref index);
data.Append(ghostBlue, ref index);
data.AppendAsByte(ghostSoundLevel, ref index);
data.Append(currentlyPlayingSiren, ref index);
} }
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType) public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{ {
alternatePelletSound = data.ReadBool(ref index);
ghostRetreating = data.ReadBool(ref index);
ghostBlue = data.ReadBool(ref index);
ghostSoundLevel = data.ReadByte(ref index);
currentlyPlayingSiren = data.ReadBool(ref index);
UpdateGhostSound();
return true; return true;
} }
} }