Esempio n. 1
0
    /**<summary> Set Item to server </summary>*/
    public static async Task <Tuple <bool, ItemData> > SetItem(string gameID, ItemData item)
    {
        UnityWebRequest www = new UnityWebRequest(App.config.apiURL + "/games/" + gameID + "/items", UnityWebRequest.kHttpVerbPOST);

        www.SetRequestHeader("Content-Type", "application/json");
        www.downloadHandler = new DownloadHandlerBuffer();
        www.uploadHandler   = new UploadHandlerRaw(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(item, serialise).Replace("$type", "type")));
        www.SendWebRequest();
        print(JsonConvert.SerializeObject(item, serialise).Replace("$type", "type"));

        while (!www.isDone)
        {
            await Task.Delay(100);
        }

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.Log(www.error);
            Debug.Log(www.downloadHandler.text);
            OnSetItemResponse?.Invoke(false, null);
            return(new Tuple <bool, ItemData>(false, null));
        }
        else
        {
            Debug.Log(www.downloadHandler.text);
            ItemData responseItem = ParseItem(www.downloadHandler.text);
            OnSetItemResponse?.Invoke(true, responseItem);
            return(new Tuple <bool, ItemData>(true, responseItem));
        }
    }
Esempio n. 2
0
    /**<summary> Set Item to server </summary>*/
    public static async Task <bool> SetItemDummy(string gameID, ItemData item)
    {
        await Task.Delay(10);

        string json = JsonConvert.SerializeObject(item, serialise);

        print(json);
        DummyServer.SetItem(json);
        OnSetItemResponse?.Invoke(true, item);
        return(true);
    }