将以下脚本添加到您的项目中,以扫描并创建或启动 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();
}
}
}
}
}
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]
开头的行。
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.
错误 | 描述 |
---|---|
[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 方法的实现。 |
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.