PointFileGetUrlCommand.cs 3.3 KB

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