将以下脚本添加到您的项目中,以扫描并创建或启动 id
为 Display0
的显示子系统。如果要加载其他显示子系统,可以更改 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>();
SubsystemManager.GetSubsystemDescriptors(displays);
Debug.Log("Number of display providers found: " + displays.Count);
foreach (var d in displays)
{
Debug.Log("Scanning display id: " + d.id);
if (d.id.Contains(match))
{
Debug.Log("Creating display " + d.id);
XRDisplaySubsystem dispInst = d.Create();
if (dispInst != null)
{
Debug.Log("Starting display " + d.id);
dispInst.Start();
}
}
}
}
}
XR Management 包是面向用户的 UI,用于在运行时配置子系统的加载。它使用相同的底层 API(如上所述)来创建和管理子系统。如果您希望提供程序显示在 XR Settings UI 中,请编写一个 XRLoader。
如果您的插件加载失败,请参阅下方的故障排除部分。
要对子系统提供程序的初始化或启动进行故障排除,请在编辑器日志或播放器输出日志中查找以 [XR]
或 [Subsystems]
开头的行。
如果您刚刚添加了 .json 和插件文件,请确保重新启动 Unity。目前,Unity 仅在启动时发现这些文件。另外,请确保提供程序使用正确的文件布局。
错误 | 描述 |
---|---|
[XR] 3 ‘displays’ descriptors matched in Assets/UnityXRDisplayExample/UnitySubsystemsManifest.json | Unity 成功找到了显示描述符并为此插件注册了三个不同的 ID。 |
[XR] No descriptors matched for inputs in Assets/UnityXRDisplayExample/UnitySubsystemsManifest.json. | .json 文件不包含输入描述符。如果您没有实现输入子系统,这是正常的。 如果您希望 Unity 在您的 .json 文件中找到描述符,则格式可能错误。请参阅有关 UnitySubsystemsManifest.json 的文档,使用正确的格式。 |
[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 方法的实现。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.