SettingPanel.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System;
  6. using SC.XR.Unity;
  7. using Blue;
  8. using LitJson;
  9. using Immersal.AR;
  10. using XRTool.Util;
  11. public class SettingPanel : AbstractController
  12. {
  13. public Text spMRtext;
  14. public Toggle MinMap;
  15. public Toggle NoMinMap;
  16. public Toggle DingWei;
  17. public Toggle feiDingWei;
  18. public Toggle LuJIng;
  19. public Toggle NoLuJIng;
  20. public Transform ChooseLine;
  21. public Toggle LineItem;
  22. public Transform LineItemParent;
  23. public Button SaveData;
  24. [SerializeField, Tooltip("小地图信息")]
  25. private MinMap m_MinMap;
  26. [SerializeField, Tooltip("路径控制器")]
  27. private RouteCtr m_RouteCtr;
  28. private List<Toggle> Lines;
  29. SpoitValue nowsp;
  30. public static Dictionary<int, bool> dingweilist = new Dictionary<int, bool>();
  31. private void Awake()
  32. {
  33. Lines = new List<Toggle>();
  34. SaveData.onClick.AddListener(OnClickSaveData);
  35. MinMap.onValueChanged.AddListener(OnMinMapValueChange);
  36. LuJIng.onValueChanged.AddListener(OnLuJIngValueChange);
  37. DingWei.onValueChanged.AddListener(DingWeiValueChange);
  38. setMsg(null);
  39. }
  40. private void DingWeiValueChange(bool arg0)
  41. {
  42. if(nowsp!=null)
  43. {
  44. if (dingweilist.ContainsKey(nowsp.id))
  45. {
  46. dingweilist[nowsp.id] = arg0;
  47. }
  48. else
  49. {
  50. dingweilist.Add(nowsp.id,arg0);
  51. }
  52. JsonData data = new JsonData();
  53. data["id"] = nowsp.id;
  54. data["projectId"] = SceneChoose.Sid;
  55. data["location"] = arg0;
  56. HttpTool.Instance.Post("/viewpoint/locationPoint", data.ToJson(), (string str) => { });
  57. }
  58. }
  59. private void OnEnable()
  60. {
  61. MinMap.interactable = false;
  62. NoMinMap.interactable = false;
  63. HttpTool.Instance.Get("/user/getUserInfo", (string str) =>
  64. {
  65. MinMap.interactable = true;
  66. NoMinMap.interactable = true;
  67. JsonData data = JsonMapper.ToObject(str);
  68. if (data["data"]["minMap"].ToString() == "0")
  69. {
  70. NoMinMap.isOn = true;
  71. m_MinMap.gameObject.SetActive(false);
  72. }
  73. else
  74. {
  75. MinMap.isOn = true;
  76. m_MinMap.gameObject.SetActive(true);
  77. }
  78. });
  79. // HttpTool.Instance.Post("/viewpoint/locationPoint", data.ToJson(), (string str) => { });
  80. // MinMap.isOn = this.GetService<IMinMapService>().setMinMap == 1 ? true : false;
  81. }
  82. public void setMsg(SpoitValue sv)
  83. {
  84. nowsp = sv;
  85. if (sv!=null)
  86. {
  87. feiDingWei.gameObject.SetActive(true);
  88. DingWei.gameObject.SetActive(true);
  89. spMRtext.text = sv.name;
  90. if (dingweilist.ContainsKey(nowsp.id))
  91. {
  92. if(dingweilist[nowsp.id])
  93. {
  94. XRLocalizer.Instance.gameObject.SetActive(true);
  95. DingWei.isOn = true;
  96. }
  97. else
  98. {
  99. if (ARSpace.isFind)
  100. {
  101. XRLocalizer.Instance.gameObject.SetActive(false);
  102. }
  103. feiDingWei.isOn = true;
  104. }
  105. }
  106. else
  107. {
  108. if(sv.location)
  109. {
  110. dingweilist.Add(nowsp.id,true);
  111. XRLocalizer.Instance.gameObject.SetActive(true);
  112. DingWei.isOn = true;
  113. }
  114. else
  115. {
  116. if (ARSpace.isFind)
  117. {
  118. XRLocalizer.Instance.gameObject.SetActive(false);
  119. }
  120. feiDingWei.isOn = true;
  121. }
  122. }
  123. }
  124. else
  125. {
  126. spMRtext.text = "----";
  127. feiDingWei.isOn = false;
  128. feiDingWei.gameObject.SetActive(false);
  129. DingWei.gameObject.SetActive(false);
  130. //if(ARSpace.isFind)
  131. //{
  132. XRLocalizer.Instance.gameObject.SetActive(true);
  133. //}
  134. }
  135. }
  136. public void Init()
  137. {
  138. CreateLines();
  139. MinMap.isOn = true;
  140. m_MinMap.gameObject.SetActive(true);
  141. LuJIng.isOn = true;
  142. if (Lines.Count > 0)
  143. {
  144. Lines[0].isOn = true;
  145. }
  146. gameObject.SetActive(false);
  147. }
  148. private void OnMinMapValueChange(bool ison)
  149. {
  150. //Debug.Log(data);
  151. JsonData data = new JsonData();
  152. data["minMap"] = ison?1:0;
  153. HttpTool.Instance.Post("/user/settings", data.ToJson(), (string str)=> { });
  154. m_MinMap.gameObject.SetActive(ison);
  155. }
  156. private void OnLuJIngValueChange(bool ison)
  157. {
  158. m_RouteCtr.gameObject.SetActive(ison);
  159. for (int i = 0; i < Lines.Count; i++)
  160. {
  161. Lines[i].interactable = ison;
  162. }
  163. }
  164. private void CreateLines()
  165. {
  166. var lines = m_RouteCtr.List_route;
  167. for (int i = 0; i < lines.Count; i++)
  168. {
  169. Toggle obj = Instantiate(LineItem, LineItemParent);
  170. obj.isOn = false;
  171. obj.transform.Find("Label").GetComponent<Text>().text = lines[i].name;
  172. var item = obj.gameObject.AddComponent<LuJingItem>();
  173. item.OnToggleSelect += OnCLickToggle;
  174. obj.gameObject.SetActive(true);
  175. Lines.Add(obj);
  176. }
  177. }
  178. private void OnCLickToggle(int index, bool ison)
  179. {
  180. m_RouteCtr.SettingLuJing(index, ison);
  181. m_MinMap.SetRoute(index, ison);
  182. }
  183. private void OnClickSaveData()
  184. {
  185. this.SendCommand(new MinMapGetSetCommand(m_MinMap.gameObject.activeSelf ? 1 : 0));
  186. // DataManager.Instance.SaveSpoits();
  187. GameManager.Instance.StartCoroutine(UIEditorPanel.Instance.SetSpoitInfo());
  188. DataManager.Instance.IsSavedData = true;
  189. }
  190. }