ModeController.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 static ModeController instance;
  11. public GameObject Company;
  12. public GameObject Player;
  13. public GameObject Editor;
  14. public GameObject EditorTools;
  15. public GameObject LineX;
  16. public GameObject LineY;
  17. public GameObject Markers;
  18. public GameObject WallCursor;
  19. public GameObject DropdownLocations;
  20. public GameObject Building;
  21. public GameObject BuildingMode;
  22. public GameObject GroundSettings;
  23. public GameObject DateTime;
  24. Transform maps;
  25. public static bool editor = false;
  26. Button button;
  27. Dropdown.OptionData item;
  28. private void Awake()
  29. {
  30. instance = this;
  31. }
  32. // Start is called before the first frame update
  33. void Start()
  34. {
  35. button = gameObject.GetComponent<Button>();
  36. button.onClick.AddListener(() => {
  37. Switch();
  38. });
  39. if (editor) EditorMode();
  40. maps = DropdownLocations.transform;
  41. }
  42. // Update is called once per frame
  43. void Update()
  44. {
  45. }
  46. public void Switch()
  47. {
  48. editor = !editor;
  49. transform.GetChild(0).gameObject.SetActive(!editor);
  50. transform.GetChild(1).gameObject.SetActive(editor);
  51. if (editor)
  52. {
  53. Player.GetComponent<PlayerController>().StopProgress();
  54. EditorMode();
  55. }
  56. else PlayerMode();
  57. }
  58. void PlayerMode()
  59. {
  60. var company = Company.GetComponent<CompanyController>();
  61. var l = company.locations[company.locations_index[company.active_location]];
  62. foreach (var b in l.beacons.Values)
  63. b.beacon.GetComponent<BeaconController>().mode = BeaconController.Mode.Player;
  64. company.LocationZones.gameObject.SetActive(true);
  65. company.selectUsers.SetActive(true);
  66. l.plane.GetComponent<TouchScript>().Resize = false;
  67. var edit = Editor.GetComponent<EditorController>();
  68. Destroy(edit.NewLocation);
  69. edit.EditLocation = null;
  70. Player.SetActive(true);
  71. //Locations.SetActive(true);
  72. Markers.SetActive(true);
  73. //Beacons.SetActive(true);
  74. Editor.SetActive(false);
  75. EditorTools.SetActive(false);
  76. Building.SetActive(false);
  77. if (BuildingMode.activeSelf == true) BuildingMode.SetActive(false);
  78. if (GroundSettings.activeSelf == true) GroundSettings.SetActive(false);
  79. Destroy(GameObject.Find("SizeX"));
  80. Destroy(GameObject.Find("SizeY"));
  81. if (item == null)
  82. {
  83. item = maps.GetComponent<Dropdown>().options.Last();
  84. maps.GetComponent<Dropdown>().options.Remove(item);
  85. maps.GetComponent<Dropdown>().RefreshShownValue();
  86. }
  87. //for (int i = 0; i < Beacons.transform.childCount; i++)
  88. //{
  89. // Beacons.transform.GetChild(i).GetComponent<BeaconController>().mode = BeaconController.Mode.Player;
  90. // Beacons.transform.GetChild(i).GetComponent<LabelObjectScript>().enabled = true;
  91. //}
  92. WallCursor.SetActive(false);
  93. var wl = WallCursor.GetComponent<WallCreate>();
  94. GameObject old_button = null;
  95. switch (wl.mode)
  96. {
  97. case WallCreate.Mode.Cursor:
  98. old_button =EditorTools.transform.GetChild(0).gameObject;
  99. break;
  100. case WallCreate.Mode.Room:
  101. old_button = EditorTools.transform.GetChild(1).gameObject;
  102. break;
  103. case WallCreate.Mode.Wall:
  104. old_button = EditorTools.transform.GetChild(2).gameObject;
  105. break;
  106. }
  107. if (old_button != null) old_button.GetComponent<Image>().color = Color.white;
  108. //PlayerController.markers = new List<Marker>();
  109. //client.SendGetUsers((uint)PlayerController.active_company + 1);
  110. //PlayerController.Beacons = new List<Beacon>();
  111. //client.BeaconsRequest((uint)PlayerController.locations[DropdownLocation.value].id);
  112. }
  113. void EditorMode()
  114. {
  115. Player.SetActive(false);
  116. //Locations.SetActive(false);
  117. Markers.SetActive(false);
  118. //Beacons.SetActive(false);
  119. Editor.SetActive(true);
  120. EditorTools.SetActive(true);
  121. Building.SetActive(true);
  122. BuildingMode.SetActive(true);
  123. var company = Company.GetComponent<CompanyController>();
  124. if (company.active_location >= 0)
  125. {
  126. var l = company.locations[company.locations_index[company.active_location]];
  127. foreach (var b in l.beacons.Values)
  128. b.beacon.GetComponent<BeaconController>().mode = BeaconController.Mode.Editor;
  129. }
  130. company.LocationZones.gameObject.SetActive(false);
  131. company.selectUsers.SetActive(false);
  132. //l.plane.GetComponent<TouchScript>().Resize = false;
  133. //item = new Dropdown.OptionData("Новая локация");
  134. //maps.GetComponent<Dropdown>().options.Add(item);
  135. //for (int i = 0; i < Beacons.transform.childCount; i++)
  136. //{
  137. // Beacons.transform.GetChild(i).GetComponent<BeaconController>().info = false;
  138. // Beacons.transform.GetChild(i).GetComponent<BeaconController>().mode = BeaconController.Mode.Editor;
  139. // Beacons.transform.GetChild(i).GetComponent<LabelObjectScript>().enabled = false;
  140. //}
  141. var color = new Color();
  142. ColorUtility.TryParseHtmlString("#C8C8C8", out color);
  143. EditorTools.transform.GetChild(0).gameObject.GetComponent<Image>().color = color;
  144. if (DateTime.activeSelf == true) DateTime.SetActive(false);
  145. //foreach (var m in PlayerController.markers)
  146. //{
  147. // Destroy(m.marker.gameObject);
  148. // Destroy(m.marker_line.gameObject);
  149. // Destroy(m.toggle.gameObject);
  150. //}
  151. //PlayerController.markers.Clear();
  152. //foreach (var b in PlayerController.Beacons)
  153. //{
  154. // Destroy(b.beacon);
  155. // Destroy(b.button);
  156. //}
  157. //PlayerController.Beacons.Clear();
  158. }
  159. }