I’ve got a dictionary which holds GameTiles with the key set to a vector2int for grid position. I need to send a bunch of these GameTiles through PunRPC. Is this the best way to do it or would there be a better way. I created these two tools to help me.
public static string Tiles2String(List<GameTile> _tileList)
{
string result = "";
foreach (GameTile i in _tileList)
{
result += ":" + i.gridLocation.ToString();
}
return result.Substring(1);
}
public static List<GameTile> String2Tiles(string _tileString)
{
string[] stringArray = _tileString.Split(':');
List<GameTile> result = new List<GameTile>();
foreach (string str in stringArray)
{
string vector = str.Substring(1, str.Length - 2);
string[] vector2split = vector.Split(",");
int x = int.Parse(vector2split[0]);
int y = int.Parse(vector2split[1]);
GameTile tile = BattleManager.Instance.gameTiles[new Vector2Int(x,y)];
result.Add(tile);
}
return result;
}