I have a class like this:
using UnityEngine;
[System.Serializable]
public class PlayerInfo
{
public string playerId;
public string deviceId;
public static PlayerInfo CreateFromJSON(string jsonString)
{
return JsonUtility.FromJson<PlayerInfo>(jsonString);
}
}
And my client receives updates with a function like this:
void OnPlayerLocalJoin(Socket socket, Packet packet, params object[] args)
{
Debug.Log(args[0]);
}
According to the documentation (which need more detail), the args
should use the default json decoder, but I see it returns args
as System.Object[]
, but oddly enough when I try args[0]
my log returns:
System.Collections.Generic.Dictionary`2[System.String,System.Object]
When I print out the raw "packet" object, I do see my object:
[ "playerLocalUpdate", {"playerId":"abc","deviceId":"150B"} ]
No matter what I try, I cannot get the second part of this array to be a dictionary or better yet, how can I get it to be an instance of PlayerInfo
Debug.Log(packet.ToString());
var serialized = JsonUtility.ToJson(packet.ToString());
Debug.Log(serialized);
I'm trying to follow the docs: https://besthttp-documentation.readthedocs.io/en/latest/#3.%20Socket.IO/2%20Subscribing%20and%20receiving%20events/