예제 #1
0
    public byte[] SerializeNetchan(int seq, int ack)
    {
        var builder = new FlatBufferBuilder(1);

        var plays = new Offset <Player> [1];

        Player.StartPlayer(builder);
        Player.AddId(builder, 1);
        var pos = Vec3.CreateVec3(builder, player.position.x, player.position.y, player.position.z);

        Player.AddPos(builder, pos);
        var rot = Vec3.CreateVec3(builder, player.localEulerAngles.x, player.localEulerAngles.y, player.localEulerAngles.z);

        Player.AddRot(builder, rot);
        var p1 = Player.EndPlayer(builder);

        plays[0] = p1;

        // serialize FlatBuffer data
        var players = Netchan.CreatePlayersVector(builder, plays);

        Netchan.StartNetchan(builder);
        Netchan.AddProtocol(builder, 1234);
        Netchan.AddSequence(builder, seq);
        Netchan.AddAck(builder, ack);
        Netchan.AddPlayers(builder, players);
        var net = Netchan.EndNetchan(builder);

        builder.Finish(net.Value);
        var buf = builder.SizedByteArray();

        return(buf);
    }