Removed most old networking stuff

This commit is contained in:
2026-01-14 20:03:52 +01:00
parent 4922a91a04
commit d9aac0158d
7 changed files with 36 additions and 95 deletions

View File

@@ -35,7 +35,6 @@ namespace Marro.PacManUdon
[SerializeField] private int pelletCountOverride = -1; [SerializeField] private int pelletCountOverride = -1;
private Maze maze; private Maze maze;
private VRCObjectPool pelletPool;
private Intermission2Pole intermission2Pole; private Intermission2Pole intermission2Pole;
private Animator mazeSpriteAnimator; private Animator mazeSpriteAnimator;
@@ -65,14 +64,13 @@ namespace Marro.PacManUdon
} }
maze = mazes[0]; maze = mazes[0];
pelletPool = maze.pelletContainer.GetComponent<VRCObjectPool>();
mazeSpriteAnimator = maze.mazeSprite.GetComponent<Animator>(); mazeSpriteAnimator = maze.mazeSprite.GetComponent<Animator>();
intermission2Pole = intermissionScreenElements[4].GetComponent<Intermission2Pole>(); intermission2Pole = intermissionScreenElements[4].GetComponent<Intermission2Pole>();
ghostManager.Initialize(maze.ghostTargets, pacMan, this); ghostManager.Initialize(maze.ghostTargets, pacMan, this);
pacMan.Initialize(playerInput, pelletPool, this); pacMan.Initialize(playerInput, this);
bonusFruit.Initialize(); bonusFruit.Initialize();
pelletManager.Initialize(pelletPool); pelletManager.Initialize();
statusDisplay.Initialize(); statusDisplay.Initialize();
playerInput.Initialize(this); playerInput.Initialize(this);
soundManager.Initialize(); soundManager.Initialize();
@@ -114,7 +112,6 @@ namespace Marro.PacManUdon
public void StartGameButtonPressed() public void StartGameButtonPressed()
{ {
Debug.Log($"{gameObject} Start Game Button was pressed!"); Debug.Log($"{gameObject} Start Game Button was pressed!");
TakeOwnership();
StartTimeSequence(PacManTimeSequence.StartNewGame); StartTimeSequence(PacManTimeSequence.StartNewGame);
} }
@@ -142,7 +139,7 @@ namespace Marro.PacManUdon
{ {
Debug.Log($"{gameObject} New level started!"); Debug.Log($"{gameObject} New level started!");
pelletCountTotal = pelletPool.Pool.Length; pelletCountTotal = pelletManager.PelletCount;
pelletCountRemaining = pelletCountTotal; pelletCountRemaining = pelletCountTotal;
ghostManager.SetPelletsRemaining(pelletCountRemaining); ghostManager.SetPelletsRemaining(pelletCountRemaining);
ghostManager.NewLevel(); ghostManager.NewLevel();
@@ -283,7 +280,7 @@ namespace Marro.PacManUdon
void SetPelletsActive(bool active) void SetPelletsActive(bool active)
{ {
pelletPool.gameObject.SetActive(active); pelletManager.gameObject.SetActive(active);
} }
void SetMazeVisible(bool visible) void SetMazeVisible(bool visible)
@@ -365,20 +362,12 @@ namespace Marro.PacManUdon
public void DecrementLives() public void DecrementLives()
{ {
if (!Networking.IsOwner(gameObject))
{
return;
}
// Debug.Log($"{gameObject} Decremented lives from {extraLives} to {extraLives - 1}"); // Debug.Log($"{gameObject} Decremented lives from {extraLives} to {extraLives - 1}");
SetExtraLives(extraLives - 1); SetExtraLives(extraLives - 1);
} }
void IncrementLives() void IncrementLives()
{ {
if (!Networking.IsOwner(gameObject))
{
return;
}
// Debug.Log($"{gameObject} Incremented lives from {extraLives} to {extraLives + 1}"); // Debug.Log($"{gameObject} Incremented lives from {extraLives} to {extraLives + 1}");
SetExtraLives(extraLives + 1); SetExtraLives(extraLives + 1);
} }
@@ -409,14 +398,6 @@ namespace Marro.PacManUdon
} }
} }
void TakeOwnership()
{
Networking.SetOwner(Networking.LocalPlayer, gameObject);
Networking.SetOwner(Networking.LocalPlayer, pacMan.gameObject);
Networking.SetOwner(Networking.LocalPlayer, pelletPool.gameObject);
ghostManager.SetOwner(Networking.LocalPlayer);
}
public override void AppendSyncedData(byte[][] data, ref int offset, NetworkEventType eventType) public override void AppendSyncedData(byte[][] data, ref int offset, NetworkEventType eventType)
{ {
data[offset++] = new byte[] { NetworkManager.Int32ToByte((int)gameState) }; data[offset++] = new byte[] { NetworkManager.Int32ToByte((int)gameState) };

View File

@@ -779,7 +779,7 @@ namespace Marro.PacManUdon
void OnTriggerEnter(Collider other) void OnTriggerEnter(Collider other)
{ {
if (Networking.IsOwner(gameObject) && other.gameObject.GetComponent<PacManGhostCollider>()) if (other.gameObject.GetComponent<PacManGhostCollider>())
{ {
if (isScared) if (isScared)
{ {

View File

@@ -332,15 +332,6 @@
} }
} }
public void SetOwner(VRCPlayerApi player)
{
Networking.SetOwner(player, gameObject);
foreach (Ghost ghost in ghosts)
{
Networking.SetOwner(player, ghost.gameObject);
}
}
public float GetTargetSpeed(Ghost ghost, PacManGhostState ghostState, bool isScared, bool inTunnel) public float GetTargetSpeed(Ghost ghost, PacManGhostState ghostState, bool isScared, bool inTunnel)
{ {
if (ghostState == PacManGhostState.Returning || ghostState == PacManGhostState.Entering) if (ghostState == PacManGhostState.Returning || ghostState == PacManGhostState.Entering)

View File

@@ -19,7 +19,6 @@ namespace Marro.PacManUdon
private Vector3 startScale; private Vector3 startScale;
private Animator animator; private Animator animator;
new Renderer renderer; new Renderer renderer;
private VRCObjectPool pelletPool;
private bool hideUntilUnfrozen; private bool hideUntilUnfrozen;
private bool dead; private bool dead;
private bool kinematic; private bool kinematic;
@@ -44,11 +43,10 @@ namespace Marro.PacManUdon
#endregion #endregion
public void Initialize(PlayerInput input, VRCObjectPool pelletPool, GameManager gameController) public void Initialize(PlayerInput input, GameManager gameController)
{ {
this.gameController = gameController; this.gameController = gameController;
this.input = input; this.input = input;
this.pelletPool = pelletPool;
animator = GetComponent<Animator>(); animator = GetComponent<Animator>();
renderer = GetComponent<Renderer>(); renderer = GetComponent<Renderer>();
frozen = false; frozen = false;
@@ -143,8 +141,6 @@ namespace Marro.PacManUdon
// Debug.Log($"{gameObject} crossed Y tile center from {currentPosition} with targetDirection {targetDirection}, nextPosition is now {nextPosition} and direction is now {direction}"); // Debug.Log($"{gameObject} crossed Y tile center from {currentPosition} with targetDirection {targetDirection}, nextPosition is now {nextPosition} and direction is now {direction}");
} }
if (Networking.IsOwner(gameObject))
{
Vector2 inputDirection = input.GetDirection(); Vector2 inputDirection = input.GetDirection();
if (!inputDirection.Equals(Vector2.zero) && !inputDirection.Equals(targetDirection) // Ignore neutral input or input in our current direction if (!inputDirection.Equals(Vector2.zero) && !inputDirection.Equals(targetDirection) // Ignore neutral input or input in our current direction
&& (inputDirection.x == 0 || (Math.Round(nextPosition.y, 5) - 0.5) % 1 != 0) && (inputDirection.y == 0 || (Math.Round(nextPosition.x, 5) - 0.5) % 1 != 0) // Target grid position near the edge of a tile may not be correct, ignore inputs near the border && (inputDirection.x == 0 || (Math.Round(nextPosition.y, 5) - 0.5) % 1 != 0) && (inputDirection.y == 0 || (Math.Round(nextPosition.x, 5) - 0.5) % 1 != 0) // Target grid position near the edge of a tile may not be correct, ignore inputs near the border
@@ -160,7 +156,6 @@ namespace Marro.PacManUdon
} }
SetTargetDirection(inputDirection); // This is the direction most logic should assume pacman is moving, the actual direction may be different due to cornering SetTargetDirection(inputDirection); // This is the direction most logic should assume pacman is moving, the actual direction may be different due to cornering
} }
}
return nextPosition; return nextPosition;
} }
@@ -324,15 +319,7 @@ namespace Marro.PacManUdon
Pellet pellet = other.gameObject.GetComponent<Pellet>(); Pellet pellet = other.gameObject.GetComponent<Pellet>();
if (pellet) if (pellet)
{ {
if (Networking.IsOwner(gameObject))
{
pelletPool.Return(pellet.gameObject);
}
else
{
pellet.pelletRenderer.enabled = false;
pellet.gameObject.SetActive(false); pellet.gameObject.SetActive(false);
}
if (pellet.isPowerPellet) if (pellet.isPowerPellet)
{ {
@@ -346,7 +333,7 @@ namespace Marro.PacManUdon
} }
return; return;
} }
else if (Networking.IsOwner(gameObject) && other.gameObject.GetComponent<BonusFruit>()) else if (other.gameObject.GetComponent<BonusFruit>())
{ {
gameController.GotFruit(); gameController.GotFruit();
} }

View File

@@ -3,9 +3,10 @@
using UdonSharp; using UdonSharp;
using UnityEngine; using UnityEngine;
[RequireComponent(typeof(Renderer))]
public class Pellet : UdonSharpBehaviour public class Pellet : UdonSharpBehaviour
{ {
[SerializeField] public bool isPowerPellet = false; public bool isPowerPellet = false;
public Renderer pelletRenderer; public Renderer pelletRenderer;
void Start() void Start()

View File

@@ -1,42 +1,24 @@
namespace Marro.PacManUdon using UdonSharp;
{ using UnityEngine;
using UdonSharp;
using UnityEngine;
using VRC.SDK3.Components;
using VRC.SDKBase;
using VRC.Udon;
namespace Marro.PacManUdon
{
public class PelletManager : UdonSharpBehaviour public class PelletManager : UdonSharpBehaviour
{ {
[SerializeField] Pellet[] pellets; Pellet[] pellets;
VRCObjectPool pelletPool;
Renderer[] pelletRenderers; Renderer[] pelletRenderers;
Animator[] powerPellets; Animator[] powerPellets;
bool powerPelletBlinkEnabled; bool powerPelletBlinkEnabled;
float powerPelletBlinkToggleInterval; float powerPelletBlinkToggleInterval;
float powerPelletBlinkProgress; float powerPelletBlinkProgress;
bool powerPelletBlinkCurrentlyVisible; bool powerPelletBlinkCurrentlyVisible;
public void Initialize(VRCObjectPool pelletPool)
{
gameObject.SetActive(true);
this.pelletPool = pelletPool;
pelletRenderers = new Renderer[pelletPool.Pool.Length];
for (int i = 0; i < pelletRenderers.Length; i++)
{
pelletRenderers[i] = pelletPool.Pool[i].GetComponent<Renderer>();
}
powerPellets = GetComponentsInChildren<Animator>(true);
// Debug.Log($"{gameObject} Initialized, powerPellets: {powerPellets}");
powerPelletBlinkToggleInterval = PacManConstants.GetPowerPelletBlinkToggleInterval();
SetPowerPelletsBlink(false);
}
public void Initialize() public void Initialize()
{ {
gameObject.SetActive(true);
pellets = GetComponentsInChildren<Pellet>(includeInactive: true);
pelletRenderers = new Renderer[pellets.Length]; pelletRenderers = new Renderer[pellets.Length];
for (int i = 0; i < pelletRenderers.Length; i++) for (int i = 0; i < pelletRenderers.Length; i++)
{ {
@@ -91,12 +73,9 @@
public void RestoreAllPellets() public void RestoreAllPellets()
{ {
foreach (GameObject pellet in pelletPool.Pool) foreach (var pellet in pellets)
{ {
if (pelletPool.TryToSpawn() == false) pellet.gameObject.SetActive(true);
{
break;
}
} }
foreach (Renderer pelletRenderer in pelletRenderers) foreach (Renderer pelletRenderer in pelletRenderers)
@@ -104,5 +83,7 @@
pelletRenderer.enabled = true; pelletRenderer.enabled = true;
} }
} }
public int PelletCount => pellets.Length;
} }
} }

View File

@@ -89,7 +89,7 @@ namespace Marro.PacManUdon
private void TimeSequencePrepareForFinish(PacManTimeSequence timeSequence) private void TimeSequencePrepareForFinish(PacManTimeSequence timeSequence)
{ {
if (Networking.IsOwner(gameObject)) if (networkManager.IsOwner)
{ {
TimeSequenceExecuteFinalize(timeSequence); TimeSequenceExecuteFinalize(timeSequence);
if (!jumpingToTimeSequence) if (!jumpingToTimeSequence)