more sorting

This commit is contained in:
vis2k 2021-03-07 15:18:00 +08:00
parent bf804a93c2
commit 2f90fca1d5

View File

@ -213,30 +213,6 @@ internal static void RemoveLocalConnection()
} }
// send //////////////////////////////////////////////////////////////// // send ////////////////////////////////////////////////////////////////
// this is like SendToReady - but it doesn't check the ready flag on the connection.
// this is used for ObjectDestroy messages.
static void SendToObservers<T>(NetworkIdentity identity, T message, int channelId = Channels.DefaultReliable)
where T : struct, NetworkMessage
{
// Debug.Log("Server.SendToObservers id:" + typeof(T));
if (identity == null || identity.observers == null || identity.observers.Count == 0)
return;
using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
{
// pack message into byte[] once
MessagePacking.Pack(message, writer);
ArraySegment<byte> segment = writer.ToArraySegment();
foreach (NetworkConnection conn in identity.observers.Values)
{
conn.Send(segment, channelId);
}
NetworkDiagnostics.OnSend(message, channelId, segment.Count, identity.observers.Count);
}
}
/// <summary>Send a message to all clients, even those that haven't joined the world yet (non ready)</summary> /// <summary>Send a message to all clients, even those that haven't joined the world yet (non ready)</summary>
public static void SendToAll<T>(T message, int channelId = Channels.DefaultReliable, bool sendToReadyOnly = false) public static void SendToAll<T>(T message, int channelId = Channels.DefaultReliable, bool sendToReadyOnly = false)
where T : struct, NetworkMessage where T : struct, NetworkMessage
@ -323,6 +299,30 @@ public static void SendToReady<T>(NetworkIdentity identity, T message, int chann
SendToReady(identity, message, true, channelId); SendToReady(identity, message, true, channelId);
} }
// this is like SendToReady - but it doesn't check the ready flag on the connection.
// this is used for ObjectDestroy messages.
static void SendToObservers<T>(NetworkIdentity identity, T message, int channelId = Channels.DefaultReliable)
where T : struct, NetworkMessage
{
// Debug.Log("Server.SendToObservers id:" + typeof(T));
if (identity == null || identity.observers == null || identity.observers.Count == 0)
return;
using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
{
// pack message into byte[] once
MessagePacking.Pack(message, writer);
ArraySegment<byte> segment = writer.ToArraySegment();
foreach (NetworkConnection conn in identity.observers.Values)
{
conn.Send(segment, channelId);
}
NetworkDiagnostics.OnSend(message, channelId, segment.Count, identity.observers.Count);
}
}
/// <summary>Send this message to the player only</summary> /// <summary>Send this message to the player only</summary>
[Obsolete("Use identity.connectionToClient.Send() instead! Previously Mirror needed this function internally, but not anymore.")] [Obsolete("Use identity.connectionToClient.Send() instead! Previously Mirror needed this function internally, but not anymore.")]
public static void SendToClientOfPlayer<T>(NetworkIdentity identity, T msg, int channelId = Channels.DefaultReliable) public static void SendToClientOfPlayer<T>(NetworkIdentity identity, T msg, int channelId = Channels.DefaultReliable)