c# - 在 Unity UWP 应用程序中找不到命名空间 'Windows'

标签 c# unity3d uwp namespaces assembly-references

我正在尝试在 Unity 中设置一个基本的 UWP 项目并使用部分 Windows 命名空间。* 但是,无论我尝试在我的脚本中导入 Windows namespace 的哪一部分,我总是得到

CS0246: The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?)

在 Visual Studio 和 Unity 中设置了对 Windows 和 UWP 的构建支持,并安装了 Windows 10 SDK (10.0.19041.0)。还有其他解决方法吗?

基于 https://forum.unity.com/threads/windows-storage-is-missing-when-building-for-uwp-hololens.541415/我会假设 Windows 在 UWP 的 Unity 中可用,因为他们能够在那里修复它?

谢谢


*从长远来看,我正在尝试使用“Windows.Devices.Input.Preview”在一个也使用 Vuforia 的项目中访问 Gaze Input,因此需要 UWP。也欢迎提供有关如何在 Unity 中结合注视跟踪和标记识别的其他技巧。

最佳答案

Unity 中的 Windows 命名空间仅适用于 Windows PC 构建。它不适用于其他系统。在脚本的顶部尝试添加一个

#if UNITY_STANDALONE_WIN

你应该像这样添加整个声明

#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
Use SpeechRecognitionEngine class

#endif

如果您正在为 android 或 ios 构建您还需要添加:

 #if UNITY_ANDROID  
Use SpeechRecognizer class

#endif

#if UNITY_IOS 使用 SFSpeechRecognizer 类 #endif

关于c# - 在 Unity UWP 应用程序中找不到命名空间 'Windows',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65117814/

相关文章:

Unity3D 包管理器/依赖管理器

c# - 如何在 Visual Studio 2017 中使用 SQLite?

c# - WPF/C# - 将日期格式应用于 ListView

c# - 泛型类型的显式和隐式转换

c# - unity2d : randomly change position of gameobject after it has been looped

unity3d - 在 Unity 编辑器中向对象添加图像

.net - 项目之间的 ListView 分隔符

c# - 如何在 Windows 10 uwp 中禁用 xaml 优化?

c# - Linq扩展方法,如何在集合递归中查找子项

c# - 我们可以在 mvvm 中应用存储过程吗?有道理的解释