ModeController.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class ModeController : MonoBehaviour
  6. {
  7. //public enum Mode { Player, Editor};
  8. //public Mode mode = Mode.Player;
  9. public GameObject Player;
  10. public GameObject Locations;
  11. public GameObject Editor;
  12. public GameObject EditorTools;
  13. public GameObject Plane;
  14. public GameObject Grid;
  15. public GameObject LineX;
  16. public GameObject LineY;
  17. public GameObject Markers;
  18. public GameObject Beacons;
  19. public GameObject Walls;
  20. Transform maps;
  21. public static bool editor = false;
  22. Button button;
  23. Dropdown.OptionData item;
  24. // Start is called before the first frame update
  25. void Start()
  26. {
  27. button = gameObject.GetComponent<Button>();
  28. button.onClick.AddListener(() => {
  29. Switch();
  30. });
  31. if (editor) EditorMode();
  32. maps = Player.transform.Find("Dropdown_maps");
  33. }
  34. // Update is called once per frame
  35. void Update()
  36. {
  37. }
  38. public void Switch()
  39. {
  40. editor = !editor;
  41. transform.GetChild(0).gameObject.SetActive(!editor);
  42. transform.GetChild(1).gameObject.SetActive(editor);
  43. if (editor)
  44. {
  45. Player.GetComponent<PlayerController>().StopProgress();
  46. EditorMode();
  47. }
  48. else PlayerMode();
  49. }
  50. void PlayerMode()
  51. {
  52. Player.SetActive(true);
  53. //Locations.SetActive(true);
  54. Markers.SetActive(true);
  55. //Beacons.SetActive(true);
  56. Editor.SetActive(false);
  57. EditorTools.SetActive(false);
  58. Plane.SetActive(false);
  59. Grid.SetActive(false);
  60. Walls.SetActive(false);
  61. Destroy(GameObject.Find("SizeX"));
  62. Destroy(GameObject.Find("SizeY"));
  63. maps.transform.SetParent(Player.transform);
  64. maps.transform.SetSiblingIndex(1);
  65. maps.GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 200);
  66. if(item != null)maps.GetComponent<Dropdown>().options.Remove(item);
  67. maps.GetComponent<Dropdown>().value = 0;
  68. for (int i = 0; i < Beacons.transform.childCount; i++)
  69. {
  70. Beacons.transform.GetChild(i).GetComponent<BeaconController>().mode = BeaconController.Mode.Player;
  71. Beacons.transform.GetChild(i).GetComponent<LabelObjectScript>().enabled = true;
  72. }
  73. //PlayerController.markers = new List<Marker>();
  74. //client.SendGetUsers((uint)PlayerController.active_company + 1);
  75. //PlayerController.Beacons = new List<Beacon>();
  76. //client.BeaconsRequest((uint)PlayerController.locations[DropdownLocation.value].id);
  77. }
  78. void EditorMode()
  79. {
  80. Player.SetActive(false);
  81. //Locations.SetActive(false);
  82. Markers.SetActive(false);
  83. //Beacons.SetActive(false);
  84. Editor.SetActive(true);
  85. EditorTools.SetActive(true);
  86. Plane.SetActive(true);
  87. Grid.SetActive(true);
  88. Walls.SetActive(true);
  89. maps.transform.SetParent(Editor.transform);
  90. maps.transform.SetSiblingIndex(0);
  91. maps.GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 190);
  92. item = new Dropdown.OptionData("Новая локация");
  93. maps.GetComponent<Dropdown>().options.Add(item);
  94. for (int i = 0; i < Beacons.transform.childCount; i++)
  95. {
  96. Beacons.transform.GetChild(i).GetComponent<BeaconController>().info = false;
  97. Beacons.transform.GetChild(i).GetComponent<BeaconController>().mode = BeaconController.Mode.Editor;
  98. Beacons.transform.GetChild(i).GetComponent<LabelObjectScript>().enabled = false;
  99. }
  100. //foreach (var m in PlayerController.markers)
  101. //{
  102. // Destroy(m.marker.gameObject);
  103. // Destroy(m.marker_line.gameObject);
  104. // Destroy(m.toggle.gameObject);
  105. //}
  106. //PlayerController.markers.Clear();
  107. //foreach (var b in PlayerController.Beacons)
  108. //{
  109. // Destroy(b.beacon);
  110. // Destroy(b.button);
  111. //}
  112. //PlayerController.Beacons.Clear();
  113. }
  114. }