// Use this for initialization void Start() { string url = "http://172.23.28.228/hackheist/updateGameInformation.php"; PlayerPackage player = new PlayerPackage(); player.playerUsername = PlayerPrefs.GetString("identity"); char[] allKeys = PlayerPrefs.GetString("keyCards").ToCharArray(); char[] allBadges = PlayerPrefs.GetString("badges").ToCharArray(); int BadgeValue = (100 * (allBadges[0] + allBadges[1] + allBadges[2] + allBadges[3] + allBadges[4] + allBadges[5] + allBadges[6])); int KeyCardValue = (10 * (allKeys[0] + allKeys[1] + allKeys[2] + allKeys[3] + allKeys[4] + allKeys[5] + allKeys[6])); int ScoreValue = PlayerPrefs.GetInt("NumQuestionsCorrect") + BadgeValue + KeyCardValue; PlayerPrefs.SetInt("Score", ScoreValue); ScoreText.text = ScoreValue.ToString(); player.score = PlayerPrefs.GetInt("Score"); player.numOfCorrectQuestions = PlayerPrefs.GetInt("NumQuestionsCorrect"); player.keyCards = PlayerPrefs.GetString("keyCards"); player.badges = PlayerPrefs.GetString("badges"); string json = JsonUtility.ToJson(player); print(json); UnityEngine.Networking.UnityWebRequest www = UnityEngine.Networking.UnityWebRequest.Put(url, json); www.SetRequestHeader("Content-Type", "application/json"); www.SendWebRequest(); }
public IEnumerator IEnumeratorGet(string url, string token) { UnityEngine.Networking.UnityWebRequest webRequest = UnityEngine.Networking.UnityWebRequest.Get(url); webRequest.SetRequestHeader("X-Authorization", token); yield return(webRequest.Send()); if (webRequest.responseCode != 200) { switch (webRequest.responseCode) { case 400: print("Invalid Data"); yield break; case 401: print("User not found"); yield break; case 403: print("Forbidden"); yield break; } } user = JsonUtility.FromJson <User>(webRequest.downloadHandler.text); sceneLoader.ChangeToScene("main"); }
public IEnumerator Download_World() { yield return(new WaitUntil(() => download)); string world_name = doARsState.search; Debug.Log(world_name); // Download the file from the URL. It will not be saved in the Cache string BundleURL = "http://www.arnocular.org/handle_doARs/"; // string BundleURL = "http://127.0.0.1:2567/handle_doARs/"; UnityEngine.Networking.UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(BundleURL, 0); request.SetRequestHeader("world", world_name); yield return(request.Send()); AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request); Debug.Log(bundle); if (world_name == "") { Instantiate(bundle.mainAsset); } else { Handheld.Vibrate(); UnityEngine.Object[] list_of_worlds = bundle.LoadAllAssets(); foreach (UnityEngine.Object world in list_of_worlds) { // GameObject core = GameObject.Find("ModifiedARCore"); // Transform t = core.transform; // t.position += new Vector3(0,0,-1); try { UnityEngine.Object clone = Instantiate(world); Debug.Log(clone.name); GameObject f = GameObject.Find(clone.name); f.gameObject.AddComponent <SelfDestruct>(); GameObject k = GameObject.Find("PortalWindow"); k.GetComponent <Portal>().device = GameObject.Find("First Person Camera").transform; } catch { Debug.Log("Not available"); } } // Instantiate(bundle.LoadAsset(world_name)); } // Unload the AssetBundles compressed contents to conserve memory Debug.Log("download asset bundle"); bundle.Unload(false); doARsState.goToState(doARs_state.rest); download = false; StartCoroutine(Download_World()); } // memory is freed from the web stream (www.Dispose() gets called implicitly)
static int QPYX_SetRequestHeader_YXQP(IntPtr L_YXQP) { try { ToLua.CheckArgsCount(L_YXQP, 3); UnityEngine.Networking.UnityWebRequest QPYX_obj_YXQP = (UnityEngine.Networking.UnityWebRequest)ToLua.CheckObject <UnityEngine.Networking.UnityWebRequest>(L_YXQP, 1); string QPYX_arg0_YXQP = ToLua.CheckString(L_YXQP, 2); string QPYX_arg1_YXQP = ToLua.CheckString(L_YXQP, 3); QPYX_obj_YXQP.SetRequestHeader(QPYX_arg0_YXQP, QPYX_arg1_YXQP); return(0); } catch (Exception e_YXQP) { return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP)); } }
static int SetRequestHeader(IntPtr L) { try { ToLua.CheckArgsCount(L, 3); UnityEngine.Networking.UnityWebRequest obj = (UnityEngine.Networking.UnityWebRequest)ToLua.CheckObject <UnityEngine.Networking.UnityWebRequest>(L, 1); string arg0 = ToLua.CheckString(L, 2); string arg1 = ToLua.CheckString(L, 3); obj.SetRequestHeader(arg0, arg1); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public bool share(string id = "", string name = "", Dictionary <string, string> values = null) { if (api_access_token == null || !api_access_token.isValid()) { if (!getAccessToken()) { return(false); } } // If no id is supplied but we have one stored, reuse it. if (id == "" && statistic_id != "") { id = statistic_id; } string url = "https://api.globalstats.io/v1/statistics"; if (id != "") { url = "https://api.globalstats.io/v1/statistics/" + id; } else { if (name == "") { name = "anonymous"; } } string json_payload = "{\"name\":\"" + name + "\",\"values\":{"; bool semicolon = false; foreach (KeyValuePair <string, string> value in values) { if (semicolon) { json_payload += ","; } json_payload += "\"" + value.Key + "\":\"" + value.Value + "\""; semicolon = true; } json_payload += "}}"; byte[] pData = Encoding.ASCII.GetBytes(json_payload.ToCharArray()); GlobalstatsIO_StatisticResponse statistic = null; if (id == "") { Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("Authorization", "Bearer " + api_access_token.access_token); headers.Add("Content-Type", "application/json"); headers.Add("Content-Length", json_payload.Length.ToString()); WWW www = new WWW(url, pData, headers); while (!www.isDone) { System.Threading.Thread.Sleep(100); } // check for errors if (www.error == null) { //UnityEngine.Debug.Log ("WWW POST Ok!"); } else { UnityEngine.Debug.Log("WWW POST Error: " + www.error); UnityEngine.Debug.Log("WWW POST Content: " + www.text); return(false); } statistic = JsonUtility.FromJson <GlobalstatsIO_StatisticResponse>(www.text); } else { UnityEngine.Networking.UnityWebRequest www = UnityEngine.Networking.UnityWebRequest.Put(url, pData); www.SetRequestHeader("Authorization", "Bearer " + api_access_token.access_token); www.SetRequestHeader("Content-Type", "application/json"); UnityEngine.Networking.UploadHandler uploader = new UnityEngine.Networking.UploadHandlerRaw(pData); www.uploadHandler = uploader; www.Send(); while (!www.isDone) { System.Threading.Thread.Sleep(100); } // check for errors if (www.error == null) { //UnityEngine.Debug.Log ("WWW PUT Ok!"); } else { UnityEngine.Debug.Log("WWW PUT Error: " + www.error); UnityEngine.Debug.Log("WWW PUT Content: " + Encoding.ASCII.GetString(www.downloadHandler.data)); return(false); } statistic = JsonUtility.FromJson <GlobalstatsIO_StatisticResponse>(Encoding.ASCII.GetString(www.downloadHandler.data)); } // ID is available only on create, not on update, so do not overwrite it if (statistic._id != null && statistic._id != "") { statistic_id = statistic._id; } user_name = statistic.name; //Store the returned data statically foreach (GlobalstatsIO_StatisticValues value in statistic.values) { bool updated_existing = false; for (int i = 0; i < statistic_values.Count; i++) { if (statistic_values[i].key == value.key) { statistic_values[i] = value; updated_existing = true; break; } } if (!updated_existing) { statistic_values.Add(value); } } return(true); }
private IntPtr UnityBackgroundDownloadAddRequestHeader(IntPtr request, string Key, string val) { request.SetRequestHeader(Key, val); return(request); }
/// <summary> /// Generate a Web Request to Spark. /// </summary> /// <param name="resource">Resource.</param> /// <param name="requestType">Request type.</param> /// <param name="data">Data to upload.</param> public UnityWebRequest Generate(string resource, string requestType, byte[] data = null) { // Setup Headers. var www = new UnityWebRequest(BaseUrl + "/" + resource); www.SetRequestHeader("Authorization", "Bearer " + AuthenticationToken); www.SetRequestHeader("Content-type", "application/json; charset=utf-8"); www.method = requestType; www.downloadHandler = new DownloadHandlerBuffer(); // Is there data to upload? if (data != null) { www.uploadHandler = new UploadHandlerRaw(data); } return www; }