Renamed CollisionManager

This commit is contained in:
2026-06-18 11:03:56 +02:00
parent a7d1adf175
commit 64e445e8a6
21 changed files with 156 additions and 767 deletions

View File

@@ -10,7 +10,7 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: PelletManager
m_Name: CollisionManager
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: 9047ff9c4ab51104b8b0160387ad180b, type: 2}
udonAssembly:
@@ -20,7 +20,7 @@ MonoBehaviour:
compiledVersion: 2
behaviourSyncMode: 0
hasInteractEvent: 0
scriptID: 2205517818672966804
scriptID: 2892584015827264300
serializationData:
SerializedFormat: 2
SerializedBytes:

View File

@@ -10,7 +10,7 @@ namespace Marro.PacManUdon
PowerPellet
}
public class PelletManager : SyncedObject
public class CollisionManager : SyncedObject
{
public int PelletCount => pellets.Length;
public int PelletCollectedCount { get; private set; }
@@ -58,49 +58,6 @@ namespace Marro.PacManUdon
SubscribeToEvent(NetworkEventType.SyncPellets);
}
#region Power pellet blink
public override void SyncedUpdate()
{
if (!powerPelletBlinkEnabled)
{
return;
}
powerPelletBlinkProgress += networkManager.SyncedDeltaTime;
if (powerPelletBlinkProgress >= powerPelletBlinkToggleInterval)
{
// Debug.Log($"{gameObject} PowerPelletBlink toggle");
powerPelletBlinkProgress -= powerPelletBlinkToggleInterval;
powerPelletBlinkCurrentlyVisible = !powerPelletBlinkCurrentlyVisible;
SetPowerPelletsVisible(powerPelletBlinkCurrentlyVisible);
}
}
void SetPowerPelletsVisible(bool visible)
{
// Debug.Log($"{gameObject} SetPowerPelletVisible {visible}, powerPellets.Length: {powerPellets.Length}");
foreach (Animator powerPellet in powerPellets)
{
powerPellet.SetBool("Visible", visible);
}
}
public void SetPowerPelletsBlink(bool enabled)
{
// Debug.Log($"{gameObject} SetPowerPelletBlink {enabled}");
powerPelletBlinkEnabled = enabled;
powerPelletBlinkCurrentlyVisible = true;
powerPelletBlinkProgress = 0;
SetPowerPelletsVisible(true);
}
public void FreezePowerPelletsBlink(bool frozen)
{
powerPelletBlinkEnabled = !frozen;
}
#endregion
#region Collision
public bool IsWallUpcoming(Vector2 position, Vector2 directionVector)
{
@@ -135,7 +92,7 @@ namespace Marro.PacManUdon
TryEatGhost(tilemapIndex);
TryCollectFruit(tile, position, nextPosition);
TryCollectFruit(tile, position);
return TryCollectPellet(tile, tilemapIndex);
}
@@ -151,7 +108,7 @@ namespace Marro.PacManUdon
}
}
private void TryCollectFruit(int tile, Vector2 position, Vector2 nextPosition)
private void TryCollectFruit(int tile, Vector2 position)
{
if (tile != (int)PacManConsumableType.FruitLeft && tile != (int)PacManConsumableType.FruitRight
|| !bonusFruit.Active)
@@ -237,6 +194,50 @@ namespace Marro.PacManUdon
pellets[i].gameObject.SetActive(active);
}
}
#endregion
#region Power pellet blink
public override void SyncedUpdate()
{
if (!powerPelletBlinkEnabled)
{
return;
}
powerPelletBlinkProgress += networkManager.SyncedDeltaTime;
if (powerPelletBlinkProgress >= powerPelletBlinkToggleInterval)
{
// Debug.Log($"{gameObject} PowerPelletBlink toggle");
powerPelletBlinkProgress -= powerPelletBlinkToggleInterval;
powerPelletBlinkCurrentlyVisible = !powerPelletBlinkCurrentlyVisible;
SetPowerPelletsVisible(powerPelletBlinkCurrentlyVisible);
}
}
void SetPowerPelletsVisible(bool visible)
{
// Debug.Log($"{gameObject} SetPowerPelletVisible {visible}, powerPellets.Length: {powerPellets.Length}");
foreach (Animator powerPellet in powerPellets)
{
powerPellet.SetBool("Visible", visible);
}
}
public void SetPowerPelletsBlink(bool enabled)
{
// Debug.Log($"{gameObject} SetPowerPelletBlink {enabled}");
powerPelletBlinkEnabled = enabled;
powerPelletBlinkCurrentlyVisible = true;
powerPelletBlinkProgress = 0;
SetPowerPelletsVisible(true);
}
public void FreezePowerPelletsBlink(bool frozen)
{
powerPelletBlinkEnabled = !frozen;
}
#endregion
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
@@ -262,6 +263,5 @@ namespace Marro.PacManUdon
SetPelletsCollectedFromSync();
return true;
}
#endregion
}
}

