SelectScene.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using QFramework;
  5. using LitJson;
  6. using Newtonsoft.Json.Linq;
  7. using UnityEngine.UI;
  8. using Newtonsoft.Json;
  9. public class SelectScene : MonoSingleton<SelectScene>
  10. {
  11. public Text text;
  12. public Text error;
  13. public List<ScenesPage> listScenesPage;
  14. public Transform panel;
  15. public RectTransform content;
  16. public GameObject SelectBtn;
  17. public int selectSceneId;
  18. private int snInfoNum = 0;
  19. public void Show(List<ScenesPage> listScenesPage)
  20. {
  21. this.listScenesPage = listScenesPage;
  22. for (int i = 0; i < listScenesPage.Count; i++)
  23. {
  24. SendInit send = new SendInit();
  25. send.sn = DeviceSN.Instance.SendSerialBy16();
  26. send.projectId = listScenesPage[i].id;
  27. string jsonString = JsonMapper.ToJson(send);
  28. HttpTool.Instance.PostTest("/client/snInfo", jsonString, SnInfoCallBack);
  29. }
  30. }
  31. public void Select(int id)
  32. {
  33. selectSceneId = id;
  34. error.text = "";
  35. }
  36. public void Confirm()
  37. {
  38. // 选择场景
  39. SendInit send = new SendInit();
  40. send.sn = DeviceSN.Instance.SendSerialBy16();
  41. error.text = "";
  42. text.text = send.sn;
  43. send.projectId = selectSceneId;
  44. string jsonString = JsonMapper.ToJson(send);
  45. HttpTool.Instance.PostTest("/sn/init", jsonString, InitSceneValueCallBack);
  46. }
  47. public void VerticalMove(bool state)
  48. {
  49. if (state)
  50. {
  51. content.anchoredPosition += new Vector2(253, 0);
  52. }
  53. else
  54. {
  55. content.anchoredPosition -= new Vector2(253, 0);
  56. }
  57. }
  58. private void InitSceneValueCallBack(string message)
  59. {
  60. GameManager.Instance.text2.text = " 获取场景信息";
  61. JObject jObject = JObject.Parse(message);
  62. message = jObject["data"].ToString();
  63. SceneValue scene = JsonMapper.ToObject<SceneValue>(message);
  64. // Debug.Log(message);
  65. if (scene.listSpoit.IsNull() || scene.listSpoit.Count == 0)
  66. {
  67. // 当前场景未创建景点
  68. error.text = "该场景未创建景点";
  69. return;
  70. }
  71. if (scene.vuforiaDat == scene.vuforiaXML || scene.vuforiaXML.IsNullOrEmpty() || scene.vuforiaDat.IsNullOrEmpty())
  72. {
  73. // 当前场景没有识别文件
  74. error.text = "该场景没有识别文件";
  75. return;
  76. }
  77. try
  78. {
  79. GameManager.Instance.scene = GameManager.Instance.ProcesSceneValueJsonData(scene);
  80. message = JsonConvert.SerializeObject(GameManager.Instance.scene);
  81. Debug.Log(message);
  82. text.text = message;
  83. GameManager.Instance.text2.text = " 场景信息获取结束";
  84. Debug.Log(scene.listSpoit.Count);
  85. HttpSocket.Instance.projectid = selectSceneId;
  86. HttpSocket.Instance.isOpen = true;
  87. panel.gameObject.SetActive(false);
  88. }
  89. catch (System.Exception e)
  90. {
  91. ErrorLogPanel.Instance.Show(" 处理场景数据出现错误 " + e.Message);
  92. }
  93. }
  94. private void SnInfoCallBack(string message)
  95. {
  96. Debug.Log(message);
  97. JObject jObject = JObject.Parse(message);
  98. message = jObject["code"].ToString();
  99. if (message == "200")
  100. snInfoNum++;
  101. if (snInfoNum == listScenesPage.Count)
  102. {
  103. LoginPanel.Instance.gameObject.SetActive(false);
  104. listScenesPage.ForEach(item =>
  105. {
  106. GameObject btn = GameObject.Instantiate(SelectBtn, content);
  107. btn.GetComponent<SelectSceneBtn>().Init(item);
  108. btn.SetActive(true);
  109. });
  110. selectSceneId = listScenesPage[listScenesPage.Count - 1].id;
  111. content.sizeDelta = new Vector2((listScenesPage.Count) * 300, 0);
  112. panel.gameObject.SetActive(true);
  113. }
  114. }
  115. }