mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-14 19:58:24 -04:00
596c4a5e5c
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.
46 lines
1.2 KiB
C#
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
|