Esempio n. 1
0
        public void ReadWriteFixedString32()
        {
            var dataStream = new DataStreamWriter(300 * 4, Allocator.Temp);

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

            dataStream.WriteFixedString32(src);

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

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

            Assert.AreEqual(src, dst);
        }
Esempio n. 2
0
    ///<summary>
    ///Handle another player joining the game.
    ///</summary>
    void HandlePlayerJoin(DataStreamReader streamReader)
    {
        //Join Message = uint playerID, string32 name, float r,g,b
        var    newPlayer       = Instantiate(playerPrefab);
        uint   playerID        = streamReader.ReadUInt();
        string otherPlayerName = streamReader.ReadFixedString32().ToString();
        uint   colorID         = streamReader.ReadUInt();

        //set up the player with the received data.
        newPlayer.GetComponent <SpriteRenderer>().color = pallette.colors[colorID];
        newPlayer.GetComponentInChildren <Text>().text  = otherPlayerName;

        var playerData = new NetworkPlayer()
        {
            transform = newPlayer.transform,
            name      = otherPlayerName
        };

        //Debug.Log($"Received info on player: {playerID}");
        otherPlayers.Add(playerID, playerData);
    }
Esempio n. 3
0
    ///<summary>
    ///Passes the info of the joining player on to the other players and tracks info.
    ///</summary>
    void HandlePlayerJoin(DataStreamReader streamReader, NetworkConnection sender)
    {
        PlayerInfo joinPlayer = new PlayerInfo()
        {
            connection = sender,
            iD         = streamReader.ReadUInt(),
            name       = streamReader.ReadFixedString32().ToString(),
            colourID   = streamReader.ReadUInt()
        };

        //notify all other players that a new one joined.
        for (int i = 0; i < connections.Length; i++)
        {
            if (!connections[i].IsCreated || connections[i] == sender)
            {
                continue;
            }
            var writer = networkDriver.BeginSend(NetworkPipeline.Null, connections[i]);
            writer.WriteUInt((uint)MessageType.Join);
            //playerID
            writer.WriteUInt(joinPlayer.iD);
            //playername
            writer.WriteFixedString32(joinPlayer.name);
            //colour
            writer.WriteUInt(joinPlayer.colourID);
            networkDriver.EndSend(writer);
        }
        //send info on all existing players.
        foreach (PlayerInfo player in connectedPlayers)
        {
            var writer = networkDriver.BeginSend(NetworkPipeline.Null, sender);
            writer.WriteUInt((uint)MessageType.Join);
            writer.WriteUInt(player.iD);
            writer.WriteFixedString32(player.name);
            writer.WriteUInt(player.colourID);
            networkDriver.EndSend(writer);
        }

        connectedPlayers.Add(joinPlayer);
    }
Esempio n. 4
0
 public void DeserializeVisual(ref DataStreamReader reader)
 {
     Entity.MeshID     = reader.ReadFixedString32();
     Entity.MaterialID = reader.ReadFixedString32();
 }