Version: 2022.3
XR SDK 输入子系统


将以下脚本添加到您的项目中,以扫描并创建或启动 idDisplay0 的显示子系统。如果要加载其他显示子系统,可以更改 match 变量:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.XR;
using UnityEngine.XR;

public class Display : MonoBehaviour
    public string match = "Display0";

    // Use this for initialization
    void Start ()
        List<XRDisplaySubsystemDescriptor> displays = new List<XRDisplaySubsystemDescriptor>();
        Debug.Log("Number of display providers found: " + displays.Count);

        foreach (var d in displays)
            Debug.Log("Scanning display id: " +;

            if (
                Debug.Log("Creating display " +;
                XRDisplaySubsystem dispInst = d.Create();

                if (dispInst != null)
                    Debug.Log("Starting display " +;

The XR Management package is the user-facing UI used to configure loading of subsystems at runtime. It uses the same underlying APIs (described above) to create and manage subsystems. If you want your provider to show up in the XR Settings UI, write an XRLoader.



要对子系统提供程序的初始化或启动进行故障排除,请在编辑器日志或播放器输出日志中查找以 [XR][Subsystems] 开头的行。

在 C# 中找不到子系统

If you just added a .json and plug-in files, make sure you relaunch Unity. Currently, Unity only discovers these files at start-up. Also, make sure that the Provider uses the correct file layout.

UnitySubsystemsManifest.json 文件的错误查找和解析

错误 描述
[XR] 3 ‘displays’ descriptors matched in Assets/UnityXRDisplayExample/UnitySubsystemsManifest.json Unity 成功找到了显示描述符并为此插件注册了三个不同的 ID。
[XR] No descriptors matched for inputs in Assets/UnityXRDisplayExample/UnitySubsystemsManifest.json. The .json file contains no input descriptors. This is normal if you’re not implementing an input subsystem.
If you were expecting Unity to find descriptors in your .json file, they could be malformed. See documentation on UnitySubsystemsManifest.json for the correct format to use.
[XR] Failed to parse json header for Assets/UnityXRDisplayExample/UnitySubsystemsManifest.json (did you forget to include name or libraryName fields?) 这可能意味着您的 .json 文件格式不正确。通过验证工具(如json linter)运行该文件。


错误 描述
[XR] PluginName failed to register Provider for DisplayId (json name or id doesn’t match?) 这意味着 RegisterLifecycleProvider 的前两个参数与 .json 文件不匹配。
第一个参数 pluginName 应该与 .json 文件中的 name 字段匹配。
第二个参数 id 应该与 .json 文件中子系统的 id 字段匹配。
[XR] Unable to load plugin PluginName for subsystem DisplayId 找不到您的插件,它是为错误的架构构建的,或者缺少需要加载的依赖项。在后一种情况下,您可以使用 Dependency Walker 工具来确定是否缺少依赖项。


错误 描述
[XR] Failed to initialize subsystem DisplayId [error: 1] Unity 调用了您的 Initialize 方法,但它返回了 kUnitySubsystemErrorCodeFailure。仔细检查您的 Initialize 方法的实现。
XR SDK 输入子系统