From 5b8a5399a77d94946f8669ab32be1f00e4dad5d8 Mon Sep 17 00:00:00 2001 From: Tore Bergebakken Date: Sun, 2 Jun 2024 16:39:39 +0200 Subject: [PATCH] wip --- Assets/Scripts/Control&Input/Peer2PeerTransport.cs | 10 ++++++++++ Assets/Scripts/Gamestate/PlayerIdentity.cs | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Control&Input/Peer2PeerTransport.cs b/Assets/Scripts/Control&Input/Peer2PeerTransport.cs index d897fe156..1ea5d4745 100644 --- a/Assets/Scripts/Control&Input/Peer2PeerTransport.cs +++ b/Assets/Scripts/Control&Input/Peer2PeerTransport.cs @@ -4,9 +4,12 @@ using System.Linq; using CollectionExtensions; using Mirror; +using Unity.Netcode; using Unity.VisualScripting; using UnityEngine; using UnityEngine.SceneManagement; +using NetworkClient = Mirror.NetworkClient; +using NetworkManager = Mirror.NetworkManager; // TODO consider splitting this into match-specific state and general player metadata public struct PlayerDetails @@ -109,6 +112,10 @@ public InitializePlayerMessage(uint id, Vector3 position, Quaternion rotation) public Quaternion rotation; } +public struct ClientHasInitializedPlayersMessage : NetworkMessage {} + +public struct StartRoundMessage : NetworkMessage {} + public enum PlayerType { Local, @@ -179,6 +186,7 @@ public override void OnStartServer() { NetworkServer.RegisterHandler(OnSpawnPlayerInput); NetworkServer.RegisterHandler(OnReceiveUpdateLoadout); + NetworkServer.RegisterHandler(OnClientHasInitializedPlayers); ResetState(); } @@ -193,6 +201,7 @@ public override void OnClientConnect() NetworkClient.RegisterHandler(OnReceivePlayerDetails); NetworkClient.RegisterHandler(InitializeFPSPlayer); NetworkClient.RegisterHandler(OnReceiveUpdatedPlayerDetails); + NetworkServer.RegisterHandler(OnStartRound); // Send message for the input that we assume is registered // TODO doesn't work if players haven't pressed a key yet @@ -617,6 +626,7 @@ private IEnumerator SendSpawnRequestsAfterSceneLoad(string originalSceneName) foreach (var p in players.Values.Where(p => p.type is PlayerType.Remote && !connectedPlayers.Contains(p.id))) { + Debug.Log($"Spawning disconnected player {p.id}"); NetworkClient.Send(new SpawnPlayerMessage(p.id, PlayerType.Local)); } } diff --git a/Assets/Scripts/Gamestate/PlayerIdentity.cs b/Assets/Scripts/Gamestate/PlayerIdentity.cs index 828a3c113..4dfd7786b 100644 --- a/Assets/Scripts/Gamestate/PlayerIdentity.cs +++ b/Assets/Scripts/Gamestate/PlayerIdentity.cs @@ -149,6 +149,10 @@ public void UpdateFromDetails(PlayerDetails playerDetails, string name) } public override string ToString() => playerName; - + +#if UNITY_EDITOR public string ToColorString() => $"{playerName}"; +#else + public string ToColorString() => playerName; +#endif }