123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- using Blue;
- using LitJson;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System.Collections;
- using System.Collections.Generic;
- using System.Text;
- using UnityEngine;
- using UnityEngine.Networking;
- using XRTool.Util;
- public interface IUpOrDownloadService : IService
- {
- List<ScenePosRotInfo> PosRot { get; }
- void GetScenePosRot(int projectID);
- void UploadScenePosRot(string Url, string JsonString);
- }
- public class UpOrDownloadService : IUpOrDownloadService
- {
- public List<ScenePosRotInfo> PosRot { get; private set; }
- public int ProjectID { get; private set; }
- private string UrlPointCloudPosRot;
- public void OnInit()
- {
- // UrlPointCloudPosRot = "http://192.168.50.114:8888/mr-navigator/v1/project/position";
- UrlPointCloudPosRot = "https://api-fat3.ghz-tech.com/mr-navigator/v1/project/position";
- }
- void IUpOrDownloadService.GetScenePosRot(int projectID)
- {
- // TimerMgr.Instance.CreateTimer(()=> {
- CoroutineSystem.Instance.StartCoroutine(GetScenePosRotRequest(projectID));
- // },3,-1);
- }
- void IUpOrDownloadService.UploadScenePosRot(string Url, string JsonString)
- {
- CoroutineSystem.Instance.StartCoroutine(RequestUpload(Url,JsonString));
- }
- private IEnumerator GetScenePosRotRequest(int projectID)
- {
- using (UnityWebRequest webRequest = new UnityWebRequest(UrlPointCloudPosRot, "POST"))
- {
- ProjectID = projectID;
- ScenePointBodyInfo TestGet = new ScenePointBodyInfo();
- TestGet.id = projectID;
- TestGet.unity = false;
- string jsonData = JsonConvert.SerializeObject(TestGet);
- 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", UserInfo.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
- {
- if (!string.IsNullOrWhiteSpace(webRequest.downloadHandler.text))
- {
- string message = webRequest.downloadHandler.text;
- JObject jobject = JObject.Parse(message);
- if (jobject["code"].ToString() == "200")
- {
- message = jobject["data"].ToString();
- if (!string.IsNullOrWhiteSpace(message))
- {
- // TimerMgr.Instance.CreateTimer(() => {
- List<ScenePosRotInfo> ScenePosRotInfoList = JsonConvert.DeserializeObject<List<ScenePosRotInfo>>(message);
- // GongShi2.F2Dto3D(ScenePosRotInfoList[0].x, ScenePosRotInfoList[0].y, 643f, 1920f, ScenePosRotInfoList[1].x, ScenePosRotInfoList[1].y, 51f, 17.1f);
-
- GongShi2.F2Dto3D(ScenePosRotInfoList[0].x, ScenePosRotInfoList[0].y, GameManager.Instance.WebMapSize.y, GameManager.Instance.WebMapSize.x, ScenePosRotInfoList[1].x, ScenePosRotInfoList[1].y, DataManager.Instance.CurrentScene.length, DataManager.Instance.CurrentScene.width);
-
- // },0.03f,-1);
- }
- }
- }
- }
- }
- }
- public IEnumerator RequestUpload(string Url, string jsonString)
- {
- using (UnityWebRequest webRequest = new UnityWebRequest(Url, "POST"))
- {
- JsonData data = JsonMapper.ToObject(jsonString);
- JsonData d2 = new JsonData();
- d2["position"] = data;
- d2["id"] = ProjectID;
- d2["unity"] = false;
- byte[] bodyRaw = Encoding.UTF8.GetBytes(d2.ToJson());
- webRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
- webRequest.downloadHandler = new DownloadHandlerBuffer();
- webRequest.SetRequestHeader("Content-Type", "application/json;charset=utf-8");
- webRequest.SetRequestHeader("authorization", UserInfo.Instance.Token);
- foreach (var v in HttpTool.Instance.RequestHeader)
- {
- webRequest.SetRequestHeader(v.Key, v.Value);
- }
- yield return webRequest.SendWebRequest();
- if (webRequest.result == UnityWebRequest.Result.ProtocolError || webRequest.result == UnityWebRequest.Result.ConnectionError)
- {
- Debug.LogError(webRequest.downloadHandler.error);
- InstantiateCommand Command = new InstantiateCommand(
- InstantiateSystem.Instance.BlueObject.WarningPopUp,
- InstantiateSystem.Instance.BlueObject.NetErrorText);
- CommandSystem.Instance.Send(Command);
- }
- else
- {
- if (!string.IsNullOrWhiteSpace(webRequest.downloadHandler.text))
- {
- string message = webRequest.downloadHandler.text;
- JObject jobject = JObject.Parse(message);
- if (jobject["code"].ToString() == "200")
- {
- message = jobject["data"].ToString();
- if (!string.IsNullOrWhiteSpace(message))
- {
- List<ScenePosRotInfo> ScenePosRotInfoList = JsonConvert.DeserializeObject<List<ScenePosRotInfo>>(message);
- PosRot = ScenePosRotInfoList;
- }
- }
- }
- InstantiateCommand Command = new InstantiateCommand(
- InstantiateSystem.Instance.BlueObject.WarningPopUp,
- InstantiateSystem.Instance.BlueObject.SuccessText);
- CommandSystem.Instance.Send(Command);
- }
- }
- }
- }
|