SelectScene.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. public class SelectScene : MonoSingleton<SelectScene>
  9. {
  10. public Text text;
  11. public Text error;
  12. public List<ScenesPage> listScenesPage;
  13. public Transform panel;
  14. public RectTransform content;
  15. public GameObject SelectBtn;
  16. public int selectSceneId;
  17. private int snInfoNum = 0;
  18. public void Show(List<ScenesPage> listScenesPage)
  19. {
  20. this.listScenesPage = listScenesPage;
  21. for (int i = 0; i < listScenesPage.Count; i++)
  22. {
  23. SendInit send = new SendInit();
  24. send.sn = DeviceSN.Instance.SendSerialBy16();
  25. send.projectId = listScenesPage[i].id;
  26. string jsonString = JsonMapper.ToJson(send);
  27. HttpTool.Instance.PostTest("/client/snInfo", jsonString, SnInfoCallBack);
  28. }
  29. }
  30. public void Select(int id)
  31. {
  32. selectSceneId = id;
  33. error.text = "";
  34. }
  35. public void Confirm()
  36. {
  37. // 选择场景
  38. SendInit send = new SendInit();
  39. send.sn = DeviceSN.Instance.SendSerialBy16();
  40. error.text = "";
  41. text.text = send.sn;
  42. send.projectId = selectSceneId;
  43. string jsonString = JsonMapper.ToJson(send);
  44. HttpTool.Instance.PostTest("/sn/init", jsonString, InitSceneValueCallBack);
  45. }
  46. public void VerticalMove(bool state)
  47. {
  48. if (state)
  49. {
  50. content.anchoredPosition += new Vector2(253, 0);
  51. }
  52. else
  53. {
  54. content.anchoredPosition -= new Vector2(253, 0);
  55. }
  56. }
  57. private void InitSceneValueCallBack(string message)
  58. {
  59. GameManager.Instance.text2.text = " 获取场景信息";
  60. JObject jObject = JObject.Parse(message);
  61. message = jObject["data"].ToString();
  62. Debug.Log(message);
  63. GameManager.Instance.text2.text = message;
  64. SceneValue scene = JsonMapper.ToObject<SceneValue>(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. text.text = message;
  81. GameManager.Instance.text2.text = " 场景信息获取结束";
  82. GameManager.Instance.text2.text = message;
  83. Debug.Log(scene.listSpoit.Count);
  84. HttpSocket.Instance.projectid = selectSceneId;
  85. HttpSocket.Instance.isOpen = true;
  86. panel.gameObject.SetActive(false);
  87. }
  88. catch (System.Exception e)
  89. {
  90. ErrorLogPanel.Instance.Show(" 处理场景数据出现错误 " + e.Message);
  91. }
  92. }
  93. private void SnInfoCallBack(string message)
  94. {
  95. Debug.Log(" @@@ "+ message);
  96. JObject jObject = JObject.Parse(message);
  97. message = jObject["code"].ToString();
  98. if (message == "200")
  99. snInfoNum++;
  100. if (snInfoNum == listScenesPage.Count)
  101. {
  102. LoginPanel.Instance.gameObject.SetActive(false);
  103. listScenesPage.ForEach(item =>
  104. {
  105. GameObject btn = GameObject.Instantiate(SelectBtn, content);
  106. btn.GetComponent<SelectSceneBtn>().Init(item);
  107. btn.SetActive(true);
  108. });
  109. selectSceneId = listScenesPage[listScenesPage.Count - 1].id;
  110. content.sizeDelta = new Vector2((listScenesPage.Count) * 300, 0);
  111. panel.gameObject.SetActive(true);
  112. }
  113. }
  114. }