NetworkManagerTester working

This commit is contained in:
2026-06-10 20:09:41 +02:00
parent cf39fd5dd9
commit e7968a5753
15 changed files with 62866 additions and 998 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -123,7 +123,7 @@ namespace Marro.PacManUdon
private void InitializeNewGame()
{
Debug.Log($"{gameObject} Started new game!");
//Debug.Log($"{gameObject} Started new game!");
SetScore(0);
SetExtraLives(startingExtraLives);
SetLevel(1);
@@ -131,7 +131,7 @@ namespace Marro.PacManUdon
private void InitializeLevel()
{
Debug.Log($"{gameObject} New level started!");
//Debug.Log($"{gameObject} New level started!");
pelletManager.RestoreAllPellets();
@@ -142,7 +142,7 @@ namespace Marro.PacManUdon
private void RestartLevel(bool afterLifeLost = false)
{
Debug.Log($"{gameObject} (Re)started level!");
//Debug.Log($"{gameObject} (Re)started level!");
// SetInGameComponentVisibility(true);
@@ -186,7 +186,7 @@ namespace Marro.PacManUdon
public void GotPowerPellet(Pellet pellet)
{
Debug.Log($"{gameObject} GotPowerPellet");
//Debug.Log($"{gameObject} GotPowerPellet");
if (gameState == PacManGameState.AttractMode)
{
@@ -215,7 +215,7 @@ namespace Marro.PacManUdon
public void GhostCaught(int scoreBonus)
{
Debug.Log($"{gameObject} GhostCaught");
//Debug.Log($"{gameObject} GhostCaught");
if (gameState == PacManGameState.AttractMode)
{
@@ -246,7 +246,7 @@ namespace Marro.PacManUdon
public void Intermission2PoleUpdate()
{
Debug.Log($"{gameObject} Intermission2PoleUpdate");
//Debug.Log($"{gameObject} Intermission2PoleUpdate");
TimeSequenceSkipToNextStep();
}

View File

@@ -163,13 +163,13 @@ namespace Marro.PacManUdon
SetPosition(nextPosition);
}
private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition)
private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition)
{
if (turnAroundSoon && ghostState == PacManGhostState.Normal
&& GridMoverTools.CrossesTileBorder(position, nextPosition, direction.x != 0, direction.y != 0))
{
SetDirection(direction * -1);
Debug.Log($"{gameObject} turned around to direction {GetDirection()}");
//Debug.Log($"{gameObject} turned around to direction {GetDirection()}");
turnAroundSoon = false;
return nextPosition;
}
@@ -816,7 +816,6 @@ namespace Marro.PacManUdon
inTunnel = data.ReadBool(ref index);
rngState = data.ReadInt(ref index);
turnAroundSoon = data.ReadBool(ref index);
Debug.Log($"{gameObject} turnAroundSoon = {turnAroundSoon}");
speed = data.ReadFloat(ref index);
ghostState = (PacManGhostState)data.ReadByte(ref index);

View File

@@ -316,7 +316,7 @@ namespace Marro.PacManUdon
public void SetLevel(int level)
{
Debug.Log($"GhostManager: SetLevel {level}");
//Debug.Log($"GhostManager: SetLevel {level}");
SetLevelConstants(level);
int[] privatePelletCounterReleaseValues = PacManConstants.GetGhostHousePrivatePelletCounterLimitForLevel(level);
@@ -377,7 +377,7 @@ namespace Marro.PacManUdon
void SetScattering(bool scattering, bool reverseDirection = true)
{
Debug.Log($"{gameObject} SetScattering: {scattering}");
//Debug.Log($"{gameObject} SetScattering: {scattering}");
foreach (Ghost ghost in ghosts)
{
if (ghost == blinky && elroyLevel > 0) // Once blinky is elroy he no longer scatters
@@ -394,7 +394,7 @@ namespace Marro.PacManUdon
/// </summary>
void SetSharedPelletCounterActive(bool active)
{
Debug.Log($"{gameObject} SetSharedPelletCounterActive {active}");
//Debug.Log($"{gameObject} SetSharedPelletCounterActive {active}");
sharedPelletCounterActive = active;
foreach (Ghost ghost in ghosts)
{
@@ -529,7 +529,7 @@ namespace Marro.PacManUdon
}
ghostScaredQueueArray[i] = (byte)((Ghost)ghost.Reference).Index;
}
Debug.Log($"{gameObject} Sent a ghostScareQueue of length {ghostScaredQueue.Count}");
//Debug.Log($"{gameObject} Sent a ghostScareQueue of length {ghostScaredQueue.Count}");
data.Append(ghostScaredQueueArray, ref index);
}
@@ -579,7 +579,7 @@ namespace Marro.PacManUdon
ghostScaredQueue.Add(ghosts[ghostIndex]);
}
index += ghosts.Length;
Debug.Log($"{gameObject} Read back a ghostScareQueue of length {ghostScaredQueue.Count}");
//Debug.Log($"{gameObject} Read back a ghostScareQueue of length {ghostScaredQueue.Count}");
return true;
}

View File

@@ -47,7 +47,7 @@ namespace Marro.PacManUdon
public void SetActive(bool isActive)
{
Debug.Log($"({nameof(PacManUdon)} {nameof(Intermission2Pole)}) SetActive {isActive}.");
//Debug.Log($"({nameof(PacManUdon)} {nameof(Intermission2Pole)}) SetActive {isActive}.");
gameObject.SetActive(isActive);
}
@@ -115,7 +115,7 @@ namespace Marro.PacManUdon
public void SetStrechLevel(PoleStrechLevels level)
{
Debug.Log($"({nameof(PacManUdon)} {nameof(Intermission2Pole)}) Set strech level to {level}.");
//Debug.Log($"({nameof(PacManUdon)} {nameof(Intermission2Pole)}) Set strech level to {level}.");
_animator.SetFloat("Strech", GetAnimatorValueForStrechLevel(level));
}

View File

@@ -43,7 +43,7 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 38
Data: 40
- Name:
Entry: 7
Data:
@@ -1627,13 +1627,13 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: <Ready>k__BackingField
Data: ready
- Name: $v
Entry: 7
Data: 85|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: <Ready>k__BackingField
Data: ready
- Name: <UserType>k__BackingField
Entry: 9
Data: 34
@@ -2025,6 +2025,116 @@ MonoBehaviour:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: DebugImageToIndicateReady
- Name: $v
Entry: 7
Data: 104|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: DebugImageToIndicateReady
- Name: <UserType>k__BackingField
Entry: 9
Data: 98
- Name: <SystemType>k__BackingField
Entry: 9
Data: 98
- 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: 105|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 106|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: tester
- Name: $v
Entry: 7
Data: 107|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: tester
- Name: <UserType>k__BackingField
Entry: 7
Data: 108|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: NetworkManagerTester, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 4
- 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: 109|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: 13
Data:

View File

@@ -6,6 +6,7 @@ using UnityEngine;
using UnityEngine.Android;
using VRC.SDK3.UdonNetworkCalling;
using VRC.SDKBase;
using VRC.SDKBase.Midi;
using VRC.Udon.Common;
namespace Marro.PacManUdon
@@ -215,11 +216,23 @@ namespace Marro.PacManUdon
#endregion
#region Public fields
private bool ready = false;
/// <summary>
/// Whether this <see cref="NetworkManager"/> is ready to transmit or receive data.
/// If false, networking is disabled and this <see cref="NetworkManager"/> acts as a pass-through.
/// </summary>
public bool Ready { get; private set; } = false;
public bool Ready
{
get => ready;
private set
{
ready = value;
if (DebugImageToIndicateReady != null)
{
DebugImageToIndicateReady.SetFloat("Color", value ? 1 : 0);
}
}
}
/// <summary>
@@ -310,6 +323,8 @@ namespace Marro.PacManUdon
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Found {syncedUpdateSubscribers.Length} {nameof(SyncedObject)} in children of {root.name}.");
initialized = true;
Reset();
}
private bool TryGetNetworkEventSubscribers(out SyncedObject[][] result)
@@ -365,7 +380,14 @@ namespace Marro.PacManUdon
return;
}
IsOwner = Networking.IsOwner(gameObject);
if (tester == null)
{
IsOwner = Networking.IsOwner(gameObject);
}
else
{
IsOwner = tester.ShouldBeOwner(this);
}
ClearBuffer();
@@ -597,6 +619,10 @@ namespace Marro.PacManUdon
{
RequestSerialization();
serializationRequested = true;
if (tester != null)
{
tester.RequestSerializationTest();
}
}
[NetworkCallable]
@@ -623,7 +649,7 @@ namespace Marro.PacManUdon
private void ProgressPingTime()
{
if (eventsQueueIndex > 0
if (eventsQueueIndex > 0 && !serializationRequested
&& internalTime - lastEventTransmissionTime >= pingDelay)
{
RequestSerializationForEvents();
@@ -651,16 +677,19 @@ namespace Marro.PacManUdon
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Serializing {eventsQueueIndex} event(s), eventTransmissionHistory is now {ArrayToString(eventTransmissionHistory)} with index {eventTransmissionHistoryIndex}");
}
public override void OnPostSerialization(SerializationResult result)
public override void OnPostSerialization(SerializationResult result) => OnPostSerializationInternal(result.success, result.byteCount);
// Version of OnPostSerialization which does not require instantiating SerializationResult, so that it can be called for debugging purposes.
public void OnPostSerializationInternal(bool success, int byteCount)
{
if (!Ready || !IsOwner || networkedData.Length == 0)
{
return;
}
if (!result.success)
if (!success)
{
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Serialization failed! Tried to send {result.byteCount} bytes.");
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Serialization failed! Tried to send {byteCount} bytes.");
return;
}
@@ -695,6 +724,11 @@ namespace Marro.PacManUdon
}
SendCustomNetworkEvent(VRC.Udon.Common.Interfaces.NetworkEventTarget.Owner, "RequestEventReceived", eventType);
if (tester != null)
{
tester.RequestEvent(eventType);
}
}
private void StoreIncomingData()
@@ -760,7 +794,7 @@ namespace Marro.PacManUdon
QueueEventInBuffer(@event);
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)} Queued event with id {eventId}");
//Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)} Queued event with id {eventId}");
}
else
{
@@ -1139,6 +1173,27 @@ namespace Marro.PacManUdon
/// </summary>
[SerializeField] private Animator DebugImageToIndicateSynced;
/// <summary>
/// An animator which visualizes whether the NetworkManager is synced.
/// </summary>
[SerializeField] private Animator DebugImageToIndicateReady;
private NetworkManagerTester tester;
public void SetNetworkManagerTester(NetworkManagerTester tester)
{
this.tester = tester;
}
public byte[] NetworkedData
{
get => networkedData;
set => networkedData = value;
}
public bool SerializationRequested => serializationRequested;
public void SetIsOwner(bool isOwner) => IsOwner = isOwner;
public void DoFullSync()
{
SendEventSoon(NetworkEventType.FullSync);

View File

@@ -64,7 +64,7 @@ namespace Marro.PacManUdon
SetDead(false);
animator.SetTrigger("Reset");
Debug.Log($"{gameObject} Reset! Position is now {GetPosition()}.");
//Debug.Log($"{gameObject} Reset! Position is now {GetPosition()}.");
}
public override void SyncedUpdate()

View File

@@ -18,7 +18,7 @@ namespace Marro.PacManUdon
private void StartTimeSequence(PacManTimeSequence timeSequence)
{
Debug.Log($"StartTimeSequence: {timeSequence}");
//Debug.Log($"StartTimeSequence: {timeSequence}");
TimeSequenceTryEndCurrent();
@@ -39,7 +39,7 @@ namespace Marro.PacManUdon
return;
}
Debug.Log($"{gameObject} TimeSequenceEndCurrent");
//Debug.Log($"{gameObject} TimeSequenceEndCurrent");
jumpingToTimeSequence = true;
TimeSequenceProgressToTime(100000f);
@@ -65,7 +65,7 @@ namespace Marro.PacManUdon
private void TimeSequenceSkipToNextStep()
{
Debug.Log($"{gameObject} TimeSequenceSkipToNextStep");
//Debug.Log($"{gameObject} TimeSequenceSkipToNextStep");
if (timeSequenceProgress < timeSequenceKeyframeTimes.Length)
{
TimeSequenceProgressToTime(timeSequenceKeyframeTimes[timeSequenceProgress]);
@@ -232,7 +232,7 @@ namespace Marro.PacManUdon
private void TimeSequenceExecuteStep(PacManTimeSequence timeSequence, int sequenceProgress)
{
Debug.Log($"{gameObject} Triggered time sequence step for sequence {currentTimeSequence} with progress {sequenceProgress}");
//Debug.Log($"{gameObject} Triggered time sequence step for sequence {currentTimeSequence} with progress {sequenceProgress}");
switch (timeSequence)
{
default:
@@ -286,7 +286,7 @@ namespace Marro.PacManUdon
private void TimeSequenceExecuteFinalize(PacManTimeSequence timeSequence)
{
Debug.Log($"{gameObject} Triggered time sequence finalize for sequence {currentTimeSequence}");
//Debug.Log($"{gameObject} Triggered time sequence finalize for sequence {currentTimeSequence}");
switch (timeSequence)
{
default:
@@ -330,7 +330,7 @@ namespace Marro.PacManUdon
private void TimeSequenceExecuteFinished(PacManTimeSequence timeSequence)
{
Debug.Log($"{gameObject} Triggered time sequence finished for sequence {currentTimeSequence}");
//Debug.Log($"{gameObject} Triggered time sequence finished for sequence {currentTimeSequence}");
switch (timeSequence)
{
default: