Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions sdks/csharp/src/ISpacetimeDBLogger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
#if UNITY_5_3_OR_NEWER
using UnityEngine;
Comment thread
ImDreamerDev marked this conversation as resolved.
#endif

namespace SpacetimeDB
{
Expand All @@ -25,6 +28,23 @@ public static class Log
new ConsoleLogger();
#endif

#if UNITY_5_3_OR_NEWER
/// <summary>
/// Resets the static instance to prevent data persistence when Enter Play Mode Options (Disable Domain Reloading) is active.
/// RuntimeInitializeOnLoadMethod is used since it is supported in older versions of Unity.
/// AutoStaticsCleanup and NoAutoStaticsCleanup is only supported in Unity 6+
/// </summary>
/// <remarks>
/// See the <see href="https://docs.unity3d.com/6000.5/Documentation/Manual/domain-reloading.html">Unity Domain Reloading Manual</see>
/// and the <see href="https://docs.unity3d.com/6000.5/Documentation/ScriptReference/RuntimeInitializeOnLoadMethodAttribute.html">RuntimeInitializeOnLoadMethodAttribute API Docs</see> for details.
/// </remarks>
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void ResetStaticFields()
{
Current = new UnityDebugLogger();
}
#endif

public static void Debug(string message) => Current.Debug(message);
public static void Trace(string message) => Current.Trace(message);
public static void Info(string message) => Current.Info(message);
Expand Down
20 changes: 20 additions & 0 deletions sdks/csharp/src/SpacetimeDBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
#if UNITY_5_3_OR_NEWER
using UnityEngine;
#endif
using SpacetimeDB.BSATN;
using SpacetimeDB.ClientApi;
using Thread = System.Threading.Thread;
Expand Down Expand Up @@ -289,6 +292,23 @@ internal struct ParsedMessage

private static readonly Status Committed = new Status.Committed(default);

#if UNITY_5_3_OR_NEWER
/// <summary>
/// Resets the static instance to prevent data persistence when Enter Play Mode Options (Disable Domain Reloading) is active.
/// RuntimeInitializeOnLoadMethod is used since it is supported in older versions of Unity.
/// AutoStaticsCleanup and NoAutoStaticsCleanup is only supported in Unity 6+
/// </summary>
/// <remarks>
/// See the <see href="https://docs.unity3d.com/6000.5/Documentation/Manual/domain-reloading.html">Unity Domain Reloading Manual</see>
/// and the <see href="https://docs.unity3d.com/6000.5/Documentation/ScriptReference/RuntimeInitializeOnLoadMethodAttribute.html">RuntimeInitializeOnLoadMethodAttribute API Docs</see> for details.
/// </remarks>
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void ResetStaticFields()
{
IsTesting = false;
}
#endif

/// <summary>
/// Get a description of a message suitable for storing in the tracker metadata.
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions sdks/csharp/src/SpacetimeDBNetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ public class SpacetimeDBNetworkManager : MonoBehaviour
{
internal static SpacetimeDBNetworkManager? _instance;

/// <summary>
/// Resets the static instance to prevent data persistence when Enter Play Mode Options (Disable Domain Reloading) is active.
/// RuntimeInitializeOnLoadMethod is used since it is supported in older versions of Unity.
/// AutoStaticsCleanup and NoAutoStaticsCleanup is only supported in Unity 6+
/// </summary>
/// <remarks>
/// See the <see href="https://docs.unity3d.com/6000.5/Documentation/Manual/domain-reloading.html">Unity Domain Reloading Manual</see>
/// and the <see href="https://docs.unity3d.com/6000.5/Documentation/ScriptReference/RuntimeInitializeOnLoadMethodAttribute.html">RuntimeInitializeOnLoadMethodAttribute API Docs</see> for details.
/// </remarks>
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void ResetStaticFields()
{
_instance = null;
}

public void Awake()
{
// Ensure that users don't create several SpacetimeDBNetworkManager instances.
Expand Down
21 changes: 21 additions & 0 deletions sdks/csharp/src/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
#if UNITY_5_3_OR_NEWER
using UnityEngine;
#endif
using SpacetimeDB.BSATN;
using SpacetimeDB.ClientApi;
using SpacetimeDB.EventHandling;
Expand Down Expand Up @@ -242,6 +245,24 @@ private static IReadWrite<Row> Serializer
}
}


#if UNITY_5_3_OR_NEWER
/// <summary>
/// Resets the static instance to prevent data persistence when Enter Play Mode Options (Disable Domain Reloading) is active.
/// RuntimeInitializeOnLoadMethod is used since it is supported in older versions of Unity.
/// AutoStaticsCleanup and NoAutoStaticsCleanup is only supported in Unity 6+
/// </summary>
/// <remarks>
/// See the <see href="https://docs.unity3d.com/6000.5/Documentation/Manual/domain-reloading.html">Unity Domain Reloading Manual</see>
/// and the <see href="https://docs.unity3d.com/6000.5/Documentation/ScriptReference/RuntimeInitializeOnLoadMethodAttribute.html">RuntimeInitializeOnLoadMethodAttribute API Docs</see> for details.
/// </remarks>
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void ResetStaticFields()
{
_serializer = null;
}
#endif

// The function to use for decoding a type value.
Row DecodeValue(BinaryReader reader) => Serializer.Read(reader);

Expand Down