1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System.Collections;
- using UnityEngine;
- using Blue;
- using UnityEngine.Networking;
- using Newtonsoft.Json;
- using System.Text;
- /// <summary>
- /// Immersal 点云定位服务
- /// </summary>
- public interface IImmersalLocationService : IService
- {
- void Set(int id,int projectId,bool location);
- }
- public class ImmersalLocationService : IImmersalLocationService
- {
- private string userInfoSetUrl;
- public void OnInit()
- {
- userInfoSetUrl = "https://api-fat3.ghz-tech.com/mr-navigator/v1/viewpoint/locationPoint";
- }
- public void Set(int id,int projectId,bool location)
- {
- CoroutineSystem.Instance.StartCoroutine(SetRequest(id,projectId,location));
- }
- private IEnumerator SetRequest(int id,int projectId,bool location)
- {
- using (UnityWebRequest webRequest = new UnityWebRequest(userInfoSetUrl, "POST"))
- {
- ImmersalLoaction ImmersalLoaction = new ImmersalLoaction();
- ImmersalLoaction.id = id;
- ImmersalLoaction.projectId = projectId;
- ImmersalLoaction.location = location;
- string jsonData = JsonConvert.SerializeObject(ImmersalLoaction);
- 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
- {
- Debug.LogError("Immersal上传:"+webRequest.downloadHandler.text);
- }
- }
- }
- }
- public class ImmersalLoaction
- {
- public int id{ get; set; }
- public int projectId{ get; set; }
- public bool location{ get; set; }
- }
|