SettingPanel.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. setdingwei(arg0);
  58. }
  59. }
  60. private void OnEnable()
  61. {
  62. MinMap.interactable = false;
  63. NoMinMap.interactable = false;
  64. HttpTool.Instance.Get("/user/getUserInfo", (string str) =>
  65. {
  66. MinMap.interactable = true;
  67. NoMinMap.interactable = true;
  68. JsonData data = JsonMapper.ToObject(str);
  69. if (data["data"]["minMap"].ToString() == "0")
  70. {
  71. NoMinMap.isOn = true;
  72. m_MinMap.gameObject.SetActive(false);
  73. }
  74. else
  75. {
  76. MinMap.isOn = true;
  77. m_MinMap.gameObject.SetActive(true);
  78. }
  79. });
  80. // HttpTool.Instance.Post("/viewpoint/locationPoint", data.ToJson(), (string str) => { });
  81. // MinMap.isOn = this.GetService<IMinMapService>().setMinMap == 1 ? true : false;
  82. }
  83. public void setMsg(SpoitValue sv)
  84. {
  85. nowsp = sv;
  86. if (sv!=null)
  87. {
  88. feiDingWei.gameObject.SetActive(true);
  89. DingWei.gameObject.SetActive(true);
  90. spMRtext.text = sv.name;
  91. if (dingweilist.ContainsKey(nowsp.id))
  92. {
  93. if(dingweilist[nowsp.id])
  94. {
  95. setdingwei(true);
  96. DingWei.isOn = true;
  97. }
  98. else
  99. {
  100. if (ARSpace.isFind)
  101. {
  102. setdingwei(false);
  103. }
  104. feiDingWei.isOn = true;
  105. }
  106. }
  107. else
  108. {
  109. if(sv.location)
  110. {
  111. dingweilist.Add(nowsp.id,true);
  112. setdingwei(true);
  113. DingWei.isOn = true;
  114. }
  115. else
  116. {
  117. if (ARSpace.isFind)
  118. {
  119. setdingwei(false);
  120. }
  121. feiDingWei.isOn = true;
  122. }
  123. }
  124. }
  125. else
  126. {
  127. spMRtext.text = "----";
  128. feiDingWei.isOn = false;
  129. feiDingWei.gameObject.SetActive(false);
  130. DingWei.gameObject.SetActive(false);
  131. //if(ARSpace.isFind)
  132. //{
  133. setdingwei(true);
  134. //}
  135. }
  136. }
  137. public void setdingwei(bool isopen)
  138. {
  139. if(isopen&&!MoveChange.islixian)
  140. XRLocalizer.Instance.gameObject.SetActive(true);
  141. else
  142. {
  143. XRLocalizer.Instance.gameObject.SetActive(false);
  144. }
  145. }
  146. public void Init()
  147. {
  148. CreateLines();
  149. // MinMap.isOn = true;
  150. // m_MinMap.gameObject.SetActive(true);
  151. gameObject.SetActive(false);
  152. }
  153. private void OnMinMapValueChange(bool ison)
  154. {
  155. Debug.Log("OnMinMapValueChange===>"+ison);
  156. JsonData data = new JsonData();
  157. data["minMap"] = ison?1:0;
  158. HttpTool.Instance.Post("/user/settings", data.ToJson(), (string str)=> { });
  159. TimerMgr.Instance.CreateTimer(()=> { m_MinMap.gameObject.SetActive(ison); },0.3f,3);
  160. }
  161. private void OnLuJIngValueChange(bool ison)
  162. {
  163. m_RouteCtr.gameObject.SetActive(ison);
  164. for (int i = 0; i < m_MinMap.list_route.Count; i++)
  165. {
  166. m_MinMap.list_route[i].gameObject.SetActive(ison);
  167. }
  168. }
  169. private void CreateLines()
  170. {
  171. var lines = m_RouteCtr.List_route;
  172. for (int i = 0; i < lines.Count; i++)
  173. {
  174. Toggle obj = Instantiate(LineItem, LineItemParent);
  175. obj.isOn = false;
  176. obj.transform.Find("Label").GetComponent<Text>().text = lines[i].name;
  177. var item = obj.gameObject.AddComponent<LuJingItem>();
  178. item.OnToggleSelect += OnCLickToggle;
  179. obj.gameObject.SetActive(true);
  180. Lines.Add(obj);
  181. }
  182. }
  183. private void OnCLickToggle(int index, bool ison)
  184. {
  185. m_RouteCtr.SettingLuJing(index, ison);
  186. m_MinMap.SetRoute(index, ison);
  187. }
  188. private void OnClickSaveData()
  189. {
  190. this.SendCommand(new MinMapGetSetCommand(m_MinMap.gameObject.activeSelf ? 1 : 0));
  191. // DataManager.Instance.SaveSpoits();
  192. GameManager.Instance.StartCoroutine(UIEditorPanel.Instance.SetSpoitInfo());
  193. DataManager.Instance.IsSavedData = true;
  194. }
  195. }