123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using QFramework;
- using LitJson;
- using Newtonsoft.Json.Linq;
- using UnityEngine.UI;
- using Newtonsoft.Json;
- public class SelectScene : MonoSingleton<SelectScene>
- {
- public Text text;
- public Text error;
- public List<ScenesPage> listScenesPage;
- public Transform panel;
- public RectTransform content;
- public GameObject SelectBtn;
- public int selectSceneId;
- private int snInfoNum = 0;
- public void Show(List<ScenesPage> listScenesPage)
- {
- this.listScenesPage = listScenesPage;
- for (int i = 0; i < listScenesPage.Count; i++)
- {
- SendInit send = new SendInit();
- send.sn = DeviceSN.Instance.SendSerialBy16();
- send.projectId = listScenesPage[i].id;
- string jsonString = JsonMapper.ToJson(send);
- HttpTool.Instance.PostTest("/client/snInfo", jsonString, SnInfoCallBack);
- }
- }
- public void Select(int id)
- {
- selectSceneId = id;
- error.text = "";
- }
- public void Confirm()
- {
- // 选择场景
- SendInit send = new SendInit();
- send.sn = DeviceSN.Instance.SendSerialBy16();
- error.text = "";
- text.text = send.sn;
- send.projectId = selectSceneId;
- string jsonString = JsonMapper.ToJson(send);
- HttpTool.Instance.PostTest("/sn/init", jsonString, InitSceneValueCallBack);
- }
- public void VerticalMove(bool state)
- {
- if (state)
- {
- content.anchoredPosition += new Vector2(253, 0);
- }
- else
- {
- content.anchoredPosition -= new Vector2(253, 0);
- }
- }
- private void InitSceneValueCallBack(string message)
- {
- GameManager.Instance.text2.text = " 获取场景信息";
- JObject jObject = JObject.Parse(message);
- message = jObject["data"].ToString();
-
- SceneValue scene = JsonMapper.ToObject<SceneValue>(message);
- // Debug.Log(message);
- if (scene.listSpoit.IsNull() || scene.listSpoit.Count == 0)
- {
- // 当前场景未创建景点
- error.text = "该场景未创建景点";
- return;
- }
- if (scene.vuforiaDat == scene.vuforiaXML || scene.vuforiaXML.IsNullOrEmpty() || scene.vuforiaDat.IsNullOrEmpty())
- {
- // 当前场景没有识别文件
- error.text = "该场景没有识别文件";
- return;
- }
-
- try
- {
- GameManager.Instance.scene = GameManager.Instance.ProcesSceneValueJsonData(scene);
- message = JsonConvert.SerializeObject(GameManager.Instance.scene);
- Debug.Log(message);
- text.text = message;
- GameManager.Instance.text2.text = " 场景信息获取结束";
- Debug.Log(scene.listSpoit.Count);
- HttpSocket.Instance.projectid = selectSceneId;
- HttpSocket.Instance.isOpen = true;
- panel.gameObject.SetActive(false);
- }
- catch (System.Exception e)
- {
- ErrorLogPanel.Instance.Show(" 处理场景数据出现错误 " + e.Message);
- }
- }
- private void SnInfoCallBack(string message)
- {
- Debug.Log(message);
- JObject jObject = JObject.Parse(message);
- message = jObject["code"].ToString();
- if (message == "200")
- snInfoNum++;
- if (snInfoNum == listScenesPage.Count)
- {
- LoginPanel.Instance.gameObject.SetActive(false);
- listScenesPage.ForEach(item =>
- {
- GameObject btn = GameObject.Instantiate(SelectBtn, content);
- btn.GetComponent<SelectSceneBtn>().Init(item);
- btn.SetActive(true);
- });
- selectSceneId = listScenesPage[listScenesPage.Count - 1].id;
- content.sizeDelta = new Vector2((listScenesPage.Count) * 300, 0);
- panel.gameObject.SetActive(true);
- }
- }
- }
|