using System;
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 static EditorController instance;
public InputField Name;
public InputField Image;
public InputField SizeX;
public InputField SizeY;
public GameObject BeaconsContent;
public GameObject PanelBeaconEdit;
public GameObject Player;
public GameObject ButtonMode;
public GameObject EditorTools;
public Toggle ToggleScalePanel;
public Toggle projection;
public Dropdown DropdownLocation;
public Transform Locations;
public Button ButtonAddBeacon;
public GameObject Dialog;
public GameObject NewLocation;
public GameObject plane;
public Location newLocation;
public Dictionary> Beacons = new Dictionary>();
CompanyController company;
ModeController mode;
ToolsController tools;
public Location EditLocation;
private void Awake()
{
instance = this;
}
// Start is called before the first frame update
void Start()
{
company = CompanyController.instance;
mode = ButtonMode.GetComponent();
tools = EditorTools.GetComponent();
ButtonAddBeacon.onClick.AddListener(() => {
AddBeacon(company);
});
var random = new System.Random();
int number = random.Next(2000000000, Int32.MaxValue);
uint uintNumber = (uint)(number + (uint)Int32.MaxValue);
if (NewLocation == null)
{
NewLocation = new GameObject();
NewLocation.transform.SetParent(Locations);
NewLocation.name = "NewLocation";
NewLocation.transform.position = Vector3.zero;
NewLocation.SetActive(false);
plane = Instantiate(Resources.Load("GameObjects/Plane", typeof(GameObject))) as GameObject;
plane.transform.SetParent(NewLocation.transform);
plane.transform.position = new Vector3(plane.transform.localScale.x * 5, 0, plane.transform.localScale.z * 5);
foreach (var g in Location.contents)
{
var go = new GameObject();
go.name = g;
go.transform.SetParent(NewLocation.transform);
}
newLocation = new Location
{
id = uintNumber,
location = NewLocation,
walls = new List(),
zones = new List(),
beacons = new List(),
plane = plane,
texture_url = ""
};
company.locations[newLocation.id] = newLocation;
company.locations_index.Add(newLocation.id);
DropdownLocation.options.Add(new Dropdown.OptionData("Новая локация"));
DropdownLocation.RefreshShownValue();
}
}
// Update is called once per frame
void Update()
{
if (projection.isOn)
{
Camera.main.orthographic = true;
}
else
{
Camera.main.orthographic = false;
}
}
string texture_url = "";
///
/// Изменение размеров панели
/// Загрузка текстуры
///
public void UpdatePanel()
{
var p = company.locations[company.locations_index[company.active_location]].plane;
if (!Image.text.Equals(texture_url))
{
StartCoroutine(SendingFormController.LoadImage(Image.text, p));
texture_url = Image.text;
}
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);
p.transform.localScale = new Vector3(x, 1, y);
var scale = p.transform.localScale;
p.transform.position = new Vector3(scale.x * 5, 0, scale.z * 5);
}
public void Save()
{
//SceneManager.LoadScene("Location");
tools.CursorOff();
if (!Name.text.Equals(""))
{
//var location = new Location { id = 0, name = Name.text, beacons = Beacons, zones = WallCreate.Zones, walls = WallCreate.Walls, texture_url = Image.text, plane = plane, location = NewLocation};
Location location;
if (EditLocation.id != 0) location = EditLocation;
else location = new Location { id = Convert.ToUInt32(4000000000), plane = plane, location = NewLocation };
location.name = Name.text;
location.texture_url = Image.text;
if (WallCreate.Walls.ContainsKey(EditLocation.id)) location.walls.AddRange(WallCreate.Walls[EditLocation.id]);
//if (WallCreate.Zones.ContainsKey(EditLocation.id)) location.zones.AddRange(WallCreate.Zones[EditLocation.id]);
if (WallCreate.Zones.ContainsKey(EditLocation.id)) location.zones = WallCreate.Zones[EditLocation.id];
if (Beacons.ContainsKey(EditLocation.id))
{
foreach(var b in Beacons[EditLocation.id])
{
var go = b.beacon;
b.x = go.transform.position.x;
b.y = go.transform.position.z;
b.z = go.transform.position.y;
}
location.beacons.AddRange(Beacons[EditLocation.id]);
}
company.DropdownLocation.options.Last().text = location.name;
location.location.name = location.name;
location.Save();
location.SaveContents();
mode.Switch();
}
else
{
Dialog.SetActive(true);
Dialog.transform.GetChild(0).GetComponent().text = "Введите название локации";
Dialog.transform.GetChild(2).GetComponent