UI Values Added

This commit is contained in:
ZeinabBF 2024-05-16 15:04:49 +02:00
parent 94ea1c7770
commit 33ae5c7ba5
3 changed files with 174 additions and 0 deletions
Assets/SharedSpatialAnchors

@ -3626,6 +3626,17 @@ BoxCollider:
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &912202276 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 5963783328903625539, guid: b49f2be068ab7e74284fd7900d48ee67, type: 3}
m_PrefabInstance: {fileID: 5963783329142366567}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &947450794
GameObject:
m_ObjectHideFlags: 0
@ -4095,6 +4106,17 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1038098150}
m_CullTransparentMesh: 1
--- !u!114 &1065765538 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 5963783329049947077, guid: b49f2be068ab7e74284fd7900d48ee67, type: 3}
m_PrefabInstance: {fileID: 5963783329142366567}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1109088824
GameObject:
m_ObjectHideFlags: 0
@ -9307,6 +9329,34 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 5963783328903625539, guid: b49f2be068ab7e74284fd7900d48ee67, type: 3}
propertyPath: m_text
value:
objectReference: {fileID: 0}
- target: {fileID: 5963783329065507781, guid: b49f2be068ab7e74284fd7900d48ee67, type: 3}
propertyPath: m_Color.a
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5963783329065507781, guid: b49f2be068ab7e74284fd7900d48ee67, type: 3}
propertyPath: m_Color.b
value: 0.7254902
objectReference: {fileID: 0}
- target: {fileID: 5963783329065507781, guid: b49f2be068ab7e74284fd7900d48ee67, type: 3}
propertyPath: m_Color.g
value: 0.2901961
objectReference: {fileID: 0}
- target: {fileID: 5963783329065507781, guid: b49f2be068ab7e74284fd7900d48ee67, type: 3}
propertyPath: m_Color.r
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5963783330193271202, guid: b49f2be068ab7e74284fd7900d48ee67, type: 3}
propertyPath: windDirValue
value:
objectReference: {fileID: 1065765538}
- target: {fileID: 5963783330193271202, guid: b49f2be068ab7e74284fd7900d48ee67, type: 3}
propertyPath: temperatureValue
value:
objectReference: {fileID: 912202276}
- target: {fileID: 5963783330193271203, guid: b49f2be068ab7e74284fd7900d48ee67, type: 3}
propertyPath: m_Pivot.x
value: 0
@ -9395,6 +9445,10 @@ PrefabInstance:
propertyPath: m_Name
value: Curved Canvas
objectReference: {fileID: 0}
- target: {fileID: 5963783330639515977, guid: b49f2be068ab7e74284fd7900d48ee67, type: 3}
propertyPath: m_text
value: Kista
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: b49f2be068ab7e74284fd7900d48ee67, type: 3}
--- !u!4 &7079690333416248134 stripped

@ -0,0 +1,109 @@
using OVRSimpleJSON;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
// Creating the data structure according to the expected Json
[Serializable]
public class DataPoint
{
public string name;
public string levelType;
public int level;
public string unit;
public List<float> values;
}
[Serializable]
public class DataPerHour
{
public string validTime;
public List<DataPoint> parameters;
}
[Serializable]
public class ApiResponse
{
public string approvedTime;
public string referenceTime;
public string geometry;
public List<DataPerHour> timeSeries;
}
public class API : MonoBehaviour
{
public TextMeshProUGUI windDirValue;
public TextMeshProUGUI temperatureValue;
private float LatestT;
private float latestWD;
private string unit;
void Start()
{
//TestFromJsonToData();
StartCoroutine(GetText());
}
IEnumerator GetText()
{
UnityWebRequest www = UnityWebRequest.Get("https://opendata-download-metanalys.smhi.se/api/category/mesan2g/version/1/geotype/point/lon/17.94/lat/59.40/data.json");
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
Debug.Log(www.error);
}
else
{
Debug.Log("Received data" + www.downloadHandler.text);
ExtractDataFromJson(www.downloadHandler.text);
}
}
public void TestFromJsonToData()
{
string testJson = "{\r\n \"name\": \"t\",\r\n \"levelType\": \"hl\",\r\n \"level\": 2,\r\n \"unit\": \"Cel\",\r\n \"values\": [\r\n 21.3\r\n ]\r\n }";
DataPoint dataTurbine = JsonUtility.FromJson<DataPoint>(testJson);
//Debug.Log(dataTurbine.name);
//Debug.Log(dataTurbine.values[0]);
}
public void ExtractDataFromJson(string json)
{
ApiResponse response = JsonUtility.FromJson<ApiResponse>(json);
//Debug.Log("Api response worked!!!!");
//Access the latest hour
DataPerHour timeResponse = response.timeSeries[0];
List<DataPoint> dataPoints = timeResponse.parameters;
//Debug.Log("Total number of data points: " + dataPoints.Count);
//Find the value of WD in the latest hour
for (int i = 0; i < dataPoints.Count; i++)
{
DataPoint point = dataPoints[i];
if (point.name == "t")
{
LatestT = point.values[0];
unit = point.unit;
temperatureValue.SetText(LatestT.ToString()+ " "+ unit);
}
if (point.name == "wd")
{
latestWD = point.values[0];
windDirValue.SetText(latestWD.ToString());
}
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e7233e77bd50673459b9746b72155a35
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: