mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkServer.SendToReady uses NetworkIdentity to avoid two GetComponent calls per SendToReady: one for the old GetComponent<NetworkIdentity>, one for the callers which always used .gameObject before.
This commit is contained in:
parent
dc9d12b67d
commit
32f77e41d4
@ -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)]
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<int, NetworkConnection> kvp in connections)
|
||||
@ -243,7 +243,6 @@ public static bool SendToReady(GameObject contextObj, short msgType, MessageBase
|
||||
return true;
|
||||
}
|
||||
|
||||
NetworkIdentity identity = contextObj.GetComponent<NetworkIdentity>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user