IImmersalLocationService.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Collections;
  2. using UnityEngine;
  3. using Blue;
  4. using UnityEngine.Networking;
  5. using Newtonsoft.Json;
  6. using System.Text;
  7. /// <summary>
  8. /// Immersal 点云定位服务
  9. /// </summary>
  10. public interface IImmersalLocationService : IService
  11. {
  12. void Set(int id,int projectId,bool location);
  13. }
  14. public class ImmersalLocationService : IImmersalLocationService
  15. {
  16. private string userInfoSetUrl;
  17. public void OnInit()
  18. {
  19. userInfoSetUrl = "https://api-fat3.ghz-tech.com/mr-navigator/v1/viewpoint/locationPoint";
  20. }
  21. public void Set(int id,int projectId,bool location)
  22. {
  23. CoroutineSystem.Instance.StartCoroutine(SetRequest(id,projectId,location));
  24. }
  25. private IEnumerator SetRequest(int id,int projectId,bool location)
  26. {
  27. using (UnityWebRequest webRequest = new UnityWebRequest(userInfoSetUrl, "POST"))
  28. {
  29. ImmersalLoaction ImmersalLoaction = new ImmersalLoaction();
  30. ImmersalLoaction.id = id;
  31. ImmersalLoaction.projectId = projectId;
  32. ImmersalLoaction.location = location;
  33. string jsonData = JsonConvert.SerializeObject(ImmersalLoaction);
  34. Debug.LogError("JsonData"+jsonData);
  35. byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonData);
  36. webRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
  37. webRequest.downloadHandler = new DownloadHandlerBuffer();
  38. webRequest.SetRequestHeader("Content-Type", "application/json;charset=utf-8");
  39. webRequest.SetRequestHeader("authorization", HttpTool.Instance.Token);
  40. yield return webRequest.SendWebRequest();
  41. if (webRequest.result== UnityWebRequest.Result.ProtocolError || webRequest.result == UnityWebRequest.Result.ConnectionError)
  42. Debug.LogError("UnityWebRequest Error:"+webRequest.downloadHandler.text);
  43. else
  44. {
  45. Debug.LogError("Immersal上传:"+webRequest.downloadHandler.text);
  46. }
  47. }
  48. }
  49. }
  50. public class ImmersalLoaction
  51. {
  52. public int id{ get; set; }
  53. public int projectId{ get; set; }
  54. public bool location{ get; set; }
  55. }