37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|
|
}
|