ModeController.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. public GameObject WallCursor;
  21. public GameObject Zones;
  22. Transform maps;
  23. public static bool editor = false;
  24. Button button;
  25. Dropdown.OptionData item;
  26. // Start is called before the first frame update
  27. void Start()
  28. {
  29. button = gameObject.GetComponent<Button>();
  30. button.onClick.AddListener(() => {
  31. Switch();
  32. });
  33. if (editor) EditorMode();
  34. maps = Player.transform.Find("Dropdown_maps");
  35. }
  36. // Update is called once per frame
  37. void Update()
  38. {
  39. }
  40. public void Switch()
  41. {
  42. editor = !editor;
  43. transform.GetChild(0).gameObject.SetActive(!editor);
  44. transform.GetChild(1).gameObject.SetActive(editor);
  45. if (editor)
  46. {
  47. Player.GetComponent<PlayerController>().StopProgress();
  48. EditorMode();
  49. }
  50. else PlayerMode();
  51. }
  52. void PlayerMode()
  53. {
  54. Player.SetActive(true);
  55. //Locations.SetActive(true);
  56. Markers.SetActive(true);
  57. //Beacons.SetActive(true);
  58. Editor.SetActive(false);
  59. EditorTools.SetActive(false);
  60. Plane.SetActive(false);
  61. Grid.SetActive(false);
  62. Walls.SetActive(false);
  63. Zones.SetActive(false);
  64. Destroy(GameObject.Find("SizeX"));
  65. Destroy(GameObject.Find("SizeY"));
  66. maps.transform.SetParent(Player.transform);
  67. maps.transform.SetSiblingIndex(1);
  68. maps.GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 200);
  69. if(item != null)maps.GetComponent<Dropdown>().options.Remove(item);
  70. maps.GetComponent<Dropdown>().value = 0;
  71. for (int i = 0; i < Beacons.transform.childCount; i++)
  72. {
  73. Beacons.transform.GetChild(i).GetComponent<BeaconController>().mode = BeaconController.Mode.Player;
  74. Beacons.transform.GetChild(i).GetComponent<LabelObjectScript>().enabled = true;
  75. }
  76. WallCursor.SetActive(false);
  77. GameObject old_button = null;
  78. switch (WallCreate.mode)
  79. {
  80. case WallCreate.Mode.Cursor:
  81. old_button =EditorTools.transform.GetChild(0).gameObject;
  82. break;
  83. case WallCreate.Mode.Room:
  84. old_button = EditorTools.transform.GetChild(1).gameObject;
  85. break;
  86. case WallCreate.Mode.Wall:
  87. old_button = EditorTools.transform.GetChild(2).gameObject;
  88. break;
  89. }
  90. if (old_button != null) old_button.GetComponent<Image>().color = Color.white;
  91. //PlayerController.markers = new List<Marker>();
  92. //client.SendGetUsers((uint)PlayerController.active_company + 1);
  93. //PlayerController.Beacons = new List<Beacon>();
  94. //client.BeaconsRequest((uint)PlayerController.locations[DropdownLocation.value].id);
  95. }
  96. void EditorMode()
  97. {
  98. Player.SetActive(false);
  99. //Locations.SetActive(false);
  100. Markers.SetActive(false);
  101. //Beacons.SetActive(false);
  102. Editor.SetActive(true);
  103. EditorTools.SetActive(true);
  104. Plane.SetActive(true);
  105. Grid.SetActive(true);
  106. Walls.SetActive(true);
  107. Zones.SetActive(true);
  108. maps.transform.SetParent(Editor.transform);
  109. maps.transform.SetSiblingIndex(0);
  110. maps.GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 190);
  111. item = new Dropdown.OptionData("Новая локация");
  112. maps.GetComponent<Dropdown>().options.Add(item);
  113. for (int i = 0; i < Beacons.transform.childCount; i++)
  114. {
  115. Beacons.transform.GetChild(i).GetComponent<BeaconController>().info = false;
  116. Beacons.transform.GetChild(i).GetComponent<BeaconController>().mode = BeaconController.Mode.Editor;
  117. Beacons.transform.GetChild(i).GetComponent<LabelObjectScript>().enabled = false;
  118. }
  119. var color = new Color();
  120. ColorUtility.TryParseHtmlString("#C8C8C8", out color);
  121. EditorTools.transform.GetChild(0).gameObject.GetComponent<Image>().color = color;
  122. //foreach (var m in PlayerController.markers)
  123. //{
  124. // Destroy(m.marker.gameObject);
  125. // Destroy(m.marker_line.gameObject);
  126. // Destroy(m.toggle.gameObject);
  127. //}
  128. //PlayerController.markers.Clear();
  129. //foreach (var b in PlayerController.Beacons)
  130. //{
  131. // Destroy(b.beacon);
  132. // Destroy(b.button);
  133. //}
  134. //PlayerController.Beacons.Clear();
  135. }
  136. }