SettingPanel.cs 2.2 KB

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