View File

@@ -730,19 +730,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: pelletManager
Data: collisionManager
- Name: $v
Entry: 7
Data: 43|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletManager
Data: collisionManager
- Name: <UserType>k__BackingField
Entry: 7
Data: 44|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.PelletManager, Assembly-CSharp
Data: Marro.PacManUdon.CollisionManager, Assembly-CSharp
- Name:
Entry: 8
Data:

View File

@@ -10,9 +10,9 @@ namespace Marro.PacManUdon
[SerializeField] private PacMan pacMan;
[SerializeField] private GhostManager ghostManager;
[SerializeField] private BonusFruit bonusFruit;
[SerializeField] private PelletManager pelletManager;
[SerializeField] private CollisionManager collisionManager;
[SerializeField] private StatusDisplay statusDisplay;
[SerializeField] private PelletManager attractScreen;
[SerializeField] private CollisionManager attractScreen;
[SerializeField] private GameObject intermissionScreen;
[SerializeField] private GameObject pressStartButtonScreen;
[SerializeField] private PlayerInput playerInput;
@@ -58,10 +58,10 @@ namespace Marro.PacManUdon
intermission2Pole = intermissionScreenElements[4].GetComponent<Intermission2Pole>();
networkManager.Initialize();
ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, pelletManager, this);
pacMan.Initialize(playerInput, maze.pacManStart, this, pelletManager);
ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, collisionManager, this);
pacMan.Initialize(playerInput, maze.pacManStart, this, collisionManager);
bonusFruit.Initialize();
pelletManager.Initialize(this, bonusFruit, ghostManager.Ghosts);
collisionManager.Initialize(this, bonusFruit, ghostManager.Ghosts);
statusDisplay.Initialize();
playerInput.Initialize(this);
soundManager.Initialize();
@@ -136,7 +136,7 @@ namespace Marro.PacManUdon
{
//Debug.Log($"{gameObject} New level started!");
pelletManager.RestoreAllPellets();
collisionManager.RestoreAllPellets();
ghostManager.NewLevel();
@@ -153,7 +153,7 @@ namespace Marro.PacManUdon
pacMan.Reset();
bonusFruit.Despawn();
soundManager.Reset();
pelletManager.SetPowerPelletsBlink(false);
collisionManager.SetPowerPelletsBlink(false);
}
private void PrepareForCutscene()
@@ -280,7 +280,7 @@ namespace Marro.PacManUdon
void SetPelletsActive(bool active)
{
pelletManager.gameObject.SetActive(active);
collisionManager.gameObject.SetActive(active);
}
void SetMazeVisible(bool visible)
@@ -394,7 +394,7 @@ namespace Marro.PacManUdon
if (!frozen)
{
pelletManager.SetPowerPelletsBlink(true);
collisionManager.SetPowerPelletsBlink(true);
}
}

View File

@@ -397,19 +397,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: pelletManager
Data: collisionManager
- Name: $v
Entry: 7
Data: 24|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletManager
Data: collisionManager
- Name: <UserType>k__BackingField
Entry: 7
Data: 25|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.PelletManager, Assembly-CSharp
Data: Marro.PacManUdon.CollisionManager, Assembly-CSharp
- Name:
Entry: 8
Data:

View File

