|
@@ -0,0 +1,106 @@
|
|
|
+using System.Collections;
|
|
|
+using System.Text;
|
|
|
+using Blue;
|
|
|
+using Newtonsoft.Json;
|
|
|
+using Newtonsoft.Json.Linq;
|
|
|
+using UnityEngine;
|
|
|
+using UnityEngine.Networking;
|
|
|
+
|
|
|
+public interface IMinMapService : IService
|
|
|
+{
|
|
|
+ void Get();
|
|
|
+ void Set();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ BindableProperty<int> setMinMap{ get; set; }
|
|
|
+}
|
|
|
+
|
|
|
+public class MinMapService : IMinMapService
|
|
|
+{
|
|
|
+ private string userInfoGetUrl;
|
|
|
+ private string userInfoSetUrl;
|
|
|
+ private string message;
|
|
|
+
|
|
|
+ public BindableProperty<int> setMinMap { get; set; } = new BindableProperty<int>(2);
|
|
|
+
|
|
|
+ public void OnInit()
|
|
|
+ {
|
|
|
+ userInfoGetUrl = "https://api-fat3.ghz-tech.com/mr-navigator/v1/user/getUserInfo";
|
|
|
+ userInfoSetUrl = "https://api-fat3.ghz-tech.com/mr-navigator/v1/user/settings";
|
|
|
+ }
|
|
|
+ public void Get()
|
|
|
+ {
|
|
|
+ CoroutineSystem.Instance.StartCoroutine(GetRequest());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Set()
|
|
|
+ {
|
|
|
+ CoroutineSystem.Instance.StartCoroutine(SetRequest(setMinMap.Value));
|
|
|
+ }
|
|
|
+
|
|
|
+ private IEnumerator GetRequest()
|
|
|
+ {
|
|
|
+ using (UnityWebRequest webRequest = new UnityWebRequest(userInfoGetUrl))
|
|
|
+ {
|
|
|
+ webRequest.downloadHandler = new DownloadHandlerBuffer();
|
|
|
+ webRequest.SetRequestHeader("Content-Type", "application/json;charset=utf-8");
|
|
|
+ webRequest.SetRequestHeader("authorization", HttpTool.Instance.Token);
|
|
|
+
|
|
|
+ yield return webRequest.SendWebRequest();
|
|
|
+
|
|
|
+ if (webRequest.result== UnityWebRequest.Result.ProtocolError || webRequest.result == UnityWebRequest.Result.ConnectionError)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.LogError(webRequest.downloadHandler.text);
|
|
|
+ if (!string.IsNullOrWhiteSpace(webRequest.downloadHandler.text))
|
|
|
+ {
|
|
|
+ message = webRequest.downloadHandler.text;
|
|
|
+ JObject jobject = JObject.Parse(message);
|
|
|
+ if (jobject["code"].ToString() == "200")
|
|
|
+ {
|
|
|
+ message = jobject["data"].ToString();
|
|
|
+ Debug.LogError(message);
|
|
|
+ if (!string.IsNullOrWhiteSpace(message))
|
|
|
+ {
|
|
|
+ GetUserInfo getUserInfo = JsonConvert.DeserializeObject<GetUserInfo>(message);
|
|
|
+
|
|
|
+ setMinMap.Value = getUserInfo.minMap;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private IEnumerator SetRequest(int isOpen)
|
|
|
+ {
|
|
|
+ using (UnityWebRequest webRequest = new UnityWebRequest(userInfoSetUrl, "POST"))
|
|
|
+ {
|
|
|
+ GetUserInfo getUserInfo = new GetUserInfo();
|
|
|
+ getUserInfo.minMap = isOpen;
|
|
|
+ string jsonData = JsonConvert.SerializeObject(getUserInfo);
|
|
|
+ Debug.LogError("JsonData"+jsonData);
|
|
|
+ byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonData);
|
|
|
+
|
|
|
+ webRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
|
|
|
+ webRequest.downloadHandler = new DownloadHandlerBuffer();
|
|
|
+
|
|
|
+ webRequest.SetRequestHeader("Content-Type", "application/json;charset=utf-8");
|
|
|
+ webRequest.SetRequestHeader("authorization", HttpTool.Instance.Token);
|
|
|
+
|
|
|
+ yield return webRequest.SendWebRequest();
|
|
|
+
|
|
|
+ if (webRequest.result== UnityWebRequest.Result.ProtocolError || webRequest.result == UnityWebRequest.Result.ConnectionError)
|
|
|
+ Debug.LogError("UnityWebRequest Error:"+webRequest.downloadHandler.text);
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|