I want to send my player list from my server to all players, but RPC doesn’t support lists/arrays. what is the best way to get around this. keep in mind that the list couldn’t simply add a player to each player’s list each time, because when a player leaves the game, the list would get all out of order and it would add players that are already there to new players list.
You can use BinaryFormatter and Convert to store your list in a string - send it to the recipient and then get it back again.
I can’t (for some reason I don’t understand) find my previous answer to a similar question but I guess in JS it would look like this:
#pragma strict
import System.Runtime.Serialization.Formatters.Binary;
import System.Runtime.Serialization;
import System.IO;
var list = new List.<SomeClass>();
function Start () {
var o = new MemoryStream(); //Create something to hold the data
var bf = new BinaryFormatter(); //Create a formatter
bf.Serialize(o, list); //Save the list
var data = Convert.ToBase64String(o.GetBuffer()); //Convert the data to a string
//Reading it back in
var ins = new MemoryStream(Convert.FromBase64String(data)); //Create an input stream from the string
//Read back the data
var x : List.<SomeClass> = bf.Deserialize(ins);
print(x.Count);
}
You would send the string in data and use the second part to read it back again.