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,36 @@
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
namespace PashaBibko.PenguinChase.Network
{
public class GameNetworkClient : NetworkBehaviour
{
private static Dictionary<ulong, GameNetworkClient> sConnectedClients = new();
private static bool sDoneInitialSearch = false;
private void Start()
{
name = $"NetworkClient-{OwnerClientId}";
// Searches for existing clients if it is the first one to be locally loaded
if (!sDoneInitialSearch)
{
GameNetworkClient[] clients = FindObjectsByType<GameNetworkClient>(FindObjectsSortMode.None);
foreach (GameNetworkClient client in clients)
{
ulong clientId = client.OwnerClientId;
sConnectedClients.Add(clientId, this);
}
sDoneInitialSearch = true;
}
// Else adds it to the global list of clients
else
{
sConnectedClients.Add(OwnerClientId, this);
}
}
}
}