【问题标题】:Namespace 'Windows' not found in Unity UWP app在 Unity UWP 应用程序中找不到命名空间“Windows”
【发布时间】:2021-03-14 23:40:59
【问题描述】:

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

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 在 Unity for UWP 中可用,因为他们能够在那里修复它?

谢谢


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

【问题讨论】:

    标签: c# unity3d uwp namespaces assembly-references


    【解决方案1】:

    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

    【讨论】:

    • 它是为 UWP 构建的,所以没有 iOS/Android,但它需要在 UWP 上运行。不幸的是,通过忽略独立之外的代码来修复错误消息无济于事。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-18
    • 1970-01-01
    • 2018-02-26
    • 2019-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多