189 lines
6.5 KiB
C#
189 lines
6.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System;
|
|
using UnityEngine.Networking;
|
|
using Newtonsoft.Json;
|
|
using UnityEngine.UIElements;
|
|
//using UnityEngine.Analytics;
|
|
|
|
|
|
public struct TagRecord
|
|
{
|
|
public String Time;
|
|
public String BlockNamesAliases;
|
|
public Vector3 LocationsMO;
|
|
public Vector3 LocationsRTLS;
|
|
}
|
|
|
|
public class ThanksStASSForTheNiceMethod : MonoBehaviour
|
|
{
|
|
[Header("Ññûëêà íà ìåòîä è àâòîðèçàöèÿ")]
|
|
public string URL;
|
|
public string Auth;
|
|
[Header("Ëèñòû ñ äàííûìè")]
|
|
public SortedDictionary<DateTime, TagRecord> mapDateTimeRecords = new SortedDictionary<DateTime, TagRecord>();
|
|
public List<String> MarksTime = new List<string>();
|
|
public List<MarkItem> MarksHronology;
|
|
//public List<Vector3> LocationsMO; //Òî÷êè ÌÎ
|
|
//public List<Vector3> LocationsRTLS; //Òî÷êè ÐÒËÑ
|
|
//public List<String> BlockNamesAliases; //Íàçâàíèå îòìåòîê
|
|
|
|
|
|
[Header("UIDocument")]
|
|
public UIDocument UI;
|
|
[Header("Ýêðàí ñ ïåðåìåùåíèåì")]
|
|
public VisualTreeAsset GameUIPrefab; //Ýêðàí ñ ïåðåùåíèåì
|
|
[Header("ÈÈ")]
|
|
public PersonScript Personchikn; // ÈÈ
|
|
[Header("Ñêðèïò âûïîëíÿþùèé çàïðîñ")]
|
|
public Uiika UIka;
|
|
|
|
public void Request()
|
|
{
|
|
GenerateRequest();
|
|
|
|
}
|
|
public void ClearList() //Î÷èñòêà äàííûõ
|
|
{
|
|
mapDateTimeRecords.Clear();
|
|
}
|
|
|
|
void GenerateRequest() //Ãåíåðàöèÿ çàïðîñà
|
|
{
|
|
//StartCoroutine(SpawnTestItems());
|
|
StartCoroutine(ProcessRequest(URL));
|
|
}
|
|
private IEnumerator SpawnTestItems()
|
|
{
|
|
string uri = "http://localhost:8001/api/v2/marks/getMarksLabelsByArrPoints";
|
|
|
|
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)
|
|
{
|
|
var responseObject = JsonConvert.DeserializeObject<Assets.Scripts.API.MTEGetMarksLabelsByArrPoint.ApiResponse>(request.downloadHandler.text);
|
|
try
|
|
{
|
|
foreach (var item in responseObject.respose.items)
|
|
{
|
|
Vector3 pos = new Vector3(item.center_point.x, item.center_point.z, item.center_point.y);
|
|
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
|
|
|
sphere.transform.position = pos;
|
|
// Ñîçäàíèå ìàòåðèàëà
|
|
Material redMaterial = new Material(Shader.Find("Standard"));
|
|
redMaterial.color = Color.red;
|
|
|
|
// Ïðèìåíåíèå ìàòåðèàëà ê ñôåðå
|
|
sphere.GetComponent<Renderer>().material = redMaterial;
|
|
|
|
}
|
|
} catch (Exception e)
|
|
{
|
|
Debug.LogException(e);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Received: " + request.downloadHandler.text);
|
|
}
|
|
}
|
|
}
|
|
|
|
private IEnumerator ProcessRequest(string uri)
|
|
{
|
|
|
|
//Analytics.CustomEvent("check_uri", new Dictionary<string, object>
|
|
//{
|
|
// { "level", 1 },
|
|
// { "player_name", "Player1" }
|
|
//});
|
|
|
|
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.DoActionsOnRequestFailed(request.error);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Received: " + request.downloadHandler.text);
|
|
var MethodJSON = JsonConvert.DeserializeObject<MethodJSON>(request.downloadHandler.text);
|
|
try
|
|
{
|
|
foreach (Item tagItem in MethodJSON.respose.items) //Ïàðñèíã äàííûõ
|
|
{
|
|
TagRecord record = new TagRecord();
|
|
record.LocationsMO = new Vector3(tagItem.x_mo, tagItem.z_mo, tagItem.y_mo);
|
|
record.LocationsRTLS = new Vector3(tagItem.x, tagItem.z, tagItem.y);
|
|
record.Time = tagItem.time.ToLocalTime().ToString();
|
|
|
|
if (tagItem.block_names_aliases.Count > 1)
|
|
{
|
|
record.BlockNamesAliases = tagItem.block_names_aliases[0] + " " + tagItem.block_names_aliases[1];
|
|
}
|
|
else
|
|
{
|
|
record.BlockNamesAliases = tagItem.block_names_aliases[0];
|
|
}
|
|
|
|
mapDateTimeRecords.Add(tagItem.time, record);
|
|
}
|
|
UIka.SetResponseCode(request.responseCode.ToString());
|
|
|
|
}
|
|
catch (NullReferenceException)
|
|
{
|
|
Debug.Log("ItemsNull");
|
|
//UIka.loadimg.visible = false;
|
|
UIka.DoActionsOnRequestFailed("Äàííûõ çà ïåðèîä íåò");
|
|
}
|
|
|
|
try
|
|
{
|
|
foreach (MarksTime mark in MethodJSON.respose.marks_time)
|
|
{
|
|
MarksTime.Add(mark.name + "!" + mark.count_seconds);
|
|
}
|
|
}
|
|
catch (NullReferenceException)
|
|
{
|
|
Debug.Log("MarksTimeNull");
|
|
UIka.DoActionsOnRequestFailed("Îøèáêà ïîëó÷åíèÿ äàííûõ");
|
|
}
|
|
|
|
MarksHronology = MethodJSON.respose.marks_hronology;
|
|
|
|
if (mapDateTimeRecords.Count > 1)
|
|
{
|
|
Debug.Log("No problemo");
|
|
UIka.SetResponseCode(request.responseCode.ToString()); //Óñòàíîâêà êîäà
|
|
Personchikn.InitMePlease(); //Âûçîâ èíèöèàëèçàöèÿ â ÈÈ
|
|
UIka.DoActionsOnRequestSuccess();
|
|
Debug.Log("Got data, here go");
|
|
}
|
|
else
|
|
{
|
|
UIka.DoActionsOnRequestFailed("Íåò äàííûõ çà çàïðàøèâàåìûé ïåðèîä");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|