Added game state and network client
This commit is contained in:
36
Assets/Scripts/Network/NetworkClient.cs
Normal file
36
Assets/Scripts/Network/NetworkClient.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user