123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- using System.Collections;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class EditorController : MonoBehaviour
- {
- public InputField Name;
- public InputField Image;
- public InputField SizeX;
- public InputField SizeY;
- public GameObject plane;
- public GameObject BeaconsContent;
- public GameObject PanelBeaconEdit;
- public Toggle ToggleGrid;
- public Toggle ToggleScalePanel;
- public Toggle projection;
- public GameObject Grid;
- public Dropdown DropdownLocation;
- public Transform Locations;
- public Button ButtonAddBeacon;
- public List<Beacon> Beacons = new List<Beacon>();
- PlayerController player;
- ModeController mode;
- ToolsController tools;
- Client client;
-
- void Start()
- {
- client = Client.instance;
- player = GameObject.Find("Canvas").transform.GetChild(2).GetComponent<PlayerController>();
- mode = GameObject.Find("ButtonMode").GetComponent<ModeController>();
- tools = GameObject.Find("EditorTools").GetComponent<ToolsController>();
- ButtonAddBeacon.onClick.AddListener(() => {
- AddBeacon();
- });
- }
-
- void Update()
- {
- SizeX.text = $"{plane.transform.localScale.x}";
- SizeY.text = $"{plane.transform.localScale.z}";
- if (ToggleGrid.isOn != Grid.activeSelf) Grid.SetActive(ToggleGrid.isOn);
- if (ToggleScalePanel.isOn != plane.GetComponent<TouchScript>().activeScript) plane.GetComponent<TouchScript>().activeScript = ToggleScalePanel.isOn;
- if (projection.isOn)
- {
- Camera.main.orthographic = true;
- }
- else
- {
- Camera.main.orthographic = false;
- }
- PlayerController.LoadMaps(client, DropdownLocation, Locations.gameObject);
- }
- public void UpdatePanel()
- {
- if (!Image.text.Equals(""))
- StartCoroutine(SendingFormController.LoadImage(Image.text, plane));
- var x = 1f;
- if (!SizeX.text.Equals(""))
- x = float.Parse(SizeX.text, CultureInfo.InvariantCulture);
- var y = 1f;
- if (!SizeY.text.Equals(""))
- y = float.Parse(SizeY.text, CultureInfo.InvariantCulture);
- plane.transform.localScale = new Vector3(x, 1, y);
- var scale = plane.transform.localScale;
- plane.transform.position = new Vector3(scale.x * 5, 0, scale.z * 5);
- }
- public void Save()
- {
-
- tools.CursorOff();
- mode.Switch();
- var l = new Location { id = PlayerController.locations.Count, name = Name.text };
- PlayerController.locations.Add(l);
- player.DropdownLocation.options.Add(new Dropdown.OptionData(l.name));
-
- var location = new GameObject();
- location.name = l.name;
- location.transform.SetParent(Locations);
- foreach (var w in WallCreate.Walls)
- w.transform.SetParent(location.transform);
- }
- public void Back()
- {
-
- mode.Switch();
- }
- public void AddBeacon(Beacon b = null)
- {
-
-
- var beacon = Instantiate(Resources.Load("GameObjects/Beacon", typeof(GameObject))) as GameObject;
- if(ModeController.editor) beacon.GetComponent<BeaconController>().mode = BeaconController.Mode.Editor;
-
- beacon.name = $"Beacon_{b?.id.ToString() ?? Beacons.Count.ToString()}";
- if (b != null)
- {
- beacon.transform.position = new Vector3(b.x / 100, 0.5f, b.y / 100);
-
- beacon.GetComponent<BeaconController>().text_info= $"{b.id}\nuuid={b.uuid}\nmajor={b.major}\nminor={b.minor}";
- beacon.GetComponent<BeaconController>().id = $"{b.id}";
- }
- beacon.transform.SetParent(GameObject.Find("Beacons").transform);
- var name_beacon = $"Маяк {b?.id.ToString() ?? Beacons.Count.ToString()}";
- PanelBeaconEdit.transform.GetChild(0).GetComponent<Text>().text = name_beacon;
- var panel_button = Instantiate(Resources.Load("GameObjects/Panel_Beacon", typeof(GameObject))) as GameObject;
- panel_button.transform.SetParent(BeaconsContent.transform);
- panel_button.name = $"Beacon_{b?.id.ToString() ?? Beacons.Count.ToString()}";
- var button = panel_button.transform.GetChild(0).GetComponent<Button>();
- button.name = $"BeaconButton_{Beacons.Count}";
-
- button.transform.GetChild(0).GetComponent<Text>().text = name_beacon;
-
- button.onClick.AddListener(() =>
- {
- PanelBeaconEdit.SetActive(true);
- PanelBeaconEdit.transform.GetChild(0).GetComponent<Text>().text = name_beacon;
- if (b != null)
- {
- PanelBeaconEdit.transform.GetChild(1).GetComponent<InputField>().text = b.uuid;
- PanelBeaconEdit.transform.GetChild(2).GetComponent<InputField>().text = $"{b.major}";
- PanelBeaconEdit.transform.GetChild(3).GetComponent<InputField>().text = $"{b.major}";
- }
- });
-
-
- if (b == null) b = new Beacon();
- var button_ok = PanelBeaconEdit.transform.GetChild(5).transform.GetChild(0).GetComponent<Button>();
- button_ok.onClick.AddListener(() =>
- {
- b.uuid = PanelBeaconEdit.transform.GetChild(1).GetComponent<InputField>().text;
- b.minor = uint.Parse(PanelBeaconEdit.transform.GetChild(2).GetComponent<InputField>().text);
- b.major = uint.Parse(PanelBeaconEdit.transform.GetChild(3).GetComponent<InputField>().text);
- PanelBeaconEdit.SetActive(false);
- });
- var button_close = PanelBeaconEdit.transform.GetChild(5).transform.GetChild(1).GetComponent<Button>();
- button_close.onClick.AddListener(() =>
- {
- PanelBeaconEdit.SetActive(false);
- });
- var button_del = panel_button.transform.GetChild(1).GetComponent<Button>();
- button_del.onClick.AddListener(() =>
- {
- Destroy(beacon);
- Destroy(panel_button);
- Beacons.Remove(b);
- if (PanelBeaconEdit.activeSelf) PanelBeaconEdit.SetActive(false);
- });
-
- b.beacon = beacon;
- b.panel_button = panel_button;
- Beacons.Add(b);
- }
- }
|