diff --git a/Assets/Scripts/BonusFruit.cs b/Assets/Scripts/BonusFruit.cs index ab49fd2..67195b5 100644 --- a/Assets/Scripts/BonusFruit.cs +++ b/Assets/Scripts/BonusFruit.cs @@ -1,14 +1,15 @@ -namespace Marro.PacManUdon -{ - using UdonSharp; - using UnityEngine; - using VRC.SDK3.Data; - using VRC.SDKBase; - using VRC.Udon; +using UdonSharp; +using UnityEngine; +using VRC.SDK3.Data; +namespace Marro.PacManUdon +{ + [RequireComponent(typeof(Animator))] + [RequireComponent(typeof(Renderer))] + [RequireComponent(typeof(Collider))] public class BonusFruit : UdonSharpBehaviour { - [SerializeField, UdonSynced, FieldChangeCallback(nameof(FruitType))] PacManFruitType fruitType; + PacManFruitType fruitType; Animator animator; new Renderer renderer; @@ -67,7 +68,6 @@ this.fruitType = fruitType; value = (int)fruitScoreValue[PacManConstants.FruitTypeToValue(fruitType)]; animator.SetFloat("FruitType", PacManConstants.FruitTypeToValue(fruitType)); - RequestSerialization(); } public void SetFrozen(bool frozen) @@ -80,7 +80,6 @@ renderer.enabled = active; collider.enabled = active; this.active = active; - RequestSerialization(); } public PacManFruitType FruitType @@ -101,18 +100,17 @@ get => active; } - private DataDictionary fruitScoreValue = new DataDictionary() - { - {(int)PacManFruitType.None , 0}, - {(int)PacManFruitType.Cherries , 100}, - {(int)PacManFruitType.Strawberry, 300}, - {(int)PacManFruitType.Peach , 500}, - {(int)PacManFruitType.Apple , 700}, - {(int)PacManFruitType.Grapes , 1000}, - {(int)PacManFruitType.Galaxian , 2000}, - {(int)PacManFruitType.Bell , 3000}, - {(int)PacManFruitType.Key , 5000} - }; - + private readonly DataDictionary fruitScoreValue = new DataDictionary() + { + {(int)PacManFruitType.None , 0}, + {(int)PacManFruitType.Cherries , 100}, + {(int)PacManFruitType.Strawberry, 300}, + {(int)PacManFruitType.Peach , 500}, + {(int)PacManFruitType.Apple , 700}, + {(int)PacManFruitType.Grapes , 1000}, + {(int)PacManFruitType.Galaxian , 2000}, + {(int)PacManFruitType.Bell , 3000}, + {(int)PacManFruitType.Key , 5000} + }; } } \ No newline at end of file diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 4477c60..c1ece4c 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -315,10 +315,6 @@ namespace Marro.PacManUdon { // Debug.Log($"{gameObject} State transitioning from {gameState} to {newGameState}"); gameState = newGameState; - if (Networking.IsOwner(gameObject)) - { - RequestSerialization(); - } } private void IncrementLevel() @@ -348,7 +344,6 @@ namespace Marro.PacManUdon } SetScore(this.score + score); - RequestSerialization(); } void SetScore(int score) diff --git a/Assets/Scripts/Ghost.cs b/Assets/Scripts/Ghost.cs index 477f109..7ec59a9 100644 --- a/Assets/Scripts/Ghost.cs +++ b/Assets/Scripts/Ghost.cs @@ -145,7 +145,6 @@ namespace Marro.PacManUdon faceInStartingDirectionUntilUnfrozen = true; UpdateAnimator(); - RequestSerialization(); // Debug.Log($"{gameObject} reset with state: {state}, target: {target}, offGrid: {offGrid}"); } @@ -666,7 +665,6 @@ namespace Marro.PacManUdon } this.scattering = scattering; UpdateAnimator(); - RequestSerialization(); } public void SetFrozen(bool frozen, bool ignoreIfCaught = false, bool keepAnimating = false) diff --git a/Assets/Scripts/GhostManager.cs b/Assets/Scripts/GhostManager.cs index 8425688..a00067d 100644 --- a/Assets/Scripts/GhostManager.cs +++ b/Assets/Scripts/GhostManager.cs @@ -92,7 +92,6 @@ } SetScattering(true, reverseDirection: false); - RequestSerialization(); } public void NewLevel() diff --git a/Assets/Scripts/PacMan.cs b/Assets/Scripts/PacMan.cs index bddc694..a75a977 100644 --- a/Assets/Scripts/PacMan.cs +++ b/Assets/Scripts/PacMan.cs @@ -1,12 +1,12 @@ -namespace Marro.PacManUdon +using System; +using UnityEngine; +using VRC.SDK3.Components; +using VRC.SDKBase; + +namespace Marro.PacManUdon { - using System; - using UdonSharp; - using UnityEngine; - using VRC.SDKBase; - using VRC.Udon; - using VRC.SDK3.Components; - + [RequireComponent(typeof(Animator))] + [RequireComponent(typeof(Renderer))] public class PacMan : GridMover { private GameManager gameController; @@ -28,12 +28,11 @@ private Vector2[] predefinedPath; private int predefinedPathIndex; - private Vector2 syncedPosition; private Vector2 targetDirection; private float freezeSeconds; private bool frozen; -#region Animator constants + #region Animator constants private const string AnimatorKeyDead = "Dead"; private const string AnimatorKeyDirection = "Direction"; private const float AnimatorDirectionNone = 0f; @@ -42,7 +41,7 @@ private const float AnimatorDirectionUp = 0.75f; private const float AnimatorDirectionDown = 1f; private const float AnimatorDirectionRightBig = 1.25f; -#endregion + #endregion public void Initialize(PlayerInput input, VRCObjectPool pelletPool, GameManager gameController) @@ -62,8 +61,7 @@ public void Reset() { // Debug.Log($"{gameObject} Reset!"); - transform.localPosition = startPosition; - transform.localRotation = startRotation; + transform.SetLocalPositionAndRotation(startPosition, startRotation); transform.localScale = startScale; direction = Vector2.left; targetDirection = Vector2.left; @@ -211,7 +209,7 @@ // Debug.Log($"{gameObject} UpdateAnimator with direction {direction}, dead {dead}, frozen {frozen}"); if (!gameObject.activeInHierarchy) return; - + animator.SetBool(AnimatorKeyDead, dead); if (dead) { diff --git a/Assets/Scripts/Sequences/TimeSequenceShared.cs b/Assets/Scripts/Sequences/TimeSequenceShared.cs index 3874a75..68897a7 100644 --- a/Assets/Scripts/Sequences/TimeSequenceShared.cs +++ b/Assets/Scripts/Sequences/TimeSequenceShared.cs @@ -15,7 +15,7 @@ namespace Marro.PacManUdon bool waitingForTimeSequenceFinalize; bool jumpingToTimeSequence; PacManTimeSequence currentTimeSequence; - [UdonSynced] float timeSequenceSecondsPassed; + float timeSequenceSecondsPassed; int timeSequenceProgress; float[] timeSequenceKeyframeTimes;