using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UI; public class CompanyController : MonoBehaviour { public static CompanyController instance; public Button ButtonStatus; public GameObject Player; public GameObject Editor; public Dropdown DropdownCompany; public Dropdown DropdownLocation; public Dialog Dialog; public GameObject ZonesScroll; public Toggle ToggleBeacons; public Toggle ToggleZones; public int active_company = -1; public int active_location = -1; public GameObject Locations; public Dictionary load_location_elements = new Dictionary(); // флаги загрузки элементов локации public bool load_location = false; public Dictionary locations; // список локаций public Dictionary> users; // список локаций public List locations_index; // сопоставление id с dropdown //public List markers; public LocationZones LocationZones; public SelectUsers selectUsers; public WallCreate Cursor; PlayerController player; EditorController editor; Client client; private void Awake() { instance = this; } // Start is called before the first frame update void Start() { DebugHelper.ActivateConsole(); player = Player.GetComponent(); editor = Editor.GetComponent(); client = Client.instance; DropdownCompany.options.Add(new Dropdown.OptionData("Тайшет")); DropdownCompany.options.Add(new Dropdown.OptionData("Тестовая")); DropdownCompany.options.Add(new Dropdown.OptionData("Братское")); locations = new Dictionary(); locations_index = new List(); } // Update is called once per frame void Update() { if (active_company != DropdownCompany.value && AuthorizationController.success) ChangeCompany(); if (active_location != DropdownLocation.value && AuthorizationController.success && locations.Any()) ChangeLocation(); if (active_location >= 0 && locations_index.Any()) if (AuthorizationController.success && load_location_elements.ContainsKey(locations_index[active_location])) { if (load_location_elements[locations_index[active_location]].location) { var l = locations[locations_index[active_location]]; LocationContents(l); } BeaconsOnOff(); ZonesOnOff(); } if (load_location) { load_location = false; DropdownLocation.options.Clear(); DropdownLocation.options = new List(); foreach (var l in locations) { l.Value.location.transform.SetParent(Locations.transform); l.Value.location.SetActive(false); DropdownLocation.options.Add(new Dropdown.OptionData($"{l.Key} {l.Value.name}")); load_location_elements[l.Key] = new Load(); load_location_elements[l.Key].location = true; l.Value.Load(); } if (ModeController.editor && editor.newLocation != null) { var l = editor.newLocation; //l.location.transform.SetParent(Locations.transform); l.location.transform.SetSiblingIndex(Locations.transform.childCount - 1); l.location.SetActive(false); DropdownLocation.options.Add(new Dropdown.OptionData($"Новая локация")); locations_index.Add(l.id); locations[l.id] = l; } DropdownLocation.value = 0; DropdownLocation.RefreshShownValue(); active_location = DropdownLocation.value; //active_location = -1; ChangeLocation(); } if(client.connected) ButtonStatus.GetComponent().color = Color.green; else ButtonStatus.GetComponent().color = Color.red; } /// /// Удаление сотрудников из-за смены компании /// Отчистка Locations /// /// public void ChangeCompany() { foreach (var l in locations) { if (l.Value.id < (uint)int.MaxValue) { Destroy(l.Value.location); foreach (var b in l.Value.beacons.Values) Destroy(b.panel_button); foreach (var z in l.Value.zones) { Destroy(z.buttons); LocationZones.DeleteZone(z.id); } load_location_elements.Remove(l.Value.id); } } active_company = DropdownCompany.value; DropdownLocation.value = 0; DropdownLocation.RefreshShownValue(); //active_location = 0; //if (player.users != null) // foreach (var m in player.users) // { // Destroy(m.Value.marker.gameObject); // Destroy(m.Value.marker_line.gameObject); // Destroy(m.Value.toggle_user); // //m.Value.UserCompany(); // } Client.instance.company_id = (uint)(active_company + 1); User.SendGetUsers(); //player.users = new Dictionary(); //player.users = users[]; if (player.users != null) foreach (var u in player.users.Values) u.UserCompany(); Location.LocationsRequest(0); } float sizex = 0; float sizey = 0; public void ChangeLocation() { Debug.Log("PlayerController locations count " + locations.Count + " active " + active_location); if (active_location >= 0) locations[locations_index[active_location]].LocationActive(false, LocationZones); active_location = DropdownLocation.value; var l = locations[locations_index[active_location]]; l.LocationActive(true, LocationZones); if (!l.texture_url.Equals("")) StartCoroutine(SendingFormController.LoadImage(l.texture_url, l.plane, l.plane.transform.position, l.plane.transform.localScale)); editor.Name.text = l.name; editor.Image.text = l.texture_url; editor.EditLocation = l; if (l.plane.transform.localScale.x != sizex) { editor.SizeX.text = $"{l.plane.transform.localScale.x}"; sizex = l.plane.transform.localScale.x; } if (l.plane.transform.localScale.z != sizey) { editor.SizeY.text = $"{l.plane.transform.localScale.z}"; sizey = l.plane.transform.localScale.z; } //l.plane.GetComponent().Resize = ModeController.editor; player.StopProgress(); } public void LocationContents(Location location) { if (load_location_elements.ContainsKey(location.id)) { if (load_location_elements[location.id].walls) { load_location_elements[location.id].walls = false; var walls = location.location.transform.GetChild(1); foreach (var w in location.walls) { var wall = Cursor.AddWall(this, new Vector3(w.start_width, WallCreate.WallHeight / 2, w.start_height), new Vector3(Mathf.Abs(w.end_width), WallCreate.WallHeight, Mathf.Abs(w.end_height))); wall.transform.SetParent(walls.transform); } } if (!editor.Beacons.ContainsKey(location.id)) editor.Beacons[location.id] = new Dictionary(); if (load_location_elements[location.id].beacons) { load_location_elements[location.id].beacons = false; foreach (var b in location.beacons.Values) { editor.AddBeacon(this, b); if (ModeController.editor == true) b.beacon.GetComponent().mode = BeaconController.Mode.Editor; } } if (load_location_elements[location.id].zones) { load_location_elements[location.id].zones = false; foreach (var z in location.zones) z.go = Cursor.AddZone(Dialog, this, ZonesScroll, z); } } } public Location GetActiveLocation() { if(active_location >= 0) return locations[locations_index[active_location]]; else return null; } public Location GetLocation(uint id) { if (locations.Count > 0) if (locations.ContainsKey(id)) return locations[id]; return null; } public void ErrorDialogClose() { Dialog.gameObject.SetActive(false); } bool beacons_view; public void BeaconsOnOff() { if (beacons_view != ToggleBeacons.isOn) { foreach (var b in locations[locations_index[active_location]].beacons.Values) b.beacon.SetActive(ToggleBeacons.isOn); beacons_view = ToggleBeacons.isOn; } } bool zones_view; public void ZonesOnOff() { if (zones_view != ToggleZones.isOn) { foreach (var z in locations[locations_index[active_location]].zones) z.go.SetActive(ToggleZones.isOn); zones_view = ToggleZones.isOn; } } void OnGUI() { //if (Input.GetKeyDown(KeyCode.BackQuote)) DebugHelper.DrawConsole(); } }