Unity XR SDK 面向想要开发自己的与 Unity 一起使用的 XR 提供程序的专业用户。要下载 XR SDK,必须在此页上注册才能获取。
在 Unity 中,XR SDK 包允许多个后端(称为“提供程序”)来实现单个引擎功能(称为“子系统”)。用户应用程序可以在运行时选择和激活提供程序。
单个子系统包含:
子系统描述符是关于子系统的元数据,可以在加载或初始化子系统之前对其进行检查。这来自清单文件并通过 C# 接口访问。Create
方法激活子系统并将它的一个实例提供给用户的脚本。
For more information, see the Runtime discovery and activation of subsystems page.
当在子系统描述符上调用 Create
时,会创建一个子系统实例。脚本代码与这些实例交互以与子系统通信。子系统本身有自己的生命周期:它可以启动、停止和关闭。
提供程序是子系统的原生实现。一个子系统可以有多个提供程序。某些子系统可以允许多个提供程序同时处于活动状态,但另一些子系统可能是互斥的。
提供程序符合 Unity 原生插件接口,在此基础上构建了一些额外的生命周期支持。入口点是 UnityPluginLoad
方法。从那里,提供程序必须向它要实现的所有子系统注册。
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API
UnityPluginLoad(IUnityInterfaces* unityInterfaces)
{
s_XrDisplay = unityInterfaces->Get<IUnityXRDisplayInterface>();
UnityLifecycleProvider displayLifecycleHandler =
{
NULL, // 这可以是要以 userData 形式传递给以下函数的任何对象
&Lifecycle_Initialize,
&Lifecycle_Start,
&Lifecycle_Stop,
&Lifecycle_Shutdown
};
s_XrDisplay->RegisterLifecycleProvider("Provider Plugin Name", "Display0", &displayLifecycleHandler);
// 注册其他子系统
}
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.