91 lines
3.0 KiB
C#
91 lines
3.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
using Newtonsoft.Json.Linq;
|
|
using static InterfaceManager;
|
|
using System;
|
|
|
|
public class InterfaceTest : MonoBehaviour
|
|
{
|
|
public string url;
|
|
public string[] query;
|
|
public string[] query_value;
|
|
|
|
public string post_json;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
//Debug.Log("{\n \"base_url\": \"https://10.7.6.50:8080\",\n \"battery\": 0,\n \"current_mapname\": \"/home/cruiser/ros_ws/install/share/cruiser_navigation/maps/CWDT010@20231122_111258\",\n \"current_pose\": {\n \"id\": \"e5691290-8b71-48db-991d-c6b503def8b4\",\n \"theta\": 1.7360243797302246,\n \"x\": 5.016031742095947,\n \"y\": -2.2412776947021484\n },\n \"mode\": \"navigation\",\n \"name\": null,\n \"robotId\": \"56ce6c39b8144d91ac3767e757933955\",\n \"status\": null,\n \"system_status\": \"Healthy;\",\n \"system_status_code\": 0\n}");
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (Input.GetKeyUp(KeyCode.G))
|
|
{
|
|
//²âÊÔ
|
|
//if (query != null && query_value != null)
|
|
//{
|
|
// var dic = new Dictionary<string, string>();
|
|
// for (int i = 0; i < query.Length; i++)
|
|
// {
|
|
// if (query_value.Length > i)
|
|
// {
|
|
// dic.Add(query[i], query_value[i]);
|
|
// }
|
|
// }
|
|
// StartCoroutine(GetRequest(url, null, dic, (_data) =>
|
|
// {
|
|
// Debug.Log(_data);
|
|
// }));
|
|
//}
|
|
|
|
if (query != null && query_value != null)
|
|
{
|
|
var dic = new Dictionary<string, string>();
|
|
for (int i = 0; i < query.Length; i++)
|
|
{
|
|
if (query_value.Length > i)
|
|
{
|
|
dic.Add(query[i], query_value[i]);
|
|
}
|
|
}
|
|
StartCoroutine(GetRequest(url, new Dictionary<string, string>() { { "Authorization", "none" } }, dic, (_error, _data) =>
|
|
{
|
|
Debug.Log(_data);
|
|
}));
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (Input.GetKeyUp(KeyCode.P))
|
|
{
|
|
StartCoroutine(PostRequest(url, post_json, new Dictionary<string, string>() { { "Authorization", "none" } }, (_error, _data) =>
|
|
{
|
|
Debug.Log(_data);
|
|
}));
|
|
}
|
|
|
|
|
|
if (Input.GetKeyUp(KeyCode.Q))
|
|
{
|
|
Tex();
|
|
}
|
|
}
|
|
|
|
public string _data;
|
|
public UnityEngine.UI.Image image;
|
|
public void Tex()
|
|
{
|
|
byte[] bytes = Convert.FromBase64String(_data);
|
|
Texture2D text2D = new Texture2D(100, 100);
|
|
text2D.LoadImage(bytes);
|
|
Sprite sprite = Sprite.Create(text2D, new Rect(0, 0, text2D.width, text2D.height), new Vector2(0.5f, 0.5f));
|
|
//_callback?.Invoke(null, sprite);
|
|
image.sprite = sprite;
|
|
}
|
|
}
|