ModeController.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class ModeController : MonoBehaviour
  7. {
  8. //public enum Mode { Player, Editor};
  9. //public Mode mode = Mode.Player;
  10. public GameObject Company;
  11. public GameObject Player;
  12. public GameObject Editor;
  13. public GameObject EditorTools;
  14. public GameObject LineX;
  15. public GameObject LineY;
  16. public GameObject Markers;
  17. public GameObject WallCursor;
  18. public GameObject DropdownLocations;
  19. public GameObject Building;
  20. public GameObject BuildingMode;
  21. public GameObject GroundSettings;
  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 = DropdownLocations.transform;
  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. var company = Company.GetComponent<CompanyController>();
  55. var l = company.locations[company.locations_index[company.active_location]];
  56. foreach (var b in l.beacons)
  57. b.beacon.GetComponent<BeaconController>().mode = BeaconController.Mode.Player;
  58. var edit = Editor.GetComponent<EditorController>();
  59. Destroy(edit.NewLocation);
  60. edit.EditLocation = null;
  61. Player.SetActive(true);
  62. //Locations.SetActive(true);
  63. Markers.SetActive(true);
  64. //Beacons.SetActive(true);
  65. Editor.SetActive(false);
  66. EditorTools.SetActive(false);
  67. Building.SetActive(false);
  68. if (BuildingMode.activeSelf == true) BuildingMode.SetActive(false);
  69. if (GroundSettings.activeSelf == true) GroundSettings.SetActive(false);
  70. Destroy(GameObject.Find("SizeX"));
  71. Destroy(GameObject.Find("SizeY"));
  72. if (item == null)
  73. {
  74. item = maps.GetComponent<Dropdown>().options.Last();
  75. maps.GetComponent<Dropdown>().options.Remove(item);
  76. maps.GetComponent<Dropdown>().RefreshShownValue();
  77. }
  78. //for (int i = 0; i < Beacons.transform.childCount; i++)
  79. //{
  80. // Beacons.transform.GetChild(i).GetComponent<BeaconController>().mode = BeaconController.Mode.Player;
  81. // Beacons.transform.GetChild(i).GetComponent<LabelObjectScript>().enabled = true;
  82. //}
  83. WallCursor.SetActive(false);
  84. GameObject old_button = null;
  85. switch (WallCreate.mode)
  86. {
  87. case WallCreate.Mode.Cursor:
  88. old_button =EditorTools.transform.GetChild(0).gameObject;
  89. break;
  90. case WallCreate.Mode.Room:
  91. old_button = EditorTools.transform.GetChild(1).gameObject;
  92. break;
  93. case WallCreate.Mode.Wall:
  94. old_button = EditorTools.transform.GetChild(2).gameObject;
  95. break;
  96. }
  97. if (old_button != null) old_button.GetComponent<Image>().color = Color.white;
  98. //PlayerController.markers = new List<Marker>();
  99. //client.SendGetUsers((uint)PlayerController.active_company + 1);
  100. //PlayerController.Beacons = new List<Beacon>();
  101. //client.BeaconsRequest((uint)PlayerController.locations[DropdownLocation.value].id);
  102. }
  103. void EditorMode()
  104. {
  105. Player.SetActive(false);
  106. //Locations.SetActive(false);
  107. Markers.SetActive(false);
  108. //Beacons.SetActive(false);
  109. Editor.SetActive(true);
  110. EditorTools.SetActive(true);
  111. Building.SetActive(true);
  112. BuildingMode.SetActive(true);
  113. var company = Company.GetComponent<CompanyController>();
  114. var l = company.locations[company.locations_index[company.active_location]];
  115. foreach (var b in l.beacons)
  116. b.beacon.GetComponent<BeaconController>().mode = BeaconController.Mode.Editor;
  117. //item = new Dropdown.OptionData("Новая локация");
  118. //maps.GetComponent<Dropdown>().options.Add(item);
  119. //for (int i = 0; i < Beacons.transform.childCount; i++)
  120. //{
  121. // Beacons.transform.GetChild(i).GetComponent<BeaconController>().info = false;
  122. // Beacons.transform.GetChild(i).GetComponent<BeaconController>().mode = BeaconController.Mode.Editor;
  123. // Beacons.transform.GetChild(i).GetComponent<LabelObjectScript>().enabled = false;
  124. //}
  125. var color = new Color();
  126. ColorUtility.TryParseHtmlString("#C8C8C8", out color);
  127. EditorTools.transform.GetChild(0).gameObject.GetComponent<Image>().color = color;
  128. //foreach (var m in PlayerController.markers)
  129. //{
  130. // Destroy(m.marker.gameObject);
  131. // Destroy(m.marker_line.gameObject);
  132. // Destroy(m.toggle.gameObject);
  133. //}
  134. //PlayerController.markers.Clear();
  135. //foreach (var b in PlayerController.Beacons)
  136. //{
  137. // Destroy(b.beacon);
  138. // Destroy(b.button);
  139. //}
  140. //PlayerController.Beacons.Clear();
  141. }
  142. }