123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- using Assets.Scripts.Models;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Runtime.InteropServices;
- using Unity.VectorGraphics;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class SendingFormController : MonoBehaviour
- {
- static string uuid = "07a13c8907d1-6a7bdba1-a2fz-aatgu4j";
- public static string url;
-
-
- void Start()
- {
-
-
-
- }
-
- void Update()
- {
- }
-
- IEnumerator PostRequest(string url, string json)
- {
- var uwr = new UnityWebRequest(url, "POST");
- byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes(json);
- uwr.uploadHandler = (UploadHandler)new UploadHandlerRaw(jsonToSend);
- uwr.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
- uwr.SetRequestHeader("Content-Type", "application/json");
-
- yield return uwr.SendWebRequest();
- if (uwr.isNetworkError)
- {
- Debug.Log("Error While Sending: " + uwr.error);
- }
- else
- {
- Debug.Log("Received: " + uwr.downloadHandler.text);
- }
- }
-
-
-
- public static IEnumerator RequestRoutine(string url, Action<string> callback = null)
- {
-
- var request = UnityWebRequest.Get(url);
-
- yield return request.SendWebRequest();
- var data = request.downloadHandler.text;
-
-
- if (callback != null)
- callback(data);
- }
-
- private void ResponseCallback(string data)
- {
- Debug.Log(data);
- }
-
-
-
-
-
-
-
-
-
- public static IEnumerator LoadImage(string url, GameObject plane, Vector3 pos = new Vector3(), Vector3 scale = new Vector3(), Action<float, float> callback = null)
- {
-
-
-
-
-
-
-
-
- using (UnityWebRequest img = UnityWebRequestTexture.GetTexture(url))
- {
-
-
- img.SetRequestHeader("Access-Control-Allow-Credentials", "true");
- img.SetRequestHeader("Access-Control-Allow-Headers", "Accept, X-Access-Token, X-Application-Name, X-Request-Sent-Time");
- img.SetRequestHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
- img.SetRequestHeader("Access-Control-Allow-Origin", "*");
- yield return img.SendWebRequest();
- if (img.isNetworkError || img.isHttpError)
- {
- Debug.Log(img.error);
- }
- else
- {
- var texture = DownloadHandlerTexture.GetContent(img);
- Renderer renderer = plane.GetComponent<Renderer>();
- renderer.material.mainTexture = texture;
- if (scale.x == 0 && scale.z == 0)
- {
- plane.transform.localScale = new Vector3(texture.width / 1000f, 1, texture.height / 1000f);
- scale = plane.transform.localScale;
- }
- else plane.transform.localScale = scale;
- if (pos.x == 0 && pos.z == 0)
- plane.transform.position = new Vector3(scale.x * 5, 0, scale.z * 5);
- else plane.transform.position = pos;
- callback?.Invoke(scale.x, scale.z);
- }
- }
- }
-
- }
|