using System.Collections.Generic; using Unity.Netcode; using UnityEngine; namespace PashaBibko.PenguinChase.Network { public class GameNetworkClient : NetworkBehaviour { private static Dictionary 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(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); } } } }