@@ -41,7 +41,7 @@ namespace Marro.PacManUdon
// External references
private GhostManager ghostManager;
private PelletManager pelletManager;
private CollisionManager collisionManager;
private Animator animator;
private new Renderer renderer;
private PacMan pacMan;
@@ -89,13 +89,13 @@ namespace Marro.PacManUdon
public bool IsScared => isScared;
public int Index { get; private set; }
public void Initialize(PelletManager pelletManager, PacMan pacMan, Ghost blinky, Transform startTransform, Vector2 homePosition, Vector2 idlePosition1, Vector2 idlePosition2, Vector2 cornerPosition, int index)
public void Initialize(CollisionManager collisionManager, PacMan pacMan, Ghost blinky, Transform startTransform, Vector2 homePosition, Vector2 idlePosition1, Vector2 idlePosition2, Vector2 cornerPosition, int index)
{
ghostManager = transform.parent.GetComponent<GhostManager>();
animator = GetComponent<Animator>();
renderer = GetComponent<Renderer>();
this.pelletManager = pelletManager;
this.collisionManager = collisionManager;
this.pacMan = pacMan;
this.blinky = blinky;
this.homePosition = homePosition;
@@ -199,7 +199,7 @@ namespace Marro.PacManUdon
if (CrossesTileBorder(position, nextPosition, direction))
{
var inTunnel = pelletManager.GhostMoveToTile(nextPosition, Index);
var inTunnel = collisionManager.GhostMoveToTile(nextPosition, Index);
if (inTunnel != this.inTunnel)
{
@@ -248,7 +248,7 @@ namespace Marro.PacManUdon
private void TryToTurn(Vector2 position, ref Vector2 nextPosition)
{
var gridPosition = PositionToGrid(position);
var availableDirections = pelletManager.GetAvailableDirections(position);
var availableDirections = collisionManager.GetAvailableDirections(position);
if ((availableDirections & (int)PacManCollisionInfoType.NoTurn) != 0 )
{
@@ -285,7 +285,7 @@ namespace Marro.PacManUdon
{
nextValidDirectionIndex += 1;
}
if (!pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)predefinedPath[nextValidDirectionIndex]]))
if (!collisionManager.IsWallUpcoming(nextPosition, directionVectors[(int)predefinedPath[nextValidDirectionIndex]]))
{
// If we're at a Vector2.zero, we skip applying the direction and only increment.
if (nextValidDirectionIndex == predefinedPathIndex)

View File

@@ -283,19 +283,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: pelletManager
Data: collisionManager
- Name: $v
Entry: 7
Data: 17|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletManager
Data: collisionManager
- Name: <UserType>k__BackingField
Entry: 7
Data: 18|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.PelletManager, Assembly-CSharp
Data: Marro.PacManUdon.CollisionManager, Assembly-CSharp
- Name:
Entry: 8
Data:

View File

@@ -11,7 +11,7 @@ namespace Marro.PacManUdon
private Ghost[] ghosts;
private Ghost blinky;
private PelletManager pelletManager;
private CollisionManager collisionManager;
// Level constants
private float speedDefault;
@@ -57,10 +57,10 @@ namespace Marro.PacManUdon
private bool frozen;
private bool kinematic;
public void Initialize(Transform[] ghostStarts, Transform[] ghostTargets, PacMan pacMan, PelletManager pelletManager, GameManager gameController)
public void Initialize(Transform[] ghostStarts, Transform[] ghostTargets, PacMan pacMan, CollisionManager collisionManager, GameManager gameController)
{
this.gameController = gameController;
this.pelletManager = pelletManager;
this.collisionManager = collisionManager;
ghosts = transform.GetComponentsInChildren<Ghost>(true);
blinky = ghosts[0];
@@ -72,7 +72,7 @@ namespace Marro.PacManUdon
Vector2 idlePosition2 = ghostTargets[2 + ghostIndex * 3].localPosition;
Vector2 cornerPosition = ghostTargets[3 + ghostIndex * 3].localPosition;
ghosts[ghostIndex].Initialize(pelletManager, pacMan, blinky, startTransform, homePosition, idlePosition1, idlePosition2, cornerPosition, ghostIndex);
ghosts[ghostIndex].Initialize(collisionManager, pacMan, blinky, startTransform, homePosition, idlePosition1, idlePosition2, cornerPosition, ghostIndex);
}
SubscribeToEvent(NetworkEventType.GhostUpdate);
@@ -105,7 +105,7 @@ namespace Marro.PacManUdon
public void NewLevel()
{
SetSharedPelletCounterActive(false);
UpdateElroyLevel(pelletManager.PelletCount);
UpdateElroyLevel(collisionManager.PelletCount);
foreach (Ghost ghost in ghosts)
{
ghost.ResetHousePelletCounter();

View File

@@ -331,19 +331,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: pelletManager
Data: collisionManager
- Name: $v
Entry: 7
Data: 19|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletManager
Data: collisionManager
- Name: <UserType>k__BackingField
Entry: 7
Data: 20|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.PelletManager, Assembly-CSharp
Data: Marro.PacManUdon.CollisionManager, Assembly-CSharp
- Name:
Entry: 8
Data:

View File

@@ -9,7 +9,7 @@ namespace Marro.PacManUdon
{
private GameManager gameManager;
private PlayerInput input;
private PelletManager pelletManager;
private CollisionManager collisionManager;
private float defaultSpeed;
private float powerPelletSpeed;
private float speed;
@@ -41,10 +41,10 @@ namespace Marro.PacManUdon
#endregion
public void Initialize(PlayerInput input, Transform startTransform, GameManager gameManager, PelletManager pelletManager)
public void Initialize(PlayerInput input, Transform startTransform, GameManager gameManager, CollisionManager collisionManager)
{
this.gameManager = gameManager;
this.pelletManager = pelletManager;
this.collisionManager = collisionManager;
this.input = input;
animator = GetComponent<Animator>();
renderer = GetComponent<Renderer>();
@@ -131,7 +131,7 @@ namespace Marro.PacManUdon
private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition)
{
if (CrossesTileCenter(position, nextPosition, Direction.Left) // If pacman is moving horizontally, check if he may cross the center of a tile in that axis
&& (!IsHorizontal(targetDirection) || pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)HorizontalComponent(direction)])))
&& (!IsHorizontal(targetDirection) || collisionManager.IsWallUpcoming(nextPosition, directionVectors[(int)HorizontalComponent(direction)])))
{ // If the target direction is in the other axis or if we're about to run into a wall
nextPosition.x = PositionToGrid(nextPosition).x; // Snap pacman to the center of his current tile in this axis
SetDirection(VerticalComponent(direction));
@@ -139,7 +139,7 @@ namespace Marro.PacManUdon
}
if (CrossesTileCenter(position, nextPosition, Direction.Down) // See comments above but now vertical
&& (!IsVertical(targetDirection) || pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)VerticalComponent(direction)])))
&& (!IsVertical(targetDirection) || collisionManager.IsWallUpcoming(nextPosition, directionVectors[(int)VerticalComponent(direction)])))
{
nextPosition.y = PositionToGrid(nextPosition).y;
SetDirection(HorizontalComponent(direction));
@@ -148,7 +148,7 @@ namespace Marro.PacManUdon
var inputDirection = input.GetDirection();
if (!inputDirection.Equals(Direction.Zero) && !inputDirection.Equals(targetDirection) // Ignore neutral input or input in our current direction
&& !pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)inputDirection])) // Check if the requested direction does not have a wall
&& !collisionManager.IsWallUpcoming(nextPosition, directionVectors[(int)inputDirection])) // Check if the requested direction does not have a wall
{
// Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel
if (IsHorizontal(inputDirection))
@@ -182,7 +182,7 @@ namespace Marro.PacManUdon
{
nextValidDirectionIndex += 1;
}
if (!pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)predefinedPath[nextValidDirectionIndex]]))
if (!collisionManager.IsWallUpcoming(nextPosition, directionVectors[(int)predefinedPath[nextValidDirectionIndex]]))
{
// If we're at a Vector2.zero, we skip applying the direction and only increment.
if (nextValidDirectionIndex == predefinedPathIndex)
@@ -213,7 +213,7 @@ namespace Marro.PacManUdon
private void CheckNewTile(Vector2 position, Vector2 nextPosition)
{
var eatResult = pelletManager.PacManMoveToTile(position, nextPosition);
var eatResult = collisionManager.PacManMoveToTile(position, nextPosition);
if (eatResult == EatResult.Pellet)
{

View File

@@ -323,7 +323,7 @@ namespace Marro.PacManUdon
break;
case 3:
SetPelletsActive(true);
pelletManager.RestoreAllPellets();
collisionManager.RestoreAllPellets();
statusDisplay.SetGameOverTextVisible(true);
break;
case 4:

View File

@@ -9,7 +9,7 @@ namespace Marro.PacManUdon
case 0:
// Show game over text, freeze power pellet blink
statusDisplay.SetGameOverTextVisible(true);
pelletManager.FreezePowerPelletsBlink(true);
collisionManager.FreezePowerPelletsBlink(true);
break;
case 1:
break;

View File

@@ -42,7 +42,7 @@ namespace Marro.PacManUdon
SetFrozen(false);
soundManager.SuppressSound(false);
soundManager.StartGhostSound();
soundManager.UpdatePelletCount(pelletManager.PelletCount - pelletManager.PelletCollectedCount);
soundManager.UpdatePelletCount(collisionManager.PelletCount - collisionManager.PelletCollectedCount);
}
}
}