//The method to use to send data to a session.
 public int SendRTDataAndBytes(int opCode,
                               GameSparksRT.DeliveryIntent deliveryIntent,
                               ArraySegment <byte> unstructuredData,
                               RTData structuredData,
                               params int[] targetPlayers)
 {
     if (session != null)
     {
         return(session.SendRTDataAndBytes(opCode, deliveryIntent, unstructuredData, structuredData, targetPlayers));
     }
     return(-1);
 }
Exemple #2
0
    //The method to use to send data to a session.
    public int SendRTDataAndBytes(int opCode,
                                  GameSparksRT.DeliveryIntent deliveryIntent,
                                  ArraySegment <byte> unstructuredData,
                                  RTData structuredData,
                                  params int[] targetPlayers)
    {
#if UNITY_WEBGL && !UNITY_EDITOR
        string payloadString     = "";
        string dataJson          = "";
        string targetPlayersJson = "";

        if (unstructuredData.Count > 0)
        {
            payloadString = System.Text.Encoding.UTF8.GetString(unstructuredData.Array, 0, unstructuredData.Array.Length);
        }

        if (structuredData != null)
        {
            JsonObject o = CreateObjectData(structuredData);

            dataJson = o.ToString();

            //Debug.Log(dataJson);
        }

        if (targetPlayers != null)
        {
            JsonArray a = new JsonArray(targetPlayers.Length);

            for (int i = 0; i < targetPlayers.Length; i++)
            {
                a.Add(targetPlayers[i]);
            }

            targetPlayersJson = a.ToString();
        }

        return(GSSendRTDataAndBytes(currSessionId, opCode, (int)deliveryIntent, payloadString, dataJson, targetPlayersJson));
#else
        if (session != null)
        {
            return(session.SendRTDataAndBytes(opCode, deliveryIntent, unstructuredData, structuredData, targetPlayers));
        }
        return(-1);
#endif
    }