mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkIdentity.UNetUpdate uses UpdateVarsMessage to reduce depencies on SendBytes
This commit is contained in:
parent
2b54665915
commit
14fcafda0c
@ -596,17 +596,18 @@ static void OnLocalClientSpawnSceneObject(NetworkMessage netMsg)
|
||||
|
||||
static void OnUpdateVarsMessage(NetworkMessage netMsg)
|
||||
{
|
||||
NetworkInstanceId netId = netMsg.reader.ReadNetworkId();
|
||||
if (LogFilter.logDev) { Debug.Log("ClientScene::OnUpdateVarsMessage " + netId + " channel:" + netMsg.channelId); }
|
||||
UpdateVarsMessage message = netMsg.ReadMessage<UpdateVarsMessage>();
|
||||
|
||||
if (LogFilter.logDev) { Debug.Log("ClientScene::OnUpdateVarsMessage " + message.netId + " channel:" + netMsg.channelId); }
|
||||
|
||||
NetworkIdentity localObject;
|
||||
if (s_NetworkScene.GetNetworkIdentity(netId, out localObject))
|
||||
if (s_NetworkScene.GetNetworkIdentity(message.netId, out localObject))
|
||||
{
|
||||
localObject.OnUpdateVars(netMsg.reader, false);
|
||||
localObject.OnUpdateVars(new NetworkReader(message.payload), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LogFilter.logWarn) { Debug.LogWarning("Did not find target for sync message for " + netId + " . Note: this can be completely normal because UDP messages may arrive out of order, so this message might have arrived after a Destroy message."); }
|
||||
if (LogFilter.logWarn) { Debug.LogWarning("Did not find target for sync message for " + message.netId + " . Note: this can be completely normal because UDP messages may arrive out of order, so this message might have arrived after a Destroy message."); }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -333,6 +333,24 @@ public override void Serialize(NetworkWriter writer)
|
||||
}
|
||||
}
|
||||
|
||||
class UpdateVarsMessage : MessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
public byte[] payload;
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
netId = reader.ReadNetworkId();
|
||||
payload = reader.ReadBytesAndSize();
|
||||
}
|
||||
|
||||
public override void Serialize(NetworkWriter writer)
|
||||
{
|
||||
writer.Write(netId);
|
||||
writer.WriteBytesAndSize(payload);
|
||||
}
|
||||
}
|
||||
|
||||
class AnimationMessage : MessageBase
|
||||
{
|
||||
public NetworkInstanceId netId;
|
||||
|
@ -742,12 +742,8 @@ internal void UNetUpdate()
|
||||
// go through each channel
|
||||
for (int channelId = 0; channelId < NetworkServer.numChannels; channelId++)
|
||||
{
|
||||
// prepare message header
|
||||
NetworkWriter writer = new NetworkWriter();
|
||||
writer.StartMessage((short)MsgType.UpdateVars);
|
||||
writer.Write(netId);
|
||||
|
||||
// serialize all the dirty components and send (if any were dirty)
|
||||
NetworkWriter writer = new NetworkWriter();
|
||||
if (OnSerializeAllSafely(m_NetworkBehaviours, writer, false, channelId))
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
@ -755,9 +751,12 @@ internal void UNetUpdate()
|
||||
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
|
||||
(short)MsgType.UpdateVars, name, 1);
|
||||
#endif
|
||||
// finish message and send
|
||||
writer.FinishMessage();
|
||||
NetworkServer.SendBytesToReady(gameObject, writer.ToArray(), channelId);
|
||||
// construct message and send
|
||||
UpdateVarsMessage message = new UpdateVarsMessage();
|
||||
message.netId = netId;
|
||||
message.payload = writer.ToArray();
|
||||
|
||||
NetworkServer.SendByChannelToReady(gameObject, (short)MsgType.UpdateVars, message, channelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user