【问题标题】:Having trouble with getting data to show up on my HoloLens无法让数据显示在我的 HoloLens 上
【发布时间】:2018-03-09 15:36:56
【问题描述】:

最近我一直在尝试以 JSON 的形式从外部源获取一些数据。 我使用的库是 Newtonsoft.Json 的统一分支。当我在我的计算机上运行该项目时,它会从外部源中提取数据,并将其转换为一个对象。我制作的 UI/文本元素应该显示从我的外部源提取的数据,当我在我的主计算机上运行项目时它没有问题并且数据显示没有问题,但是当我将项目发送到我的 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 Code 2017 将它发送到我的 hololens。我还收到以下错误:

(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 数据,因此在运行后的每一秒,这都会显示在我的调试中: 输入(这是类 pulljsondata() 中的 debug.log)。 获取数据时出错:

(Filename: C:\buildslave\unity\build\artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)

【问题讨论】:

  • 首先,该端点可用于 Hololens,对吗?其次,您是否检查了 Internet 客户端功能?
  • 我确实检查了客户端功能,对于端点,您的意思是这样的:docs.unity3d.com/ScriptReference/…?我可以看到数据是从我在 hololens 上的外部 URL 中提取的,当我在我的计算机上启动它时它可以正常工作,但是在我设置的 ui/text 元素上的 hololens 上没有显示任何内容
  • 我认为这可能是导致问题的WWW 类。我在我的一个项目中使用了它,但是,它仅用于从 HoloLens 获取本地保存的文件。但是,由于某种原因,它不会在协程内执行WWW。相反,我只是调用了一次,我没有遇到任何问题。可能只是因为我正在访问本地数据。你的jsonString 是空的吗?
  • 我回去工作后再打印出来

标签: json debugging unity3d json.net hololens


【解决方案1】:

我设法让一切正常。我的 UI 上没有显示任何内容的原因是因为我安装了带有 Hololens 工具包的 Unity 2017.3f1 和来自 github(https://github.com/Microsoft/MixedRealityToolkit-Unity) 的 MixedRealityToolkit v2017.2.1.2。 我是如何设法让它工作的? 我删除了 Unity 2017.3f1 并安装了 Unity 2017.2.1f1 并安装了最新版本的 MixedRealityToolkit v2017.2.1.3。 重新安装后,我尝试启动并运行包含一些元素的画布,它正确地从外部 URL 提取 json 数据。

【讨论】:

    猜你喜欢
    • 2013-12-03
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2014-12-19
    • 2020-01-03
    • 1970-01-01
    • 2020-04-08
    • 1970-01-01
    相关资源
    最近更新 更多