Exemple #1
0
 ///<summary>
 ///Handle the received chat message.
 ///</summary>
 void HandleMessage(DataStreamReader streamReader)
 {
     //playername: message
     chat.text += $"<{otherPlayers[streamReader.ReadUInt()].name}>:{streamReader.ReadFixedString64().ToString()}\n";
     chatBoxScroll.verticalNormalizedPosition = 0;
     //Debug.Log($"Received message: {messageContent.ToString()}");
 }
Exemple #2
0
        public void ReadWriteFixedString64()
        {
            var dataStream = new DataStreamWriter(300 * 4, Allocator.Temp);

            var src = new FixedString64("This is a string");

            dataStream.WriteFixedString64(src);

            //Assert.AreEqual(src.LengthInBytes+2, dataStream.Length);

            var reader = new DataStreamReader(dataStream.AsNativeArray());
            var dst    = reader.ReadFixedString64();

            Assert.AreEqual(src, dst);
        }
Exemple #3
0
    ///<summary>
    ///Send a message from one player to all the others.
    ///</summary>
    void HandleMessage(DataStreamReader streamReader)
    {
        uint          senderID = streamReader.ReadUInt();
        FixedString64 content  = streamReader.ReadFixedString64();

        foreach (PlayerInfo player in connectedPlayers)
        {
            if (player.iD == senderID)
            {
                continue;
            }
            var writer = networkDriver.BeginSend(player.connection);
            writer.WriteUInt((uint)MessageType.Message);
            writer.WriteUInt(senderID);
            writer.WriteFixedString64(content);
            networkDriver.EndSend(writer);
        }
    }