PointFileGetUrlCommand.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using Blue;
  2. using Newtonsoft.Json.Linq;
  3. using Newtonsoft.Json;
  4. using LitJson;
  5. using System.IO;
  6. using UnityEngine;
  7. using System.Collections.Generic;
  8. using System.Collections;
  9. /// <summary>
  10. /// 获取点云文件(json、bytes)的Url下载地址命令
  11. /// </summary>
  12. public class PointFileGetUrlCommand : ICommand
  13. {
  14. private string methodName = "/project/pointcloud";
  15. private int sceneID;
  16. private PointFileType fileType;
  17. /// <summary>
  18. /// 获取点云文件(json、bytes)的Url下载地址命令
  19. /// </summary>
  20. /// <param name="sceneId">场景ID</param>
  21. /// <param name="fileType">文件类型</param>
  22. public PointFileGetUrlCommand(int sceneId, PointFileType fileType)
  23. {
  24. this.sceneID = sceneId;
  25. this.fileType = fileType;
  26. }
  27. public void OnExcute()
  28. {
  29. this.GetService<IPointService>().GetPointFileDownloadUrl(methodName, sceneID.ToString(), fileType, GetPointFileUrlSuccess);
  30. }
  31. string PointName;
  32. private void GetPointFileUrlSuccess(string message)
  33. {
  34. Debug.Log(message);
  35. if (!string.IsNullOrWhiteSpace(message))
  36. {
  37. JObject jobject = JObject.Parse(message);
  38. if (jobject["code"].ToString() == "200")
  39. {
  40. Debug.Log("Hjj message====>"+ message);
  41. JsonData dataJ = JsonMapper.ToObject(message);
  42. string downLoadPath = "";
  43. if (fileType==PointFileType.bytes)
  44. {
  45. downLoadPath = dataJ["data"]["bytesFile"]["path"].ToString();
  46. }
  47. else
  48. {
  49. downLoadPath = dataJ["data"]["jsonFile"]["path"].ToString();
  50. }
  51. PointName = dataJ["data"]["bytesFile"]["name"].ToString() + "." + dataJ["data"]["bytesFile"]["ext"].ToString();
  52. // Debug.Log(" SetData " + updateTime);
  53. // PointFileData PointFile = JsonConvert.DeserializeObject<PointFileData>(message);
  54. // this.GetService<IPointService>().DownloadPointFile(PointFile.url, fileType);
  55. if(!string.IsNullOrWhiteSpace(downLoadPath))
  56. {
  57. DownLoadMaterial data = new DownLoadMaterial();
  58. data.downLoadPath = downLoadPath;
  59. data.localLoadPath = Application.persistentDataPath + "/Map Data/" + Path.GetFileName(downLoadPath);
  60. Debug.Log("DGJ byte " + data.downLoadPath);
  61. data.updataTime = 0;// GameManager.Instance.m_SceneValue.updateTime;
  62. data.type = "-1";
  63. MsgHandler.AddListener(downLoadPath, HandleMsg);
  64. DownloadResManager.Instance.DownLoad(data);
  65. }
  66. else
  67. {
  68. Debug.LogError("当前场景未上传点云文件 ");
  69. }
  70. }
  71. }
  72. }
  73. private void HandleMsg(Msg msg)
  74. {
  75. Debug.Log("DGJ GetPointFileUrlSuccess HandleMsg");
  76. if (msg.Value!=null)
  77. if (fileType == PointFileType.bytes)
  78. {
  79. GameManager.Instance.StartCoroutine(loadmapend((byte[])msg.Value));
  80. }
  81. // this.SendEvent(new LoadMapFileEvent() { fileName = PointName ,bytes = (byte[])msg.Value});
  82. }
  83. public static int mapct = 1000;
  84. public static byte[] nowBytes = new byte[0];
  85. public IEnumerator loadmapend(byte[] bytes)
  86. {
  87. mapct++;
  88. nowBytes = bytes;
  89. // GameManager.Instance.armap.renderMode = Immersal.AR.ARMap.RenderMode.EditorAndRuntime;
  90. GameManager.Instance.armap.renderMode = Immersal.AR.ARMap.RenderMode.DoNotRender;
  91. yield return GameManager.Instance.armap.LoadMap(bytes, mapct);
  92. GameManager.Instance.armap.enabled = true;
  93. this.SendCommand(new StartImmersalLocalizerCommand());
  94. }
  95. }