Added game state and network client

This commit is contained in:
2026-05-20 19:56:25 +01:00
parent 8d3998945a
commit 48f8ae6c08
34 changed files with 713 additions and 16 deletions

View File

@@ -0,0 +1,46 @@
using PashaBibko.PenguinChase.Extensions;
using Unity.Services.Authentication;
using Unity.Services.Core;
using System.Collections;
using UnityEngine;
namespace PashaBibko.PenguinChase.Network
{
public static class Authenticator
{
public static bool IsAuthenticated { get; private set; }
private static bool sIsAuthenticating;
public static IEnumerator Authenticate()
{
// Early return if already authenticated
Debug.Log($"Authenticate called, [Authenticated: {IsAuthenticated}]");
if (IsAuthenticated)
{
yield break;
}
// Stops multiple authentication attempts at the same time
if (sIsAuthenticating)
{
yield return new WaitUntil(() => IsAuthenticated || !sIsAuthenticating);
yield break; // User should be logged in from other attempt
}
sIsAuthenticating = true;
Debug.Log("Initializing Unity Services");
yield return UnityServices
.InitializeAsync()
.Await();
Debug.Log("Signing in anonymously");
yield return AuthenticationService.Instance
.SignInAnonymouslyAsync()
.Await();
Debug.Log("User has been authenticated");
sIsAuthenticating = false;
IsAuthenticated = true;
}
}
}