在我的 HoloLens 上显示数据时遇到问题
Having trouble with getting data to show up on my HoloLens
最近我一直在尝试以 JSON 的形式从外部来源获取一些数据。
我正在使用的库是 Newtonsoft.Json 的统一分支。当我 运行 我电脑上的项目时,它从外部源中提取数据,并将其转换为对象。我制作的 UI/text 元素应该显示从我的外部来源提取的数据,当我 运行 我的主计算机上的项目没有问题并且数据显示没有问题时,但是当我发送项目到我的 Hololens,我的调试器获取数据,我可以从字面上看到数据是从外部源提取的,但数据不会显示在 Hololens 上。谁能告诉我如何解决这个问题?
我的代码如下:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//using SimpleJSON;
using Newtonsoft.Json;
[System.Serializable]
public class TimeProperties
{
public string Year { get; set; }
public string Month { get; set; }
public string Day { get; set; }
public string Hour { get; set; }
public string Minutes { get; set; }
public string Seconds { get; set; }
}
[System.Serializable]
public class TimeClass
{
public TimeProperties Time { get; set; }
}
public class test : MonoBehaviour
{
string url = "http://172.16.24.135:8080";
public Text year;
public Text month;
public Text day;
public Text hour;
public Text minutes;
public Text seconds;
private void Start()
{
StartCoroutine(UpdateValues());
}
IEnumerator PullJsonData()
{
Debug.Log("entered");
WWW www = new WWW(url);
yield return www;
if(www.error != null)
{
print("There was an error getting the data: " + www.error);
yield break;
}
string jsonstring = www.text;
var data = JsonConvert.DeserializeObject<TimeClass>(jsonstring);
Debug.Log(data.Time.Seconds);
var jaren = data.Time.Year; //data["Year"].AsInt;
var maanden = data.Time.Month;//data["Month"].AsInt;
var dagen = data.Time.Day;//data["Day"].AsInt;
var uren = data.Time.Hour;//data["Hour"].AsInt;
var minuten = data.Time.Minutes;//data["Minutes"].AsInt;
var seconden = data.Time.Seconds;//data["Seconds"].AsInt;
year.text = "Year: " + jaren;
month.text = "Month: " + maanden;
day.text = "Days: " + dagen;
hour.text = "Hours: " + uren;
minutes.text = "Minutes: " + minuten;
seconds.text = "Seconds: " + seconden;
}
IEnumerator UpdateValues()
{
while (true)
{
StartCoroutine(PullJsonData());
yield return new WaitForSeconds(1);
}
}
}
我使用 "Release x86" 通过 Visual studio 代码 2017 将它发送到我的全息镜头。我还收到以下错误:
(Filename: 'C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)
Display is Transparent
(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)
There was an error getting the data:
(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)
Failed to get spatial stage statics - can't retrieve or interact with boundaries! Error code: '0x80040154'.
(Filename: C:\buildslave\unity\build\Runtime/VR/HoloLens/StageRoot.cpp Line: 20)
entered
(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)'
我每秒从我的外部源中提取我的 JSON 数据,所以在 运行 时间后的每一秒,这都会出现在我的调试中:
输入(这是 class pulljsondata() 中的 debug.log。
获取数据时出错:
(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)
我设法使一切正常。我的 UI 上没有显示任何内容的原因是因为我安装了 Unity 2017.3f1 和 Hololens 工具包以及来自 github(https://github.com/Microsoft/MixedRealityToolkit-Unity) 的 MixedRealityToolkit v2017.2.1.2。
我是如何让它工作的?
我删除了 Unity 2017.3f1 并安装了 Unity 2017.2.1f1 并安装了最新版本的 MixedRealityToolkit v2017.2.1.3。
重新安装后,我尝试获取带有一些元素的 canvas 和 运行,它从外部 URL 正确地提取了 json 数据。
最近我一直在尝试以 JSON 的形式从外部来源获取一些数据。 我正在使用的库是 Newtonsoft.Json 的统一分支。当我 运行 我电脑上的项目时,它从外部源中提取数据,并将其转换为对象。我制作的 UI/text 元素应该显示从我的外部来源提取的数据,当我 运行 我的主计算机上的项目没有问题并且数据显示没有问题时,但是当我发送项目到我的 Hololens,我的调试器获取数据,我可以从字面上看到数据是从外部源提取的,但数据不会显示在 Hololens 上。谁能告诉我如何解决这个问题?
我的代码如下:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//using SimpleJSON;
using Newtonsoft.Json;
[System.Serializable]
public class TimeProperties
{
public string Year { get; set; }
public string Month { get; set; }
public string Day { get; set; }
public string Hour { get; set; }
public string Minutes { get; set; }
public string Seconds { get; set; }
}
[System.Serializable]
public class TimeClass
{
public TimeProperties Time { get; set; }
}
public class test : MonoBehaviour
{
string url = "http://172.16.24.135:8080";
public Text year;
public Text month;
public Text day;
public Text hour;
public Text minutes;
public Text seconds;
private void Start()
{
StartCoroutine(UpdateValues());
}
IEnumerator PullJsonData()
{
Debug.Log("entered");
WWW www = new WWW(url);
yield return www;
if(www.error != null)
{
print("There was an error getting the data: " + www.error);
yield break;
}
string jsonstring = www.text;
var data = JsonConvert.DeserializeObject<TimeClass>(jsonstring);
Debug.Log(data.Time.Seconds);
var jaren = data.Time.Year; //data["Year"].AsInt;
var maanden = data.Time.Month;//data["Month"].AsInt;
var dagen = data.Time.Day;//data["Day"].AsInt;
var uren = data.Time.Hour;//data["Hour"].AsInt;
var minuten = data.Time.Minutes;//data["Minutes"].AsInt;
var seconden = data.Time.Seconds;//data["Seconds"].AsInt;
year.text = "Year: " + jaren;
month.text = "Month: " + maanden;
day.text = "Days: " + dagen;
hour.text = "Hours: " + uren;
minutes.text = "Minutes: " + minuten;
seconds.text = "Seconds: " + seconden;
}
IEnumerator UpdateValues()
{
while (true)
{
StartCoroutine(PullJsonData());
yield return new WaitForSeconds(1);
}
}
}
我使用 "Release x86" 通过 Visual studio 代码 2017 将它发送到我的全息镜头。我还收到以下错误:
(Filename: 'C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)
Display is Transparent
(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)
There was an error getting the data:
(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)
Failed to get spatial stage statics - can't retrieve or interact with boundaries! Error code: '0x80040154'.
(Filename: C:\buildslave\unity\build\Runtime/VR/HoloLens/StageRoot.cpp Line: 20)
entered
(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)'
我每秒从我的外部源中提取我的 JSON 数据,所以在 运行 时间后的每一秒,这都会出现在我的调试中: 输入(这是 class pulljsondata() 中的 debug.log。 获取数据时出错:
(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)
我设法使一切正常。我的 UI 上没有显示任何内容的原因是因为我安装了 Unity 2017.3f1 和 Hololens 工具包以及来自 github(https://github.com/Microsoft/MixedRealityToolkit-Unity) 的 MixedRealityToolkit v2017.2.1.2。 我是如何让它工作的? 我删除了 Unity 2017.3f1 并安装了 Unity 2017.2.1f1 并安装了最新版本的 MixedRealityToolkit v2017.2.1.3。 重新安装后,我尝试获取带有一些元素的 canvas 和 运行,它从外部 URL 正确地提取了 json 数据。