using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using UnityEngine.Networking; using Newtonsoft.Json; using UnityEngine.UIElements; public class ThanksStASSForTheNiceMethod : MonoBehaviour { [Header("Ссылка на метод и авторизация")] public string URL; public string Auth; [Header("Листы с данными")] public List LocationsMO; //Точки МО public List LocationsRTLS; //Точки РТЛС public List BlockNamesAliases; //Название отметок public List Time; //Время public List MarksTime; [Header("UIDocument")] public UIDocument UI; [Header("Экран с перемещением")] public VisualTreeAsset GameUIPrefab; //Экран с перещением [Header("ИИ")] public PersonScript Personchikn; // ИИ [Header("Скрипт выполняющий запрос")] public Uiika UIka; public void Request() { GenerateRequest(); } public void ClearList() //Очистка данных { LocationsMO.Clear(); LocationsRTLS.Clear(); BlockNamesAliases.Clear(); Time.Clear(); MarksTime.Clear(); } void GenerateRequest() //Генерация запроса { StartCoroutine(ProcessRequest(URL)); } private IEnumerator ProcessRequest(string uri) { using (UnityWebRequest request = UnityWebRequest.Get(uri)) { //request.SetRequestHeader("Authorization", Auth); //request.SetRequestHeader("Access-Control-Allow-Origin", "*"); request.timeout = 60; yield return request.SendWebRequest(); if (request.result != UnityWebRequest.Result.Success) { Debug.Log("Error: " + request.error); UIka.RequestButton.SetEnabled(true); UIka.forcodes.visible = true; UIka.forcodes.text = "В данный момент сервис временно недоступен."; UIka.loadimg.visible = false; } else { Debug.Log("Received: " + request.downloadHandler.text); var MethodJSON = JsonConvert.DeserializeObject(request.downloadHandler.text); try { foreach (Item x in MethodJSON.respose.items) //Парсинг данных { LocationsMO.Add(new Vector3(x.x_mo, x.z_mo, x.y_mo)); LocationsRTLS.Add(new Vector3(x.x, x.z, x.y)); Time.Add(x.time.ToLocalTime().ToString()); if (x.block_names_aliases.Count > 1) { BlockNamesAliases.Add(x.block_names_aliases[0] + " " + x.block_names_aliases[1]); } else { BlockNamesAliases.Add(x.block_names_aliases[0]); } UIka.SetResponseCode(request.responseCode.ToString()); } } catch (NullReferenceException) { Debug.Log("ItemsNull"); UIka.loadimg.visible = false; } try { foreach (MarksTime y in MethodJSON.respose.marks_time) { MarksTime.Add(y.name + "!" + y.count_seconds); } } catch (NullReferenceException) { Debug.Log("MarksTimeNull"); UIka.loadimg.visible = false; } if (LocationsMO.Count > 1) { Debug.Log("No problemo"); UIka.SetResponseCode(request.responseCode.ToString()); //Установка кода UI.visualTreeAsset = GameUIPrefab; //Установка экрана для перемещения Personchikn.InitMePlease(); //Вызов инициализация в ИИ Debug.Log("Got data, here go"); } else { UIka.RequestButton.SetEnabled(true); UIka.forcodes.visible = true; UIka.forcodes.text = "В данных обнаружена ошибка."; UIka.forcodes.text = MethodJSON.error; UIka.loadimg.visible = false; } } } } }