diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index c1ece4c..a23dfe6 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -35,7 +35,6 @@ namespace Marro.PacManUdon [SerializeField] private int pelletCountOverride = -1; private Maze maze; - private VRCObjectPool pelletPool; private Intermission2Pole intermission2Pole; private Animator mazeSpriteAnimator; @@ -65,14 +64,13 @@ namespace Marro.PacManUdon } maze = mazes[0]; - pelletPool = maze.pelletContainer.GetComponent(); mazeSpriteAnimator = maze.mazeSprite.GetComponent(); intermission2Pole = intermissionScreenElements[4].GetComponent(); ghostManager.Initialize(maze.ghostTargets, pacMan, this); - pacMan.Initialize(playerInput, pelletPool, this); + pacMan.Initialize(playerInput, this); bonusFruit.Initialize(); - pelletManager.Initialize(pelletPool); + pelletManager.Initialize(); statusDisplay.Initialize(); playerInput.Initialize(this); soundManager.Initialize(); @@ -114,7 +112,6 @@ namespace Marro.PacManUdon public void StartGameButtonPressed() { Debug.Log($"{gameObject} Start Game Button was pressed!"); - TakeOwnership(); StartTimeSequence(PacManTimeSequence.StartNewGame); } @@ -142,7 +139,7 @@ namespace Marro.PacManUdon { Debug.Log($"{gameObject} New level started!"); - pelletCountTotal = pelletPool.Pool.Length; + pelletCountTotal = pelletManager.PelletCount; pelletCountRemaining = pelletCountTotal; ghostManager.SetPelletsRemaining(pelletCountRemaining); ghostManager.NewLevel(); @@ -283,7 +280,7 @@ namespace Marro.PacManUdon void SetPelletsActive(bool active) { - pelletPool.gameObject.SetActive(active); + pelletManager.gameObject.SetActive(active); } void SetMazeVisible(bool visible) @@ -365,20 +362,12 @@ namespace Marro.PacManUdon public void DecrementLives() { - if (!Networking.IsOwner(gameObject)) - { - return; - } // Debug.Log($"{gameObject} Decremented lives from {extraLives} to {extraLives - 1}"); SetExtraLives(extraLives - 1); } void IncrementLives() { - if (!Networking.IsOwner(gameObject)) - { - return; - } // Debug.Log($"{gameObject} Incremented lives from {extraLives} to {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) { data[offset++] = new byte[] { NetworkManager.Int32ToByte((int)gameState) }; diff --git a/Assets/Scripts/Ghost.cs b/Assets/Scripts/Ghost.cs index 7ec59a9..029a774 100644 --- a/Assets/Scripts/Ghost.cs +++ b/Assets/Scripts/Ghost.cs @@ -779,7 +779,7 @@ namespace Marro.PacManUdon void OnTriggerEnter(Collider other) { - if (Networking.IsOwner(gameObject) && other.gameObject.GetComponent()) + if (other.gameObject.GetComponent()) { if (isScared) { diff --git a/Assets/Scripts/GhostManager.cs b/Assets/Scripts/GhostManager.cs index a00067d..3ca4c55 100644 --- a/Assets/Scripts/GhostManager.cs +++ b/Assets/Scripts/GhostManager.cs @@ -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) { if (ghostState == PacManGhostState.Returning || ghostState == PacManGhostState.Entering) diff --git a/Assets/Scripts/PacMan.cs b/Assets/Scripts/PacMan.cs index a75a977..d5e6b4a 100644 --- a/Assets/Scripts/PacMan.cs +++ b/Assets/Scripts/PacMan.cs @@ -19,7 +19,6 @@ namespace Marro.PacManUdon private Vector3 startScale; private Animator animator; new Renderer renderer; - private VRCObjectPool pelletPool; private bool hideUntilUnfrozen; private bool dead; private bool kinematic; @@ -44,11 +43,10 @@ namespace Marro.PacManUdon #endregion - public void Initialize(PlayerInput input, VRCObjectPool pelletPool, GameManager gameController) + public void Initialize(PlayerInput input, GameManager gameController) { this.gameController = gameController; this.input = input; - this.pelletPool = pelletPool; animator = GetComponent(); renderer = GetComponent(); frozen = false; @@ -143,23 +141,20 @@ namespace Marro.PacManUdon // 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(); - 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 - && !GridMoverTools.CheckCollisionInDirection(transform, nextPosition, inputDirection)) - { // Check if the requested direction does not have a wall - if (inputDirection.x != 0) - { // Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel - SetDirection(inputDirection + new Vector2(0, GridMoverTools.PositionToGrid(nextPosition).y - nextPosition.y).normalized); - } - else - { - SetDirection(inputDirection + new Vector2(GridMoverTools.PositionToGrid(nextPosition).x - nextPosition.x, 0).normalized); - } - SetTargetDirection(inputDirection); // This is the direction most logic should assume pacman is moving, the actual direction may be different due to cornering + Vector2 inputDirection = input.GetDirection(); + 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 + && !GridMoverTools.CheckCollisionInDirection(transform, nextPosition, inputDirection)) + { // Check if the requested direction does not have a wall + if (inputDirection.x != 0) + { // Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel + SetDirection(inputDirection + new Vector2(0, GridMoverTools.PositionToGrid(nextPosition).y - nextPosition.y).normalized); } + else + { + SetDirection(inputDirection + new Vector2(GridMoverTools.PositionToGrid(nextPosition).x - nextPosition.x, 0).normalized); + } + SetTargetDirection(inputDirection); // This is the direction most logic should assume pacman is moving, the actual direction may be different due to cornering } return nextPosition; @@ -324,15 +319,7 @@ namespace Marro.PacManUdon Pellet pellet = other.gameObject.GetComponent(); 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) { @@ -346,7 +333,7 @@ namespace Marro.PacManUdon } return; } - else if (Networking.IsOwner(gameObject) && other.gameObject.GetComponent()) + else if (other.gameObject.GetComponent()) { gameController.GotFruit(); } diff --git a/Assets/Scripts/Pellet.cs b/Assets/Scripts/Pellet.cs index 71e0dda..01544ca 100644 --- a/Assets/Scripts/Pellet.cs +++ b/Assets/Scripts/Pellet.cs @@ -3,9 +3,10 @@ using UdonSharp; using UnityEngine; + [RequireComponent(typeof(Renderer))] public class Pellet : UdonSharpBehaviour { - [SerializeField] public bool isPowerPellet = false; + public bool isPowerPellet = false; public Renderer pelletRenderer; void Start() diff --git a/Assets/Scripts/PelletManager.cs b/Assets/Scripts/PelletManager.cs index 05c8f82..5673408 100644 --- a/Assets/Scripts/PelletManager.cs +++ b/Assets/Scripts/PelletManager.cs @@ -1,42 +1,24 @@ -namespace Marro.PacManUdon -{ - using UdonSharp; - using UnityEngine; - using VRC.SDK3.Components; - using VRC.SDKBase; - using VRC.Udon; +using UdonSharp; +using UnityEngine; +namespace Marro.PacManUdon +{ public class PelletManager : UdonSharpBehaviour { - [SerializeField] Pellet[] pellets; - VRCObjectPool pelletPool; + Pellet[] pellets; Renderer[] pelletRenderers; Animator[] powerPellets; - bool powerPelletBlinkEnabled; float powerPelletBlinkToggleInterval; float powerPelletBlinkProgress; 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(); - } - - powerPellets = GetComponentsInChildren(true); - // Debug.Log($"{gameObject} Initialized, powerPellets: {powerPellets}"); - powerPelletBlinkToggleInterval = PacManConstants.GetPowerPelletBlinkToggleInterval(); - SetPowerPelletsBlink(false); - } - public void Initialize() { + gameObject.SetActive(true); + pellets = GetComponentsInChildren(includeInactive: true); + pelletRenderers = new Renderer[pellets.Length]; for (int i = 0; i < pelletRenderers.Length; i++) { @@ -91,12 +73,9 @@ public void RestoreAllPellets() { - foreach (GameObject pellet in pelletPool.Pool) + foreach (var pellet in pellets) { - if (pelletPool.TryToSpawn() == false) - { - break; - } + pellet.gameObject.SetActive(true); } foreach (Renderer pelletRenderer in pelletRenderers) @@ -104,5 +83,7 @@ pelletRenderer.enabled = true; } } + + public int PelletCount => pellets.Length; } } \ No newline at end of file diff --git a/Assets/Scripts/Sequences/TimeSequenceShared.cs b/Assets/Scripts/Sequences/TimeSequenceShared.cs index 68897a7..99d3bfc 100644 --- a/Assets/Scripts/Sequences/TimeSequenceShared.cs +++ b/Assets/Scripts/Sequences/TimeSequenceShared.cs @@ -89,7 +89,7 @@ namespace Marro.PacManUdon private void TimeSequencePrepareForFinish(PacManTimeSequence timeSequence) { - if (Networking.IsOwner(gameObject)) + if (networkManager.IsOwner) { TimeSequenceExecuteFinalize(timeSequence); if (!jumpingToTimeSequence)