From 3ef7df8a7252f398adac68ca11308b64497ffc92 Mon Sep 17 00:00:00 2001 From: vis2k Date: Sun, 30 Dec 2018 23:09:08 +0100 Subject: [PATCH] NetworkServer.SendToClientOfPlayer simplified: doesn't loop through all connections anymore, which was crazy --- Mirror/Runtime/NetworkServer.cs | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/Mirror/Runtime/NetworkServer.cs b/Mirror/Runtime/NetworkServer.cs index 0c1738574..17241595b 100644 --- a/Mirror/Runtime/NetworkServer.cs +++ b/Mirror/Runtime/NetworkServer.cs @@ -487,23 +487,6 @@ public static void ClearHandlers() handlers.Clear(); } - // send this message to the player only - public static void SendToClientOfPlayer(GameObject player, short msgType, MessageBase msg) - { - foreach (KeyValuePair kvp in connections) - { - NetworkConnection conn = kvp.Value; - if (conn.playerController != null && - conn.playerController.gameObject == player) - { - conn.Send(msgType, msg); - return; - } - } - - Debug.LogError("Failed to send message to player object '" + player.name + ", not found in connection list"); - } - public static void SendToClient(int connectionId, short msgType, MessageBase msg) { NetworkConnection conn; @@ -515,6 +498,20 @@ public static void SendToClient(int connectionId, short msgType, MessageBase msg Debug.LogError("Failed to send message to connection ID '" + connectionId + ", not found in connection list"); } + // send this message to the player only + public static void SendToClientOfPlayer(GameObject player, short msgType, MessageBase msg) + { + NetworkIdentity identity = player.GetComponent(); + if (identity != null) + { + identity.connectionToClient.Send(msgType, msg); + } + else + { + Debug.LogError("SendToClientOfPlayer: player has no NetworkIdentity: " + player.name); + } + } + public static bool ReplacePlayerForConnection(NetworkConnection conn, GameObject player, Guid assetId) { NetworkIdentity identity;