Page 1 of 1

Sending and Receiving an ES3File In Multiplayer

Posted: Mon May 21, 2018 11:23 pm
by frezno
Hello!

I just wanted to see if I'm on the right track of what I'm trying to do. Essentially I have an ES3File that will contain a bunch of various data that belongs to the player. I would like to send this file to all players in the room so that the users can load this players data without actually having to be sent the file physically.

In networking, the general rule is that sending Bytes it better than sending raw data and since ES3File has LoadRaw, would it be wise to essentially do something like the code below? I have tested it, and everything seemed fine, but I just wanted to make sure I'm doing this correctly or see if there is a better way to do it.

Thanks!

Code: Select all

    public void SendPlayerData(string playerDataFile)
    {
        //Load physical file into ES3File
        var pData = new ES3File(playerDataFile);

        //Convert player data to bytes
        var bytesToSend = pData.LoadRawBytes();

        this.RPC("SendBytes", All, bytesToSend);
    }

    public void ReceivePlayerData(byte[] receivedBytes)
    {
        var rData = new ES3File(receivedBytes);

        rData.LoadInto("playerSetupData", NetPlayer[thisPlayer.index].Components.PlayerData);
    }

Re: Sending and Receiving an ES3File In Multiplayer

Posted: Tue May 22, 2018 6:57 am
by Joel
Hi there,

This is indeed the best and most efficient way of doing what you want.

All the best,
Joel