/// <summary> /// Method for communicating with the middleware and exchanging relevant metadata /// </summary> /// <param name="lat">Latitude of user</param> /// <param name="lon">Longitude of user</param> /// <param name="micrositeArr">Array of possible microsites</param> public IEnumerator RequestData(string[] micrositeArr, float lat, float lon) { var valObj = new Values { microsites = micrositeArr, latitude = lat, longitude = lon }; // data sent as part of POST request var json = JsonUtility.ToJson(valObj); var postContent = Encoding.UTF8.GetBytes(json); using (UnityWebRequest www = new UnityWebRequest("http://138.68.119.131/request/", "POST")) { www.uploadHandler = (UploadHandler) new UploadHandlerRaw(postContent); www.SetRequestHeader("Content-Type", "application/json"); www.downloadHandler = new DownloadHandlerBuffer(); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { // Overwrite data in RestaurantMetadata JsonUtility.FromJsonOverwrite(www.downloadHandler.text, RestaurantMetadata.GetData); var args = new ResDataReceivedEventArgs(www.responseCode); OnDataReceived(this, args); // Trigger event } } }
protected virtual void OnDataReceived(object source, ResDataReceivedEventArgs e) { DataReceived?.Invoke(this, e); }