public static JSONObject GetField(this SocketIOEvent e, string field)
    {
        if (!e.HasPayload())
        {
            return(null);
        }
        var payload = e.GetPayload();

        return(payload.HasField(field) ? payload.GetField(field) : null);
    }
Exemplo n.º 2
0
    public void OnPlayerAdded(SocketIOEvent e)
    {
        Assert.That(e.HasPayload());

        var playerId = e.GetString(SOCKET_DATA_FIELDS.PlayerId);

        if (GetRemotePlayer(playerId) != null)
        {
            return;
        }

        AddPlayerFromPayload(e.GetPayload());
    }
    public static float?GetFloat(this SocketIOEvent e, string field)
    {
        if (!e.HasPayload())
        {
            return(null);
        }
        var payload = e.GetPayload();

        if (!payload.HasField(field))
        {
            return(null);
        }

        var jobj = payload.GetField(field);

        return(jobj.IsNumber ? jobj.n : float.Parse(jobj.str));
    }
Exemplo n.º 4
0
    public void OnPlayerWelcome(SocketIOEvent e)
    {
        Debug.Log($"welcomed, current player {(GetLocalPlayer() != null ? "set" : "null")}");

        if (GetLocalPlayer() != null)
        {
            return;
        }

        Assert.That(e.HasPayload());
        Assert.That(e.HasField("x"));
        Assert.That(e.HasField("y"));

        var x = e.GetFloat("x").Value;
        var y = e.GetFloat("y").Value;

        var position = new Vector3(x, 0.5F, y);

        this.localPlayer = CreatePlayer("local", position, Quaternion.identity, false);

        this.socket.EmitIfConnected(SOCKET_EVENTS.PlayerJoin, new JSONObject());
    }
 public static bool HasField(this SocketIOEvent e, string field)
 {
     return(e.HasPayload() && e.GetPayload().HasField(field));
 }