SettingPanel.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. public class SettingPanel : AbstractController
  9. {
  10. public Toggle MinMap;
  11. public Toggle LuJIng;
  12. public Transform ChooseLine;
  13. public Toggle LineItem;
  14. public Transform LineItemParent;
  15. public Button SaveData;
  16. [SerializeField, Tooltip("小地图信息")]
  17. private MinMap m_MinMap;
  18. [SerializeField, Tooltip("路径控制器")]
  19. private RouteCtr m_RouteCtr;
  20. private List<Toggle> Lines;
  21. private void Awake()
  22. {
  23. Lines = new List<Toggle>();
  24. SaveData.onClick.AddListener(OnClickSaveData);
  25. MinMap.onValueChanged.AddListener(OnMinMapValueChange);
  26. LuJIng.onValueChanged.AddListener(OnLuJIngValueChange);
  27. }
  28. private void OnEnable()
  29. {
  30. MinMap.isOn = this.GetService<IMinMapService>().setMinMap == 1 ? true : false;
  31. }
  32. public void Init()
  33. {
  34. CreateLines();
  35. MinMap.isOn = true;
  36. m_MinMap.gameObject.SetActive(true);
  37. LuJIng.isOn = true;
  38. if (Lines.Count > 0)
  39. {
  40. Lines[0].isOn = true;
  41. }
  42. gameObject.SetActive(false);
  43. }
  44. private void OnMinMapValueChange(bool ison)
  45. {
  46. m_MinMap.gameObject.SetActive(ison);
  47. }
  48. private void OnLuJIngValueChange(bool ison)
  49. {
  50. m_RouteCtr.gameObject.SetActive(ison);
  51. for (int i = 0; i < Lines.Count; i++)
  52. {
  53. Lines[i].interactable = ison;
  54. }
  55. }
  56. private void CreateLines()
  57. {
  58. var lines = m_RouteCtr.List_route;
  59. for (int i = 0; i < lines.Count; i++)
  60. {
  61. Toggle obj = Instantiate(LineItem, LineItemParent);
  62. obj.isOn = false;
  63. obj.transform.Find("Label").GetComponent<Text>().text = lines[i].name;
  64. var item = obj.gameObject.AddComponent<LuJingItem>();
  65. item.OnToggleSelect += OnCLickToggle;
  66. obj.gameObject.SetActive(true);
  67. Lines.Add(obj);
  68. }
  69. }
  70. private void OnCLickToggle(int index, bool ison)
  71. {
  72. m_RouteCtr.SettingLuJing(index, ison);
  73. m_MinMap.SetRoute(index, ison);
  74. }
  75. private void OnClickSaveData()
  76. {
  77. this.SendCommand(new MinMapGetSetCommand(m_MinMap.gameObject.activeSelf ? 1 : 0));
  78. DataManager.Instance.SaveSpoits();
  79. DataManager.Instance.IsSavedData = true;
  80. }
  81. }