From 32f77e41d40e2cc4895019a511470d7bc237ce97 Mon Sep 17 00:00:00 2001 From: vis2k Date: Wed, 16 Jan 2019 14:47:38 +0100 Subject: [PATCH] NetworkServer.SendToReady uses NetworkIdentity to avoid two GetComponent calls per SendToReady: one for the old GetComponent, one for the callers which always used .gameObject before. --- Assets/Mirror/Runtime/NetworkBehaviour.cs | 4 ++-- Assets/Mirror/Runtime/NetworkIdentity.cs | 2 +- Assets/Mirror/Runtime/NetworkServer.cs | 9 ++++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Assets/Mirror/Runtime/NetworkBehaviour.cs b/Assets/Mirror/Runtime/NetworkBehaviour.cs index 660dcdfaf..745634ce0 100644 --- a/Assets/Mirror/Runtime/NetworkBehaviour.cs +++ b/Assets/Mirror/Runtime/NetworkBehaviour.cs @@ -127,7 +127,7 @@ protected void SendRPCInternal(Type invokeClass, string rpcName, NetworkWriter w message.functionHash = (invokeClass + ":" + rpcName).GetStableHashCode(); // type+func so Inventory.RpcUse != Equipment.RpcUse message.payload = writer.ToArray(); - NetworkServer.SendToReady(gameObject, (short)MsgType.Rpc, message, channelId); + NetworkServer.SendToReady(netIdentity, (short)MsgType.Rpc, message, channelId); } [EditorBrowsable(EditorBrowsableState.Never)] @@ -174,7 +174,7 @@ protected void SendEventInternal(Type invokeClass, string eventName, NetworkWrit message.functionHash = (invokeClass + ":" + eventName).GetStableHashCode(); // type+func so Inventory.RpcUse != Equipment.RpcUse message.payload = writer.ToArray(); - NetworkServer.SendToReady(gameObject, (short)MsgType.SyncEvent, message, channelId); + NetworkServer.SendToReady(netIdentity, (short)MsgType.SyncEvent, message, channelId); } [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/Assets/Mirror/Runtime/NetworkIdentity.cs b/Assets/Mirror/Runtime/NetworkIdentity.cs index bfc871d78..bcf9fbd69 100644 --- a/Assets/Mirror/Runtime/NetworkIdentity.cs +++ b/Assets/Mirror/Runtime/NetworkIdentity.cs @@ -943,7 +943,7 @@ internal void UNetUpdate() message.netId = netId; message.payload = payload; - NetworkServer.SendToReady(gameObject, (short)MsgType.UpdateVars, message); + NetworkServer.SendToReady(this, (short)MsgType.UpdateVars, message); } } diff --git a/Assets/Mirror/Runtime/NetworkServer.cs b/Assets/Mirror/Runtime/NetworkServer.cs index abe55eb63..0690de652 100644 --- a/Assets/Mirror/Runtime/NetworkServer.cs +++ b/Assets/Mirror/Runtime/NetworkServer.cs @@ -225,11 +225,11 @@ public static bool SendToAll(short msgType, MessageBase msg, int channelId = Cha return result; } - public static bool SendToReady(GameObject contextObj, short msgType, MessageBase msg, int channelId = Channels.DefaultReliable) + public static bool SendToReady(NetworkIdentity identity, short msgType, MessageBase msg, int channelId = Channels.DefaultReliable) { if (LogFilter.Debug) { Debug.Log("Server.SendToReady msgType:" + msgType); } - if (contextObj == null) + if (identity == null) { // no context.. send to all ready connections foreach (KeyValuePair kvp in connections) @@ -243,7 +243,6 @@ public static bool SendToReady(GameObject contextObj, short msgType, MessageBase return true; } - NetworkIdentity identity = contextObj.GetComponent(); if (identity != null && identity.observers != null) { bool result = true; @@ -905,7 +904,7 @@ internal static void SendSpawnMessage(NetworkIdentity identity, NetworkConnectio // conn is == null when spawning it for the local player else { - SendToReady(identity.gameObject, (short)MsgType.SpawnPrefab, msg); + SendToReady(identity, (short)MsgType.SpawnPrefab, msg); } } // 'identity' is a scene object that should be spawned again @@ -928,7 +927,7 @@ internal static void SendSpawnMessage(NetworkIdentity identity, NetworkConnectio // conn is == null when spawning it for the local player else { - SendToReady(identity.gameObject, (short)MsgType.SpawnSceneObject, msg); + SendToReady(identity, (short)MsgType.SpawnSceneObject, msg); } } }