将 UWP 应用程序转换为适用于 HoloLens 的 Unity

Convert an UWP app to Unity for the HoloLens

我正在使用 HoloLens,我需要在其上安装 GPS。我成功地将我的 HoloLens 连接到蓝牙 GPS 接收器,我找到了一个项目,我可以使用它来读取 UWP 中的 GPS 数据 (project)。

我需要 Unity 中的 GPS 数据,所以我尝试将 UWP 代码转换为 Unity,但 Unity 没有例如 C# StreamSockets,...。

在 Unity 中使用特定 UWP 代码的最佳方式是什么?

您只需将平台指令 NETFX_CORE 放入您的脚本中:

#if NETFX_CORE
    using Windows.Networking.Sockets;
#endif

private void MyFunctionForHololens()
{
    #if NETFX_CORE
        // UWP code here using StreamSocket class
    #else
        // non-UWP core here (maybe some error message for platform not supported)
    #endif
}

Unity 的平台指令文档:https://docs.unity3d.com/Manual/PlatformDependentCompilation.html