Added basic lobby

This commit is contained in:
2026-05-20 21:03:54 +01:00
parent 48f8ae6c08
commit 6055fba959
15 changed files with 1019 additions and 6 deletions

View File

@@ -45,4 +45,4 @@ namespace PashaBibko.PenguinChase.Network
networkObject.SpawnAsPlayerObject(id);
}
}
}
}

View File

@@ -1,18 +1,54 @@
using System.Collections.Generic;
using Unity.Netcode;
using System.Linq;
using Unity.Collections;
using UnityEngine;
namespace PashaBibko.PenguinChase.Network
{
public class GameNetworkClient : NetworkBehaviour
{
private static Dictionary<ulong, GameNetworkClient> sConnectedClients = new();
public static int LocalClientCount { get; set; }
public static string LocalName { get; set; }
private static readonly Dictionary<ulong, GameNetworkClient> sConnectedClients = new();
private static bool sDoneInitialSearch = false;
public static GameNetworkClient LocalClient { get; private set; }
public static GameNetworkClient[] ConnectedClients => sConnectedClients.Values.ToArray();
public static int ConnectedClientCount => sConnectedClients.Count;
private readonly NetworkVariable<FixedString32Bytes> mPlayerName = new
(
default,
NetworkVariableReadPermission.Everyone,
NetworkVariableWritePermission.Owner
);
private readonly NetworkVariable<int> mLocalPlayerCount = new
(
0,
NetworkVariableReadPermission.Everyone,
NetworkVariableWritePermission.Owner
);
public int LocalPlayerCount => mLocalPlayerCount.Value;
public string PlayerName => mPlayerName.Value.ToString();
private void Start()
{
name = $"NetworkClient-{OwnerClientId}";
// If it is the local instance registers it as such
if (IsOwner)
{
mLocalPlayerCount.Value = LocalClientCount;
mPlayerName.Value = LocalName;
LocalClient = this;
Debug.Log($"[Game Network Client] has had start called [{LocalName} | {mPlayerName.Value}]");
}
// Searches for existing clients if it is the first one to be locally loaded
if (!sDoneInitialSearch)
{
@@ -32,5 +68,7 @@ namespace PashaBibko.PenguinChase.Network
sConnectedClients.Add(OwnerClientId, this);
}
}
public override void OnDestroy() => sConnectedClients.Remove(OwnerClientId);
}
}