Files
SpacetimeDB/src/NetworkManager.cs
T
Ingvar Stepanyan 596c4a5e5c Make logger a separate SDK setting from client instance (#79)
This allows to:

1. Have a preset logger that is already correctly matching the environment (console vs Unity).
2. Removes the need for explicit `SpacetimeDBClient.CreateInstance(...)` which is particularly awkward to use and easy to forget with singleton as it doesn't return a result as a factory method name could suggest. Instead, `SpacetimeDBClient.instance` is available on first use.
3. Slightly simplifies dependencies between classes, e.g. `ClientCache` doesn't need a circular dependency on `SpacetimeDBClient`, making future maintenance and changes a bit easier.
2024-04-24 17:51:53 +01:00

46 lines
1.2 KiB
C#

/* SpacetimeDB for Unity
* * This class is only used in Unity projects. Attach this to a gameobject in your scene to use SpacetimeDB.
* *
*/
#if UNITY_5_3_OR_NEWER
using UnityEngine;
namespace SpacetimeDB
{
// This is an optional helper class to store your auth token in PlayerPrefs
// Override GetTokenKey() if you want to use a player pref key specific to your game
public static class AuthToken
{
public static string Token => PlayerPrefs.GetString(GetTokenKey());
public static void SaveToken(string token)
{
PlayerPrefs.SetString(GetTokenKey(), token);
}
public static string GetTokenKey()
{
var key = "spacetimedb.identity_token";
#if UNITY_EDITOR
// Different editors need different keys
key += $" - {Application.dataPath}";
#endif
return key;
}
}
public class NetworkManager : MonoBehaviour
{
private void OnDestroy()
{
SpacetimeDBClient.instance.Close();
}
private void Update()
{
SpacetimeDBClient.instance.Update();
}
}
}
#endif