Pellet sync

This commit is contained in:
2026-01-18 17:47:07 +01:00
parent eef7084e21
commit c3a19cc53e
12 changed files with 1933 additions and 747 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,7 @@ namespace Marro.PacManUdon
{ {
public static void Append(this byte[] target, byte[] value, ref int index) public static void Append(this byte[] target, byte[] value, ref int index)
{ {
Debug.Log($"ByteUtils Append {nameof(value)}.Length: {value.Length}, {nameof(target)}.Length : {target.Length}, {nameof(index)}: {index}"); //Debug.Log($"ByteUtils Append {nameof(value)}.Length: {value.Length}, {nameof(target)}.Length : {target.Length}, {nameof(index)}: {index}");
Array.Copy(value, 0, target, index, value.Length); Array.Copy(value, 0, target, index, value.Length);
index += value.Length; index += value.Length;
} }

View File

@@ -43,7 +43,7 @@ MonoBehaviour:
Data: Data:
- Name: - Name:
Entry: 12 Entry: 12
Data: 37 Data: 34
- Name: - Name:
Entry: 7 Entry: 7
Data: Data:
@@ -1423,79 +1423,16 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: pelletCountOverride Data: maze
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 86|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 86|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletCountOverride
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 87|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 88|UnityEngine.TooltipAttribute, UnityEngine.CoreModule
- Name: tooltip
Entry: 1
Data: Override amount of pellets needed to clear stage, set to -1 to disable.
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 89|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: maze
- Name: $v
Entry: 7
Data: 90|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: maze Data: maze
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 91|System.RuntimeType, mscorlib Data: 87|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: Marro.PacManUdon.Maze, Assembly-CSharp Data: Marro.PacManUdon.Maze, Assembly-CSharp
@@ -1519,7 +1456,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 92|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 88|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -1543,13 +1480,13 @@ MonoBehaviour:
Data: intermission2Pole Data: intermission2Pole
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 93|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 89|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: intermission2Pole Data: intermission2Pole
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 94|System.RuntimeType, mscorlib Data: 90|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: Marro.PacManUdon.Intermission2Pole, Assembly-CSharp Data: Marro.PacManUdon.Intermission2Pole, Assembly-CSharp
@@ -1573,7 +1510,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 95|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 91|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -1597,7 +1534,7 @@ MonoBehaviour:
Data: mazeSpriteAnimator Data: mazeSpriteAnimator
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 96|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 92|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: mazeSpriteAnimator Data: mazeSpriteAnimator
@@ -1621,7 +1558,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 97|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 93|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -1642,19 +1579,25 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: pelletCountTotal Data: attractScreenElements
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 98|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 94|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: pelletCountTotal Data: attractScreenElements
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 7
Data: 15 Data: 95|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.GameObject[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 95
- 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
@@ -1669,7 +1612,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 99|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 96|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -1690,16 +1633,70 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: pelletCountRemaining Data: intermissionScreenElements
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 100|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 97|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: pelletCountRemaining Data: intermissionScreenElements
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 95
- Name: <SystemType>k__BackingField
Entry: 9
Data: 95
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 98|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: gameState
- Name: $v
Entry: 7
Data: 99|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: gameState
- Name: <UserType>k__BackingField
Entry: 7
Data: 100|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.PacManGameState, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 15
@@ -1739,126 +1736,16 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: attractScreenElements Data: score
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 102|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 102|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: attractScreenElements Data: score
- Name: <UserType>k__BackingField
Entry: 7
Data: 103|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.GameObject[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 103
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 104|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: intermissionScreenElements
- Name: $v
Entry: 7
Data: 105|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: intermissionScreenElements
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 103 Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 103
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 106|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: gameState
- Name: $v
Entry: 7
Data: 107|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: gameState
- Name: <UserType>k__BackingField
Entry: 7
Data: 108|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.PacManGameState, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 15
@@ -1866,8 +1753,8 @@ MonoBehaviour:
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name: - Name:
Entry: 6 Entry: 3
Data: Data: 1
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
@@ -1876,11 +1763,23 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 109|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], Data: 103|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 2
- Name:
Entry: 7
Data: 104|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 105|UdonSharp.FieldChangeCallbackAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name: - Name:
Entry: 13 Entry: 13
Data: Data:
@@ -1898,13 +1797,74 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: score Data: level
- Name: $v
Entry: 7
Data: 106|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: level
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 3
Data: 1
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 107|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 108|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 109|UdonSharp.FieldChangeCallbackAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: highScore
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 110|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 110|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: score Data: highScore
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 15
@@ -1959,13 +1919,13 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: level Data: extraLives
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 114|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 114|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: level Data: extraLives
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 15
@@ -2015,128 +1975,6 @@ MonoBehaviour:
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: highScore
- Name: $v
Entry: 7
Data: 118|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: highScore
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 3
Data: 1
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 119|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 120|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 121|UdonSharp.FieldChangeCallbackAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: extraLives
- Name: $v
Entry: 7
Data: 122|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: extraLives
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 3
Data: 1
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 123|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 124|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 125|UdonSharp.FieldChangeCallbackAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name: - Name:
Entry: 13 Entry: 13
Data: Data:

View File

@@ -26,15 +26,11 @@ namespace Marro.PacManUdon
[Header("Game settings")] [Header("Game settings")]
[SerializeField] private int startingExtraLives = 3; [SerializeField] private int startingExtraLives = 3;
[SerializeField] private int scoreToExtraLife = 10000; [SerializeField] private int scoreToExtraLife = 10000;
[Tooltip("Override amount of pellets needed to clear stage, set to -1 to disable.")]
[SerializeField] private int pelletCountOverride = -1;
private Maze maze; private Maze maze;
private Intermission2Pole intermission2Pole; private Intermission2Pole intermission2Pole;
private Animator mazeSpriteAnimator; private Animator mazeSpriteAnimator;
private int pelletCountTotal;
private int pelletCountRemaining;
private GameObject[] attractScreenElements; private GameObject[] attractScreenElements;
private GameObject[] intermissionScreenElements; private GameObject[] intermissionScreenElements;
@@ -63,7 +59,7 @@ namespace Marro.PacManUdon
intermission2Pole = intermissionScreenElements[4].GetComponent<Intermission2Pole>(); intermission2Pole = intermissionScreenElements[4].GetComponent<Intermission2Pole>();
networkManager.Initialize(); networkManager.Initialize();
ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, this); ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, pelletManager, this);
pacMan.Initialize(playerInput, maze.pacManStart, this); pacMan.Initialize(playerInput, maze.pacManStart, this);
bonusFruit.Initialize(); bonusFruit.Initialize();
pelletManager.Initialize(); pelletManager.Initialize();
@@ -138,27 +134,20 @@ namespace Marro.PacManUdon
{ {
Debug.Log($"{gameObject} New level started!"); Debug.Log($"{gameObject} New level started!");
pelletCountTotal = pelletManager.PelletCount;
pelletCountRemaining = pelletCountTotal;
ghostManager.SetPelletsRemaining(pelletCountRemaining);
ghostManager.NewLevel();
pelletManager.RestoreAllPellets(); pelletManager.RestoreAllPellets();
if (pelletCountOverride > 0) ghostManager.NewLevel();
{
pelletCountRemaining = pelletCountOverride;
}
mazeSpriteAnimator.SetBool("Blinking", false); mazeSpriteAnimator.SetBool("Blinking", false);
} }
private void RestartLevel() private void RestartLevel(bool afterLifeLost = false)
{ {
Debug.Log($"{gameObject} (Re)started level!"); Debug.Log($"{gameObject} (Re)started level!");
// SetInGameComponentVisibility(true); // SetInGameComponentVisibility(true);
ghostManager.Reset(); ghostManager.Reset(afterLifeLost);
pacMan.Reset(); pacMan.Reset();
bonusFruit.Despawn(); bonusFruit.Despawn();
soundManager.Reset(); soundManager.Reset();
@@ -172,29 +161,31 @@ namespace Marro.PacManUdon
SetFrozen(true); SetFrozen(true);
} }
public void GotPellet(bool addScore = true) public void GotPellet(Pellet pellet, bool addScore = true)
{ {
pelletCountRemaining--; var pelletCollectedCount = pelletManager.PelletCollected(pellet);
if (addScore) AddScore(10); if (addScore) AddScore(10);
ghostManager.PelletConsumed(); ghostManager.PelletConsumed();
soundManager.PlayPelletSound(); soundManager.PlayPelletSound();
var pelletCountRemaining = pelletManager.PelletCount - pelletCollectedCount;
soundManager.UpdatePelletCount(pelletCountRemaining); soundManager.UpdatePelletCount(pelletCountRemaining);
int pelletsConsumed = pelletCountTotal - pelletCountRemaining;
if (pelletCountRemaining <= 0) if (pelletCountRemaining <= 0)
{ {
StartTimeSequence(PacManTimeSequence.BoardClear); StartTimeSequence(PacManTimeSequence.BoardClear);
} }
else if (pelletsConsumed == 70 || pelletsConsumed == 170) else if (pelletCollectedCount == 70 || pelletCollectedCount == 170)
{ {
bonusFruit.Spawn(); bonusFruit.Spawn();
} }
} }
public void GotPowerPellet() public void GotPowerPellet(Pellet pellet)
{ {
Debug.Log($"{gameObject} GotPowerPellet"); Debug.Log($"{gameObject} GotPowerPellet");
@@ -203,7 +194,7 @@ namespace Marro.PacManUdon
TimeSequenceSkipToNextStep(); TimeSequenceSkipToNextStep();
return; return;
} }
GotPellet(addScore: false); GotPellet(pellet, addScore: false);
AddScore(50); AddScore(50);
ghostManager.SetPowerPellet(true); ghostManager.SetPowerPellet(true);
pacMan.SetPowerPellet(true); pacMan.SetPowerPellet(true);

View File

@@ -32,6 +32,8 @@ namespace Marro.PacManUdon
TargetingIdlePosition2 TargetingIdlePosition2
} }
[RequireComponent(typeof(Renderer))]
[RequireComponent(typeof(Animator))]
public class Ghost : GridMover public class Ghost : GridMover
{ {
[SerializeField] private PacManGhostType ghostType; [SerializeField] private PacManGhostType ghostType;
@@ -73,7 +75,6 @@ namespace Marro.PacManUdon
private bool isScared; private bool isScared;
private bool scattering; private bool scattering;
private PacManGhostFrozenState frozenState; private PacManGhostFrozenState frozenState;
private bool hideUntilUnfrozen;
private int housePelletCounter; private int housePelletCounter;
private bool housePelletCounterActive; private bool housePelletCounterActive;
private bool turnAroundSoon; private bool turnAroundSoon;
@@ -137,12 +138,8 @@ namespace Marro.PacManUdon
public override void SyncedUpdate() public override void SyncedUpdate()
{ {
if (ghostType == PacManGhostType.Blinky)
{
// ghostManager.gameStateManager.statusDisplay.SetDebugText(2, $"{turnAroundSoon}");
}
if (frozenState == PacManGhostFrozenState.Frozen || if (frozenState == PacManGhostFrozenState.Frozen ||
(frozenState == PacManGhostFrozenState.FrozenIfNotCaught && ((ghostState != PacManGhostState.Returning && ghostState != PacManGhostState.Entering) || hideUntilUnfrozen))) (frozenState == PacManGhostFrozenState.FrozenIfNotCaught && ghostState != PacManGhostState.Returning && ghostState != PacManGhostState.Entering))
{ {
return; return;
} }
@@ -642,7 +639,7 @@ namespace Marro.PacManUdon
if (reverseDirection && this.scattering != scattering) if (reverseDirection && this.scattering != scattering)
{ {
if (ghostState == PacManGhostState.Normal || ghostState == PacManGhostState.Home || ghostState == PacManGhostState.Exiting if (ghostState == PacManGhostState.Normal || ghostState == PacManGhostState.Home || ghostState == PacManGhostState.Exiting
// This is afaik not normal PacMan behaviour, but is needed to accomidate slight timing differences // This is afaik not normal PacMan behaviour, but is needed to accomidate slight timing differences during the demo
|| ghostState == PacManGhostState.Entering && ghostManager.gameController.GameState == PacManGameState.AttractModeDemo || ghostState == PacManGhostState.Entering && ghostManager.gameController.GameState == PacManGameState.AttractModeDemo
) )
{ {

File diff suppressed because it is too large Load Diff

View File

@@ -7,9 +7,12 @@ namespace Marro.PacManUdon
public class GhostManager : SyncedObject public class GhostManager : SyncedObject
{ {
[NonSerialized] public GameManager gameController; [NonSerialized] public GameManager gameController;
private Ghost[] ghosts; private Ghost[] ghosts;
private Ghost blinky; private Ghost blinky;
private PelletManager pelletManager;
// Level constants // Level constants
private float speedDefault; private float speedDefault;
private float speedScared; private float speedScared;
@@ -42,7 +45,6 @@ namespace Marro.PacManUdon
// Elroy logic // Elroy logic
public int elroyLevel; public int elroyLevel;
private int pelletsRemaining;
// Ghost house logic // Ghost house logic
private bool sharedPelletCounterActive; private bool sharedPelletCounterActive;
@@ -55,9 +57,11 @@ namespace Marro.PacManUdon
private bool kinematic; private bool kinematic;
// This should be called once when the game is initialized // This should be called once when the game is initialized
public void Initialize(Transform[] ghostStarts, Transform[] ghostTargets, PacMan pacMan, GameManager gameController) public void Initialize(Transform[] ghostStarts, Transform[] ghostTargets, PacMan pacMan, PelletManager pelletManager, GameManager gameController)
{ {
this.gameController = gameController; this.gameController = gameController;
this.pelletManager = pelletManager;
ghosts = transform.GetComponentsInChildren<Ghost>(true); ghosts = transform.GetComponentsInChildren<Ghost>(true);
blinky = ghosts[0]; blinky = ghosts[0];
for (int ghostIndex = 0; ghostIndex < ghosts.Length; ghostIndex++) for (int ghostIndex = 0; ghostIndex < ghosts.Length; ghostIndex++)
@@ -73,7 +77,7 @@ namespace Marro.PacManUdon
} }
// This should be called every time the level is reset // This should be called every time the level is reset
public void Reset() public void Reset(bool afterLifeLost = false)
{ {
ghostScaredQueue = new DataList(); ghostScaredQueue = new DataList();
powerPelletActive = false; powerPelletActive = false;
@@ -84,6 +88,11 @@ namespace Marro.PacManUdon
elroyLevel = 0; elroyLevel = 0;
kinematic = false; kinematic = false;
if (afterLifeLost)
{
SetSharedPelletCounterActive(true);
}
foreach (Ghost ghost in ghosts) foreach (Ghost ghost in ghosts)
{ {
ghost.Reset(); ghost.Reset();
@@ -95,20 +104,15 @@ namespace Marro.PacManUdon
public void NewLevel() public void NewLevel()
{ {
SetSharedPelletCounterActive(false); SetSharedPelletCounterActive(false);
UpdateElroyLevel();
foreach (Ghost ghost in ghosts) foreach (Ghost ghost in ghosts)
{ {
ghost.ResetHousePelletCounter(); ghost.ResetHousePelletCounter();
} }
} }
public void RestartAfterLifeLost()
{
SetSharedPelletCounterActive(true);
}
public override void SyncedUpdate() public override void SyncedUpdate()
{ {
// gameStateManager.statusDisplay.SetDebugText(1, this.blinkCountdown.ToString());
if (frozen || kinematic) if (frozen || kinematic)
{ {
return; return;
@@ -368,7 +372,7 @@ namespace Marro.PacManUdon
Debug.Log($"{gameObject} SetScattering: {scattering}"); Debug.Log($"{gameObject} SetScattering: {scattering}");
foreach (Ghost ghost in ghosts) foreach (Ghost ghost in ghosts)
{ {
if (ghost == blinky && pelletsRemaining <= elroy1PelletCount) if (ghost == blinky && elroyLevel > 0) // Once blinky is elroy he no longer scatters
{ {
continue; continue;
} }
@@ -376,15 +380,13 @@ namespace Marro.PacManUdon
} }
} }
public void SetPelletsRemaining(int pelletsRemaining) /// <summary>
{ /// Whether to use the shared pellet counter for ghost exiting.
this.pelletsRemaining = pelletsRemaining; /// Should be called before ghosts are reset.
UpdateElroyLevel(); /// </summary>
}
void SetSharedPelletCounterActive(bool active) void SetSharedPelletCounterActive(bool active)
{ {
// Debug.Log($"{gameObject} SetSharedPelletCounterActive {active}"); Debug.Log($"{gameObject} SetSharedPelletCounterActive {active}");
sharedPelletCounterActive = active; sharedPelletCounterActive = active;
foreach (Ghost ghost in ghosts) foreach (Ghost ghost in ghosts)
{ {
@@ -394,10 +396,10 @@ namespace Marro.PacManUdon
public void PelletConsumed() public void PelletConsumed()
{ {
SetPelletsRemaining(pelletsRemaining - 1);
pelletTimeout = 0; pelletTimeout = 0;
UpdateElroyLevel();
if (sharedPelletCounterActive) if (sharedPelletCounterActive)
{ {
IncrementSharedPelletCounter(); IncrementSharedPelletCounter();
@@ -411,6 +413,7 @@ namespace Marro.PacManUdon
void IncrementSharedPelletCounter() void IncrementSharedPelletCounter()
{ {
sharedPelletCounter++; sharedPelletCounter++;
//Debug.Log($"Incremented shared pellet counter to {sharedPelletCounter}");
for (int ghostIndex = 0; ghostIndex < sharedPelletCounterReleaseValues.Length; ghostIndex++) for (int ghostIndex = 0; ghostIndex < sharedPelletCounterReleaseValues.Length; ghostIndex++)
{ {
Ghost ghost = ghosts[ghostIndex]; Ghost ghost = ghosts[ghostIndex];
@@ -442,10 +445,13 @@ namespace Marro.PacManUdon
void UpdateElroyLevel() void UpdateElroyLevel()
{ {
// Debug.Log($"{gameObject} Updating Elroy Level with pelletsRemaining {pelletsRemaining} with elroy2PelletCount {elroy2PelletCount} and elroy1PelletCount {elroy1PelletCount}"); // Debug.Log($"{gameObject} Updating Elroy Level with pelletsRemaining {pelletsRemaining} with elroy2PelletCount {elroy2PelletCount} and elroy1PelletCount {elroy1PelletCount}");
int oldElroyLevel = elroyLevel; var oldElroyLevel = elroyLevel;
var pelletsRemaining = pelletManager.PelletCount - pelletManager.PelletCollectedCount;
if (pelletsRemaining < elroy2PelletCount) elroyLevel = 2; if (pelletsRemaining < elroy2PelletCount) elroyLevel = 2;
else if (pelletsRemaining < elroy1PelletCount) elroyLevel = 1; else if (pelletsRemaining < elroy1PelletCount) elroyLevel = 1;
else elroyLevel = 0; else elroyLevel = 0;
if (elroyLevel != oldElroyLevel) if (elroyLevel != oldElroyLevel)
{ {
blinky.SetElroy(elroyLevel); blinky.SetElroy(elroyLevel);

View File

@@ -15,6 +15,7 @@ namespace Marro.PacManUdon
FullSync = 1, FullSync = 1,
PacManTurn = 2, PacManTurn = 2,
StartGameButtonPressed = 3, StartGameButtonPressed = 3,
SyncPellets = 4,
} }
public class NetworkManager : UdonSharpBehaviour public class NetworkManager : UdonSharpBehaviour
@@ -624,7 +625,6 @@ namespace Marro.PacManUdon
if (Synced) if (Synced)
{ {
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)} blaat");
UpdateNextEventTime(); UpdateNextEventTime();
} }
} }
@@ -657,7 +657,6 @@ namespace Marro.PacManUdon
} }
DequeueEventsFromBuffer(1); DequeueEventsFromBuffer(1);
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)} damn");
UpdateNextEventTime(); UpdateNextEventTime();
} }
} }
@@ -964,6 +963,11 @@ namespace Marro.PacManUdon
{ {
SendEventSoon(NetworkEventType.FullSync); SendEventSoon(NetworkEventType.FullSync);
} }
public void DoPelletSync()
{
SendEventSoon(NetworkEventType.SyncPellets);
}
#endregion #endregion
} }
} }

View File

@@ -316,16 +316,14 @@ namespace Marro.PacManUdon
Pellet pellet = other.gameObject.GetComponent<Pellet>(); Pellet pellet = other.gameObject.GetComponent<Pellet>();
if (pellet) if (pellet)
{ {
pellet.gameObject.SetActive(false);
if (pellet.isPowerPellet) if (pellet.isPowerPellet)
{ {
gameController.GotPowerPellet(); gameController.GotPowerPellet(pellet);
freezeSeconds = 0.05f; freezeSeconds = 0.05f;
} }
else else
{ {
gameController.GotPellet(); gameController.GotPellet(pellet);
freezeSeconds = 0.0166666666666667f; freezeSeconds = 0.0166666666666667f;
} }
return; return;

View File

@@ -43,7 +43,7 @@ MonoBehaviour:
Data: Data:
- Name: - Name:
Entry: 12 Entry: 12
Data: 8 Data: 9
- Name: - Name:
Entry: 7 Entry: 7
Data: Data:
@@ -109,31 +109,25 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: pellets Data: <PelletCollectedCount>k__BackingField
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 6|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 6|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: pellets Data: <PelletCollectedCount>k__BackingField
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 7|System.RuntimeType, mscorlib Data: 7|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: Marro.PacManUdon.Pellet[], Assembly-CSharp Data: System.Int32, mscorlib
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 7 Entry: 9
Data: 8|System.RuntimeType, mscorlib Data: 7
- Name:
Entry: 1
Data: UnityEngine.Component[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- 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
@@ -148,7 +142,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 9|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 8|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -169,25 +163,31 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: pelletRenderers Data: pellets
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 10|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 9|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: pelletRenderers Data: pellets
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 11|System.RuntimeType, mscorlib Data: 10|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: UnityEngine.Renderer[], UnityEngine.CoreModule Data: Marro.PacManUdon.Pellet[], Assembly-CSharp
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 7
Data: 11 Data: 11|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Component[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- 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
@@ -476,6 +476,60 @@ MonoBehaviour:
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: syncedPelletsCollected
- Name: $v
Entry: 7
Data: 26|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: syncedPelletsCollected
- Name: <UserType>k__BackingField
Entry: 7
Data: 27|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Byte[], mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 27
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 28|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name: - Name:
Entry: 13 Entry: 13
Data: Data:

View File

@@ -1,12 +1,14 @@
using UdonSharp; using System;
using UnityEngine; using UnityEngine;
namespace Marro.PacManUdon namespace Marro.PacManUdon
{ {
public class PelletManager : SyncedObject public class PelletManager : SyncedObject
{ {
public int PelletCount => pellets.Length;
public int PelletCollectedCount { get; private set; }
Pellet[] pellets; Pellet[] pellets;
Renderer[] pelletRenderers;
Animator[] powerPellets; Animator[] powerPellets;
bool powerPelletBlinkEnabled; bool powerPelletBlinkEnabled;
@@ -14,20 +16,18 @@ namespace Marro.PacManUdon
float powerPelletBlinkProgress; float powerPelletBlinkProgress;
bool powerPelletBlinkCurrentlyVisible; bool powerPelletBlinkCurrentlyVisible;
byte[] syncedPelletsCollected;
public void Initialize() public void Initialize()
{ {
gameObject.SetActive(true); gameObject.SetActive(true);
pellets = GetComponentsInChildren<Pellet>(includeInactive: true); pellets = GetComponentsInChildren<Pellet>(includeInactive: true);
pelletRenderers = new Renderer[pellets.Length];
for (int i = 0; i < pelletRenderers.Length; i++)
{
pelletRenderers[i] = pellets[i].GetComponent<Renderer>();
}
powerPellets = GetComponentsInChildren<Animator>(true); powerPellets = GetComponentsInChildren<Animator>(true);
powerPelletBlinkToggleInterval = PacManConstants.GetPowerPelletBlinkToggleInterval(); powerPelletBlinkToggleInterval = PacManConstants.GetPowerPelletBlinkToggleInterval();
SetPowerPelletsBlink(false); SetPowerPelletsBlink(false);
RestoreAllPellets();
} }
public override void SyncedUpdate() public override void SyncedUpdate()
@@ -71,29 +71,63 @@ namespace Marro.PacManUdon
powerPelletBlinkEnabled = !frozen; powerPelletBlinkEnabled = !frozen;
} }
public void RestoreAllPellets() public int PelletCollected(Pellet pellet)
{
pellet.gameObject.SetActive(false);
var index = pellet.transform.GetSiblingIndex();
syncedPelletsCollected[index/8] |= (byte)(1 << index%8);
PelletCollectedCount++;
return PelletCollectedCount;
}
public int RestoreAllPellets()
{ {
foreach (var pellet in pellets) foreach (var pellet in pellets)
{ {
pellet.gameObject.SetActive(true); pellet.gameObject.SetActive(true);
} }
foreach (Renderer pelletRenderer in pelletRenderers) syncedPelletsCollected = new byte[pellets.Length/8 + 1];
PelletCollectedCount = 0;
return PelletCount;
}
private void SetPelletsCollectedFromSync()
{
for (int i = 0; i < pellets.Length; i++)
{ {
pelletRenderer.enabled = true; var active = (syncedPelletsCollected[i/8] & (byte)(1 << i%8)) == 0;
pellets[i].gameObject.SetActive(active);
} }
} }
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType) public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{ {
if (eventType != NetworkEventType.SyncPellets)
{
return;
}
data.Append((byte)PelletCollectedCount, ref index);
data.Append(syncedPelletsCollected, ref index);
} }
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType) public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{ {
if (eventType != NetworkEventType.SyncPellets)
{
return true;
}
PelletCollectedCount = data.ReadByte(ref index);
Array.Copy(data, index, syncedPelletsCollected, 0, syncedPelletsCollected.Length);
index += syncedPelletsCollected.Length;
SetPelletsCollectedFromSync();
return true; return true;
} }
public int PelletCount => pellets.Length;
} }
} }

View File

@@ -13,8 +13,7 @@ namespace Marro.PacManUdon
break; break;
case 1: case 1:
// Make maze visible // Make maze visible
RestartLevel(); RestartLevel(afterLifeLost: true);
ghostManager.RestartAfterLifeLost();
SetMazeVisible(true); SetMazeVisible(true);
break; break;
case 2: case 2:
@@ -43,7 +42,7 @@ namespace Marro.PacManUdon
SetFrozen(false); SetFrozen(false);
soundManager.SuppressSound(false); soundManager.SuppressSound(false);
soundManager.StartGhostSound(); soundManager.StartGhostSound();
soundManager.UpdatePelletCount(pelletCountRemaining); soundManager.UpdatePelletCount(pelletManager.PelletCount - pelletManager.PelletCollectedCount);
} }
} }
} }