44 lines
1.0 KiB
C#
44 lines
1.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.UI;
|
|
|
|
public class OpenHabItemView : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private string itemUrl;
|
|
[SerializeField]
|
|
private Text text;
|
|
[SerializeField]
|
|
private float refreshInterval;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
CultureInfo.CurrentCulture = new CultureInfo("en-US");
|
|
StartCoroutine(LoadAndSet());
|
|
}
|
|
|
|
private IEnumerator LoadAndSet()
|
|
{
|
|
while (true)
|
|
{
|
|
var www = UnityWebRequest.Get(itemUrl);
|
|
yield return www.SendWebRequest();
|
|
if (!www.isNetworkError && !www.isHttpError)
|
|
{
|
|
float result = float.NaN;
|
|
if (float.TryParse(www.downloadHandler.text, out result))
|
|
{
|
|
text.text = string.Format("{0:F2}", result);
|
|
}
|
|
}
|
|
yield return new WaitForSeconds(refreshInterval);
|
|
}
|
|
}
|
|
|
|
}
|