123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410 |
- using LitJson;
- using Newtonsoft.Json.Linq;
- using SC.XR.Unity;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using UnityEngine.UI;
- using Newtonsoft.Json;
- using Blue;
- using UnityEngine.Networking;
- using XRTool.Util;
- public class SceneChoose : BaseUI
- {
- public CustomHorizintalScrollView view;
- private Button m_LeftBtn;
- private Button m_RightBtn;
- private Button m_OkBtn;
- private GameObject m_SceneItem;
- private Transform m_ScenePanel;
- /// <summary>
- /// 场景选择面板中确认的场景
- /// </summary>
- private SceneValue m_CurrentData;
- private List<SChooseItem> m_Items;
- private CarouselImage m_CarImage;
- private List<SceneValue> m_SceneData;
- public static int Sid = -1;
- protected override void OnAwake()
- {
- base.OnAwake();
- m_SceneData = new List<SceneValue>();
- m_Items = new List<SChooseItem>();
- m_CurrentData = null;
- m_LeftBtn = CacheTransform.Find("Left").GetComponent<Button>();
- m_RightBtn = CacheTransform.Find("Right").GetComponent<Button>();
- m_OkBtn = CacheTransform.Find("OK").GetComponent<Button>();
- m_SceneItem = CacheTransform.Find("SceneChooseItem").gameObject;
- m_ScenePanel = CacheTransform.Find("ScenePanel");
- m_ScenePanel.GetComponent<RectTransform>().sizeDelta = new Vector2(400, 150);
- Debug.Log("CustomHorizintalScrollView " + view.name);
- //m_LeftBtn.onClick.AddListener(ONClickLeftBtn);
- //m_RightBtn.onClick.AddListener(ONClickRightBtn);
- //m_OkBtn.onClick.AddListener(OnClickOKBtn);
- }
- #region UI监听事件
- private void ONClickLeftBtn()
- {
- if (m_CarImage != null)
- {
- m_CarImage.MoveToIndex(m_CarImage.CurrentIndex + 1);
- }
- }
- private void ONClickRightBtn()
- {
- if (m_CarImage != null)
- {
- m_CarImage.MoveToIndex(m_CarImage.CurrentIndex - 1);
- }
- }
- public void OnClickOKBtn(SceneValue m_CurrentData)
- {
- // GetComponent<RectTransform>().position = new Vector3(1000000,42.1f,0);
- this.m_CurrentData = m_CurrentData;
- MQTTClient.Instance.SubscribeScene(this.m_CurrentData.id.ToString());
- Sid = this.m_CurrentData.id;
- //根据场景数据,下载资源
- Debug.Log("选择的场景为:" + m_CurrentData.name);
- SendSceneDetail detail = new SendSceneDetail();
- detail.id = m_CurrentData.id;
- string str = JsonConvert.SerializeObject(detail);
- this.GetModel<ISceneModel>().sceneID = m_CurrentData.id;
- this.SendCommand(new PointFileGetUrlCommand(detail.id, PointFileType.json));
- this.SendCommand(new PointFileGetUrlCommand(detail.id, PointFileType.bytes));
- this.SendCommand(new PointPosRotDownloadCommand(detail.id));
- this.SendCommand(new MinMapGetSetCommand());
- HttpTool.Instance.PostTest("/project/detail", str, (mes) =>
- {
- if (mes == "UnityWebRequest Error") return;
- JObject jObject = JObject.Parse(mes);
- if (jObject["code"].ToString() == "200")
- {
- mes = jObject["data"].ToString();
- SceneValue scene = JsonConvert.DeserializeObject<SceneValue>(mes);
- Debug.Log("scene.backgroundImages===>" + mes);
- Debug.Log("scene.backgroundImages===>"+ scene.backgroundImages.Count);
- GameManager.Instance.MapPicUrl = scene.backgroundImages[0].base64;
- GameManager.Instance.GetMinMap(scene, (bool back) =>
- {
- Debug.Log("scene.backgroundImages===>back"+ back);
- if (back)
- {
- GetSNInit();
- this.SendCommand(new GetReferencePosCommand(detail.id));
- }
- else
- {
- UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), scene+" 通讯出错 请尝试重启应用");
- m_OkBtn.interactable = true;
- }
- } );
- }
- else
- {
- UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), "/project/detail 通讯出错 请尝试重启应用");
- m_OkBtn.interactable = true;
- }
- });
- /*
- if (m_CurrentData != null)
- {
- }
- else
- {
- ///Module_Notice.getInstance.SetNoticeInfo("未选择导览场景", "请先勾选要进入的场景", NoticeType.Normal, 1.7f);
- //Module_Notice.getInstance._Follower.WindowAnchor = TextAnchor.UpperCenter;
- //Module_Notice.getInstance.StartNotice(3f);
- // this.SendCommand(new InstantiateCommand(InstantiateSystem.Instance.BlueObject.WarningPopUp));
- UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), "请选择场景");
- TimerMgr.Instance.CreateTimer(()=> {
- UIManager.Instance.HideUI(UINameConfig.LoadingPanel);
- m_OkBtn.interactable = true;
- },1f);
- }
- */
- }
- private IEnumerator LoadCRT()
- {
- #if UNITY_ANDROID
- string streamingAssetsPath = "jar:file://" + Application.dataPath + "!/assets/";
- string fileName = "";
- string filePath = Path.Combine(streamingAssetsPath, fileName);
- Debug.Log("DGJ ===> filePath " + filePath);
- using (WWW www = new WWW(filePath))
- {
- yield return www;
- byte[] bytes = www.bytes;
- // MQTTClient.Instance.bytes = bytes;
- Debug.Log("DGJ ===> bytes " + bytes.Length);
- }
- #endif
- }
- private void GetSNInit()
- {
- // 选择场景
- SendInit send = new SendInit();
- send.sn = SendSN.GetSN();
- //send.sn = API_GSXR_Slam.SlamManager.plugin.SN;
- send.projectId = m_CurrentData.id;
- string jsonString = JsonConvert.SerializeObject(send);
- UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.sceneChoose);
- //通过SN获取场景数据
- HttpTool.Instance.PostTest("/sn/init", jsonString, (message) =>
- {
- if (message == "UnityWebRequest Error") return;
- Debug.Log("SN:" + send.sn);
- Debug.Log("通过SN获取场景数据:" + message);
- if (!string.IsNullOrWhiteSpace(message))
- {
- Debug.Log("Hjj 当前选择场景数据 1: " + message);
- JsonData jobject = JsonMapper.ToObject(message);
- if (!jobject.Keys.Contains("code") ||jobject["code"].ToJson() == "400")
- {
- UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), "/sn/init 通讯出错 请尝试重启应用");
- }
- else
- {
- message = jobject["data"]["info"].ToJson();
- SceneValue scene = JsonConvert.DeserializeObject<SceneValue>(message);
- DataManager.Instance.CurrentScene = scene;
- DataManager.Instance.ProjectID = m_CurrentData.id;
- UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.createScene);
- StartCoroutine(GetSpoitValueDetail(scene));
- }
- }
- else
- {
- UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), "/sn/init 通讯出错 请尝试重启应用");
- }
- });
- }
- private IEnumerator GetSpoitValueDetail(SceneValue scene)
- {
- var spoits = scene.listSpoit;
- UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), "正在获取服务器景点信息");
- for (int i = 0; i < spoits.Count; i++)
- {
- //通过ID获取场景详情
- SendSceneDetail detail = new SendSceneDetail();
- detail.id = spoits[i].id;
- string jsonString = JsonConvert.SerializeObject(detail);
- yield return StartCoroutine(HttpTool.Instance.SendHttp("/viewpoint/detail", jsonString, (message) =>
- {
- //Debug.Log("当前选择场景数据: " + message);
- JObject jObject = JObject.Parse(message);
- if (jObject["code"].ToString() == "200")
- {
- message = jObject["data"].ToString();
- Debug.Log("Hjj jObjectjObjectjObject " + message);
- SpoitValueDetail spoit = JsonConvert.DeserializeObject<SpoitValueDetail>(message);
- if(!GameManager.Instance.SpoitsValueDetail.ContainsKey(spoit.id))
- GameManager.Instance.SpoitsValueDetail.Add(spoit.id, spoit);
- else
- {
- GameManager.Instance.SpoitsValueDetail[spoit.id] = spoit;
- }
- }else
- {
- UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), "/viewpoint/detail 通讯出错 请尝试重启应用");
- }
- }));
- }
- Debug.Log("Hjj scene.vuforiaXML" + scene.vuforiaXML);
- if(UserInfo.Instance.is20)
- {
- string xmlName = Path.GetFileName(scene.vuforiaXML);
- if (xmlName != null)
- {
- xmlName = xmlName.Substring(0, xmlName.Length - 4);
- AppConfigConst.IMAGE_TARGET_FILE_NAME = xmlName;
- }
- if (scene.vuforiaXML != null)
- {
- if(Directory.Exists(Application.persistentDataPath + "/StreamingAssets"))
- Directory.Delete(Application.persistentDataPath + "/StreamingAssets");
- //DownloadData xml = new DownloadData();
- //string filename = Path.GetFileName(scene.vuforiaXML);
- //xml.name = filename;
- //xml.type = 8;
- //xml.downloadPath = scene.vuforiaXML;
- //xml.updateTime = (int)scene.updateTime;
- //xml.localSavePath = Application.persistentDataPath + "/StreamingAssets/Vuforia/" + filename;
- //DownloadManager.Instance.AddDownloadData(xml);
- //DownloadData dat = new DownloadData();
- //string filename2 = Path.GetFileName(scene.vuforiaDat);
- //dat.name = filename2;
- //dat.type = 8;
- //dat.downloadPath = scene.vuforiaDat;
- //dat.updateTime = (int)scene.updateTime;
- //dat.localSavePath = Application.persistentDataPath + "/StreamingAssets/Vuforia/" + filename2;
- //DownloadManager.Instance.AddDownloadData(dat);
- DownLoadMaterial xml = new DownLoadMaterial();
- string filename = Path.GetFileName(scene.vuforiaXML);
- // xml.name = filename;
- xml.type = "-2";
- xml.downLoadPath = scene.vuforiaXML;
- xml.updataTime = scene.updateTime;
- xml.localLoadPath = Application.persistentDataPath + "/StreamingAssets/Vuforia/GHZVuforia." + filename.Split('.')[1];
- // DownloadManager.Instance.AddDownloadData(xml);
- DownloadResManager.Instance.DownLoad(xml);
- DownLoadMaterial dat = new DownLoadMaterial();
- string filename2 = Path.GetFileName(scene.vuforiaDat);
- //dat.name = filename2;
- dat.type = "-2";
- dat.downLoadPath = scene.vuforiaDat;
- dat.updataTime = (int)scene.updateTime;
- dat.localLoadPath = Application.persistentDataPath + "/StreamingAssets/Vuforia/GHZVuforia." + filename2.Split('.')[1];
- DownloadResManager.Instance.DownLoad(dat);
- }
-
- }
- yield return new WaitForSeconds(1f);
- while(GameManager.Instance.isShowDownTip)
- {
- yield return null;
- }
- Debug.Log("创建场景123");
- //创建场景
- StartCoroutine(GameManager.Instance.CreateScene(scene));
- Hide();
-
- }
- public RectTransform scrollview;
- private void UpdateSceneItem()
- {
- Debug.Log("UpdateSceneItem1");
- if (m_SceneData == null)
- {
- return;
- }
- ClearItem();
- Debug.Log("UpdateSceneItem2");
- for (int i = 0; i < m_SceneData.Count; i++)
- {
- Debug.Log("UpdateSceneItem21");
- var obj = Instantiate(m_SceneItem);
- Debug.Log("UpdateSceneItem22");
- obj.transform.SetParent(m_ScenePanel);
- var item = obj.GetComponent<SChooseItem>();
- obj.gameObject.SetActive(true);
- obj.transform.localScale = new Vector3(1, 1, 1);
- obj.transform.localEulerAngles = Vector3.zero;
- item.OnSelectScene += OnClickSceneItem;
- item.SceneData = m_SceneData[i];
- m_Items.Add(item);
- }
- switch(m_SceneData.Count)
- {
- case 1:
- scrollview.sizeDelta = new Vector2(200,266);
- break;
- case 2:
- scrollview.sizeDelta = new Vector2(500, 266);
- break;
- }
- Debug.Log("UpdateSceneItem3");
- if (m_CarImage == null)
- {
- m_CarImage = m_ScenePanel.gameObject.AddComponent<CarouselImage>();
- }
- Debug.Log("UpdateSceneItem4");
- Debug.Log("CustomHorizintalScrollView " + view.name);
- view.Init(m_SceneData,this);
- Debug.Log("UpdateSceneItem6");
- m_CarImage.mCellSize = new Vector2(400, 150);
- m_CarImage.mSpacing = new Vector2(0, 0);
- m_CarImage.mAutoLoop = false;
- m_CarImage.mDrag = true;
- m_CarImage.mLoopSpaceTime = 5f;
- m_CarImage.resizeChildren();
- Debug.Log("UpdateSceneItem5");
- }
- private void OnClickSceneItem(SceneValue item, bool b)
- {
- m_CurrentData = b ? item : null;
- }
- #endregion
- protected override void OnInit()
- {
- base.OnInit();
- }
- protected override void OnShow(object param)
- {
- base.OnShow(param);
- m_SceneData = (List<SceneValue>)param;
- UpdateSceneItem();
- }
- protected override void OnHide()
- {
- base.OnHide();
- }
- /// <summary>
- /// 清除所有场景信息
- /// </summary>
- private void ClearItem()
- {
- while (m_Items.Count > 0)
- {
- var item = m_Items[0];
- m_Items.RemoveAt(0);
- Destroy(item.gameObject);
- }
- }
- }
|