Created
November 22, 2024 13:50
SyncOnStart test cases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UdonSharp; | |
using UnityEngine; | |
using VRC.SDKBase; | |
namespace FairlySadPanda.TestCases | |
{ | |
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)] | |
public class SyncOnStart : UdonSharpBehaviour | |
{ | |
[SerializeField] private string testCaseName; | |
[SerializeField] private string dataToSync = "the quick brown fox jumped over the lazy dog"; | |
[UdonSynced] private string newSyncedData; | |
private string oldSyncedData; | |
public void Start() | |
{ | |
Debug.Log($"{buildPrefix()} sync on start triggered for {gameObject}"); | |
if (!Networking.IsOwner(gameObject)) | |
{ | |
Debug.Log($"{buildPrefix()} we don't think you're the owner of {gameObject} so we're not going to sync anything..."); | |
return; | |
} | |
if (oldSyncedData == dataToSync || newSyncedData == dataToSync) | |
{ | |
Debug.Log($"{buildPrefix()} not syncing anything, test already run"); | |
return; | |
} | |
newSyncedData = dataToSync; | |
RequestSerialization(); | |
} | |
public override void OnPreSerialization() | |
{ | |
Debug.Log($"{buildPrefix()} successfully reached preserialization of behaviour {gameObject}"); | |
} | |
public override void OnPostSerialization(VRC.Udon.Common.SerializationResult result) | |
{ | |
Debug.Log($"{buildPrefix()} successfully reached postserialization of behaviour {gameObject}"); | |
} | |
public override void OnDeserialization(VRC.Udon.Common.DeserializationResult result) | |
{ | |
if (newSyncedData == oldSyncedData) | |
{ | |
Debug.LogWarning($"{buildPrefix()} successfully reached deserialization of behaviour {gameObject}: synced value is '{newSyncedData}' which isn't new data. Is this intended?"); | |
return; | |
} | |
Debug.Log($"{buildPrefix()} successfully reached deserialization of behaviour {gameObject}: synced value is '{newSyncedData}'"); | |
oldSyncedData = newSyncedData; | |
} | |
private string buildPrefix() | |
{ | |
return $"[TEST] [{testCaseName}] [{Networking.LocalPlayer.displayName}:{Networking.LocalPlayer.playerId}]"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the tests involving interact I used this code: