using Blue;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using LitJson;
using System.IO;
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
///
/// 获取点云文件(json、bytes)的Url下载地址命令
///
public class PointFileGetUrlCommand : ICommand
{
private string methodName = "/project/pointcloud";
private int sceneID;
private PointFileType fileType;
///
/// 获取点云文件(json、bytes)的Url下载地址命令
///
/// 场景ID
/// 文件类型
public PointFileGetUrlCommand(int sceneId, PointFileType fileType)
{
this.sceneID = sceneId;
this.fileType = fileType;
}
public void OnExcute()
{
this.GetService().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(message);
// this.GetService().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)
{
GameManager.Instance.StartCoroutine(loadmapend((byte[])msg.Value));
}
// this.SendEvent(new LoadMapFileEvent() { fileName = PointName ,bytes = (byte[])msg.Value});
}
public static int mapct = 1000;
public static byte[] nowBytes = new byte[0];
public IEnumerator loadmapend(byte[] bytes)
{
mapct++;
nowBytes = bytes;
// GameManager.Instance.armap.renderMode = Immersal.AR.ARMap.RenderMode.EditorAndRuntime;
GameManager.Instance.armap.renderMode = Immersal.AR.ARMap.RenderMode.DoNotRender;
yield return GameManager.Instance.armap.LoadMap(bytes, mapct);
GameManager.Instance.armap.enabled = true;
this.SendCommand(new StartImmersalLocalizerCommand());
}
}