123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- 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<uint, Load> load_location_elements = new Dictionary<uint, Load>(); // флаги загрузки элементов локации
- public bool load_location = false;
- public Dictionary<uint, Location> locations; // список локаций
- public Dictionary<uint, Dictionary<uint, User>> users; // список локаций
- public List<uint> locations_index; // сопоставление id с dropdown
- //public List<Marker> 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<PlayerController>();
- editor = Editor.GetComponent<EditorController>();
- client = Client.instance;
- DropdownCompany.options.Add(new Dropdown.OptionData("Тайшет"));
- DropdownCompany.options.Add(new Dropdown.OptionData("Тестовая"));
- DropdownCompany.options.Add(new Dropdown.OptionData("Братское"));
- locations = new Dictionary<uint, Location>();
- locations_index = new List<uint>();
- }
- // 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<Dropdown.OptionData>();
- 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<Image>().color = Color.green;
- else
- ButtonStatus.GetComponent<Image>().color = Color.red;
- }
- /// <summary>
- /// Удаление сотрудников из-за смены компании
- /// Отчистка Locations
- ///
- /// </summary>
- 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<uint, User>();
- //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<TouchScript>().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<uint, Beacon>();
- 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<BeaconController>().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();
- }
- }
|