public static void SendToMany <T>(IEnumerable <INetworkPlayer> players, T msg, int channelId = Channel.Reliable) { using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter()) { // pack message into byte[] once MessagePacker.Pack(msg, writer); var segment = writer.ToArraySegment(); int count = 0; foreach (INetworkPlayer player in players) { // send to all connections, but don't wait for them player.Send(segment, channelId); count++; } NetworkDiagnostics.OnSend(msg, channelId, segment.Count, count); } }
void FixedUpdate() { if (!SendMessagesAllowed) { return; } if (!Animator.enabled) { return; } CheckSendRate(); for (int i = 0; i < Animator.layerCount; i++) { if (!CheckAnimStateChanged(out int stateHash, out float normalizedTime, i)) { continue; } using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter()) { WriteParameters(writer); SendAnimationMessage(stateHash, normalizedTime, i, layerWeight[i], writer.ToArraySegment()); } } }