EditorController.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using UnityEngine;
  5. using UnityEngine.SceneManagement;
  6. using UnityEngine.UI;
  7. /// <summary>
  8. /// Редактор
  9. /// </summary>
  10. public class EditorController : MonoBehaviour
  11. {
  12. public InputField Name;
  13. public InputField Image;
  14. public InputField SizeX;
  15. public InputField SizeY;
  16. public GameObject plane;
  17. public GameObject BeaconsContent;
  18. public GameObject PanelBeaconEdit;
  19. public Toggle ToggleGrid;
  20. public Toggle ToggleScalePanel;
  21. public Toggle projection;
  22. public GameObject Grid;
  23. public List<Beacon> Beacons = new List<Beacon>();
  24. PlayerController player;
  25. ModeController mode;
  26. ToolsController tools;
  27. // Start is called before the first frame update
  28. void Start()
  29. {
  30. player = GameObject.Find("Canvas").transform.GetChild(2).GetComponent<PlayerController>();
  31. mode = GameObject.Find("ButtonMode").GetComponent<ModeController>();
  32. tools = GameObject.Find("EditorTools").GetComponent<ToolsController>();
  33. }
  34. // Update is called once per frame
  35. void Update()
  36. {
  37. SizeX.text = $"{plane.transform.localScale.x}";
  38. SizeY.text = $"{plane.transform.localScale.z}";
  39. if (ToggleGrid.isOn != Grid.activeSelf) Grid.SetActive(ToggleGrid.isOn);
  40. if (ToggleScalePanel.isOn != plane.GetComponent<TouchScript>().activeScript) plane.GetComponent<TouchScript>().activeScript = ToggleScalePanel.isOn;
  41. if (projection.isOn)
  42. {
  43. Camera.main.orthographic = true;
  44. }
  45. else
  46. {
  47. Camera.main.orthographic = false;
  48. }
  49. }
  50. public void UpdatePanel()
  51. {
  52. if (!Image.text.Equals(""))
  53. StartCoroutine(SendingFormController.LoadImage(Image.text, plane));
  54. var x = 1f;
  55. if (!SizeX.text.Equals(""))
  56. x = float.Parse(SizeX.text, CultureInfo.InvariantCulture);
  57. var y = 1f;
  58. if (!SizeY.text.Equals(""))
  59. y = float.Parse(SizeY.text, CultureInfo.InvariantCulture);
  60. plane.transform.localScale = new Vector3(x, 1, y);
  61. var scale = plane.transform.localScale;
  62. plane.transform.position = new Vector3(scale.x * 5, 0, scale.z * 5);
  63. }
  64. public void Save()
  65. {
  66. //SceneManager.LoadScene("Location");
  67. tools.CursorOff();
  68. mode.Switch();
  69. var l = new Location { id = PlayerController.locations.Count, name = Name.text };
  70. PlayerController.locations.Add(l);
  71. player.DropdownLocation.options.Add(new Dropdown.OptionData(l.name));
  72. var locations = GameObject.Find("Locations").gameObject;
  73. var location = new GameObject();
  74. location.name = l.name;
  75. location.transform.SetParent(locations.transform);
  76. foreach (var w in WallCreate.Walls)
  77. w.transform.SetParent(location.transform);
  78. player.maps.Add(location);
  79. }
  80. public void Back()
  81. {
  82. //SceneManager.LoadScene("Location");
  83. mode.Switch();
  84. }
  85. public void AddBeacon()
  86. {
  87. PanelBeaconEdit.SetActive(true);
  88. PanelBeaconEdit.transform.GetChild(0).GetComponent<Text>().text = $"Маяк_{Beacons.Count}";
  89. var beacon = Instantiate(Resources.Load("GameObjects/Beacon", typeof(GameObject))) as GameObject;
  90. beacon.GetComponent<BeaconController>().mode = BeaconController.Mode.Editor;
  91. var panel_button = Instantiate(Resources.Load("GameObjects/Panel_Beacon", typeof(GameObject))) as GameObject;
  92. panel_button.transform.SetParent(BeaconsContent.transform);
  93. var button = panel_button.transform.GetChild(0).GetComponent<Button>();
  94. button.name = $"BeaconButton_{Beacons.Count}";
  95. button.transform.GetChild(0).GetComponent<Text>().text = $"Маяк_{Beacons.Count}";
  96. var b = new Beacon { };
  97. button.onClick.AddListener(() =>
  98. {
  99. PanelBeaconEdit.SetActive(true);
  100. });
  101. //var text = PanelBeaconEdit.transform.GetChild(0).GetComponent<Text>().text = "";
  102. //var uuid = PanelBeaconEdit.transform.GetChild(1).GetComponent<InputField>().text = "";
  103. var button_ok = PanelBeaconEdit.transform.GetChild(5).transform.GetChild(0).GetComponent<Button>();
  104. button_ok.onClick.AddListener(() =>
  105. {
  106. b.uuid = PanelBeaconEdit.transform.GetChild(1).GetComponent<InputField>().text;
  107. b.minor = uint.Parse(PanelBeaconEdit.transform.GetChild(2).GetComponent<InputField>().text);
  108. b.major = uint.Parse(PanelBeaconEdit.transform.GetChild(3).GetComponent<InputField>().text);
  109. PanelBeaconEdit.SetActive(false);
  110. });
  111. var button_close = PanelBeaconEdit.transform.GetChild(5).transform.GetChild(1).GetComponent<Button>();
  112. button_close.onClick.AddListener(() =>
  113. {
  114. PanelBeaconEdit.SetActive(false);
  115. });
  116. var button_del = panel_button.transform.GetChild(1).GetComponent<Button>();
  117. button_del.onClick.AddListener(() =>
  118. {
  119. Destroy(beacon);
  120. Destroy(panel_button);
  121. Beacons.Remove(b);
  122. if (PanelBeaconEdit.activeSelf) PanelBeaconEdit.SetActive(false);
  123. });
  124. b.id = (uint)Beacons.Count;
  125. b.beacon = beacon;
  126. b.button = button;
  127. Beacons.Add(b);
  128. }
  129. }