12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using Blue;
- using Newtonsoft.Json.Linq;
- using Newtonsoft.Json;
- using LitJson;
- using System.IO;
- using UnityEngine;
- /// <summary>
- /// 获取点云文件(json、bytes)的Url下载地址命令
- /// </summary>
- public class PointFileGetUrlCommand : ICommand
- {
- private string methodName = "/project/pointcloud";
- private int sceneID;
- private PointFileType fileType;
- /// <summary>
- /// 获取点云文件(json、bytes)的Url下载地址命令
- /// </summary>
- /// <param name="sceneId">场景ID</param>
- /// <param name="fileType">文件类型</param>
- public PointFileGetUrlCommand(int sceneId, PointFileType fileType)
- {
- this.sceneID = sceneId;
- this.fileType = fileType;
- }
- public void OnExcute()
- {
- this.GetService<IPointService>().GetPointFileDownloadUrl(methodName, sceneID.ToString(), fileType, GetPointFileUrlSuccess);
- }
- string PointName;
- private void GetPointFileUrlSuccess(string message)
- {
- Debug.Log(message);
- if (!string.IsNullOrWhiteSpace(message))
- {
- JObject jobject = JObject.Parse(message);
- if (jobject["code"].ToString() == "200")
- {
- Debug.Log("Hjj message====>"+ message);
- JsonData dataJ = JsonMapper.ToObject(message);
- string downLoadPath = "";
- if (fileType==PointFileType.bytes)
- {
- downLoadPath = dataJ["data"]["bytesFile"]["path"].ToString();
- }
- else
- {
- downLoadPath = dataJ["data"]["jsonFile"]["path"].ToString();
- }
- PointName = dataJ["data"]["bytesFile"]["name"].ToString() + "." + dataJ["data"]["bytesFile"]["ext"].ToString();
-
- // Debug.Log(" SetData " + updateTime);
- // PointFileData PointFile = JsonConvert.DeserializeObject<PointFileData>(message);
- // this.GetService<IPointService>().DownloadPointFile(PointFile.url, fileType);
- if(!string.IsNullOrWhiteSpace(downLoadPath))
- {
- DownLoadMaterial data = new DownLoadMaterial();
- data.downLoadPath = downLoadPath;
- data.localLoadPath = Application.persistentDataPath + "/Map Data/" + Path.GetFileName(downLoadPath);
- Debug.Log("DGJ byte " + data.downLoadPath);
- data.updataTime = 0;// GameManager.Instance.m_SceneValue.updateTime;
- data.type = "-1";
- MsgHandler.AddListener(downLoadPath, HandleMsg);
- DownloadResManager.Instance.DownLoad(data);
- }
- else
- {
- Debug.LogError("当前场景未上传点云文件 ");
- }
-
- }
- }
- }
- private void HandleMsg(Msg msg)
- {
- Debug.Log("DGJ GetPointFileUrlSuccess HandleMsg");
- if(msg.Value!=null)
- if (fileType == PointFileType.bytes)
- this.SendEvent(new LoadMapFileEvent() { fileName = PointName ,bytes = (byte[])msg.Value});
- }
- }
|