コード例 #1
0
        void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
        {
            int count = packets.Count;

            if (stream.isWriting)
            {
                stream.Serialize(ref count);

                while (packets.Count > 0)
                {
                    VoiceChatPacket packet = packets.Dequeue();
                    stream.WritePacket(packet);

                    // If this packet is the same size as the sample size, we can return it
                    if (packet.Data.Length == VoiceChatSettings.Instance.SampleSize)
                    {
                        VoiceChatBytePool.Instance.Return(packet.Data);
                    }
                }
            }
            else
            {
                if (Network.isServer)
                {
                    stream.Serialize(ref count);

                    for (int i = 0; i < count; ++i)
                    {
                        packets.Enqueue(stream.ReadPacket());

                        if (Network.connections.Length < 2)
                        {
                            packets.Dequeue();
                        }
                    }
                }
                else
                {
                    stream.Serialize(ref count);

                    for (int i = 0; i < count; ++i)
                    {
                        var packet = stream.ReadPacket();

                        if (player != null)
                        {
                            player.OnNewSample(packet);
                        }
                    }
                }
            }
        }