unity-xr
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBefore calling any skill in this module: if you are about to call a skill with parameters guessed from its name or description, STOP — read this file (or fetch its schema via) first. If you already have the parameter definitions from recommend/schema, you may proceed straight to dryRun.GET /skills/recommend?includeSchema=true
调用本模块中的任何技能之前: 如果您打算根据技能名称或描述猜测参数来调用技能,请停止操作——先阅读本文档(或通过获取其 schema)。如果您已经从推荐/schema中获取了参数定义,则可以直接进行dryRun。GET /skills/recommend?includeSchema=true
Triggers
触发场景
- Building VR/AR interaction
- Setting up an XR rig
- Configuring grab/socket/ray interactors
- 构建 VR/AR 交互、搭建 XR rig、配置抓取/插槽/射线交互器
- 构建VR/AR交互
- 搭建XR rig
- 配置抓取/插槽/射线交互器
- 构建 VR/AR 交互、搭建 XR rig、配置抓取/插槽/射线交互器
Unity XR Interaction Toolkit Skills
Unity XR Interaction Toolkit 技能
Use this module for XR Interaction Toolkit setup and configuration. All skills are reflection-based and support XRI 2.x on Unity 2022 and XRI 3.x on Unity 6+.
xr_*Requires:. Hard rule: Read this file before the firstcom.unity.xr.interaction.toolkitcall in a session. Wrong property names can fail silently because the bridge is reflection-based.xr_*
本模块用于XR Interaction Toolkit的设置与配置。所有技能均基于反射实现,支持Unity 2022上的XRI 2.x版本以及Unity 6+上的XRI 3.x版本。
xr_*依赖要求:。 硬性规则:在会话中首次调用com.unity.xr.interaction.toolkit技能前,请阅读本文档。由于桥接层基于反射实现,错误的属性名称可能会导致静默失败。xr_*
Guardrails
防护规则
Operating Mode (v1.9 three-tier):
- Approval (default): query/list/info skills (,
xr_check_setup,xr_get_scene_report,xr_list_interactors) run directly. Create/modify skills are FullAuto — onxr_list_interactables, run the grant protocol; a successfulMODE_RESTRICTEDexecutes the skill server-side and returns the result in the same response./permission/grant - Auto / Bypass: SemiAuto and FullAuto run directly.
- This module contains no Delete / PlayMode / Reload / skills, so nothing is auto-classified as forbidden — every skill is reachable via grant.
RiskLevel="high" - When is missing, every
com.unity.xr.interaction.toolkitskill returns thexr_*install instruction instead of executing.NoXRI() - Reflection-sensitive: property names on XRI components must match XRI 2.x/3.x exactly. A wrong field name on /
xr_configure_interactable/xr_configure_hapticsis silently ignored. Loadxr_configure_interaction_layersbefore issuing detailed property edits.API_REFERENCE.md
DO NOT (common hallucinations):
- ,
XRHand,XRPlayer,XRTeleporter,GrabInteractor,VRController, andXRLocomotionare not the runtime classes you want hereXRManager - /
interactable.OnGrab()are not the XRI event model -> useOnRelease()/selectEnteredselectExited - is not the documented route here -> configure haptics through
controller.vibrate()xr_configure_haptics - Do not assume physics Layer or Tag replaces
InteractionLayerMask - Do not guess component property names. Load before setting detailed XR component properties
API_REFERENCE.md
Correct class names to anchor on:
XRInteractionManagerXROriginXRRayInteractorXRDirectInteractorXRSocketInteractorXRGrabInteractableXRSimpleInteractableTeleportationProviderTeleportationAreaTeleportationAnchorContinuousMoveProviderSnapTurnProviderContinuousTurnProviderTrackedDeviceGraphicRaycasterXRUIInputModuleTrackedPoseDriver
Routing:
- For non-XR Canvas UI creation -> use
ui - For architecture or lifecycle decisions in XR gameplay code -> load advisory modules such as ,
architecture,patterns, orasyncscriptdesign - For exact component property names and full workflow examples -> load
API_REFERENCE.md
运行模式(v1.9 三层模式):
- 审批模式(默认):查询/列表/信息类技能(、
xr_check_setup、xr_get_scene_report、xr_list_interactors)可直接运行。创建/修改类技能为FullAuto模式——在xr_list_interactables模式下,需执行授权协议;成功调用MODE_RESTRICTED后,技能将在服务器端执行,并在同一响应中返回结果。/permission/grant - 自动模式/绕过模式:SemiAuto和FullAuto模式的技能可直接运行。
- 本模块不包含删除/播放模式/重载/类技能,因此没有技能会被自动归类为禁用——所有技能均可通过授权访问。
RiskLevel="high" - 当缺少包时,所有
com.unity.xr.interaction.toolkit技能将返回xr_*安装指引,而非执行操作。NoXRI() - 反射敏感:XRI组件的属性名称必须与XRI 2.x/3.x版本完全匹配。/
xr_configure_interactable/xr_configure_haptics技能中使用错误的字段名将被静默忽略。在进行详细的组件属性编辑前,请加载xr_configure_interaction_layers文档。API_REFERENCE.md
请勿执行以下操作(常见错误认知):
- 、
XRHand、XRPlayer、XRTeleporter、GrabInteractor、VRController和XRLocomotion并非此处所需的运行时类XRManager - /
interactable.OnGrab()并非XRI的事件模型,请使用OnRelease()/selectEnteredselectExited - 并非此处的官方调用方式,请通过
controller.vibrate()配置触觉反馈xr_configure_haptics - 请勿假设物理层(Layer)或标签(Tag)可以替代
InteractionLayerMask - 请勿猜测组件属性名称。在设置XR组件的详细属性前,请加载文档
API_REFERENCE.md
应参考的正确类名:
XRInteractionManagerXROriginXRRayInteractorXRDirectInteractorXRSocketInteractorXRGrabInteractableXRSimpleInteractableTeleportationProviderTeleportationAreaTeleportationAnchorContinuousMoveProviderSnapTurnProviderContinuousTurnProviderTrackedDeviceGraphicRaycasterXRUIInputModuleTrackedPoseDriver
路由指引:
- 若要创建非XR的Canvas UI,请使用模块
ui - 若要进行XR游戏代码的架构或生命周期决策,请加载、
architecture、patterns或async等咨询模块scriptdesign - 若要获取准确的组件属性名称和完整工作流示例,请加载文档
API_REFERENCE.md
Skills
技能列表
Setup and Diagnostics
设置与诊断
| Skill | Use | Key parameters |
|---|---|---|
| Validate XR package, rig, managers, and scene prerequisites | |
| Create XR Origin + camera + controllers | |
| Add or find manager | none |
| Replace/add XR UI input stack | none |
| Report scene-side XR status | none |
| 技能 | 用途 | 关键参数 |
|---|---|---|
| 验证XR包、Rig、管理器及场景前置条件 | |
| 创建XR Origin + 相机 + 控制器 | |
| 添加或查找管理器 | 无 |
| 替换/添加XR UI输入栈 | 无 |
| 报告场景端XR状态 | 无 |
Interactors and Interactables
交互器与可交互对象
| Skill | Use | Key parameters |
|---|---|---|
| Remote pointing / ray interaction | |
| Close-range hand grab | |
| Snap-to slot | |
| Rigidbody + collider + grab config | |
| Hover/select without grab | |
| Fine-tune interactable behavior | target + changed fields only |
| List all scene interactors | none |
| List all scene interactables | none |
| 技能 | 用途 | 关键参数 |
|---|---|---|
| 远程指向/射线交互 | |
| 近距离手部抓取 | |
| 吸附插槽 | |
| 刚体 + 碰撞器 + 抓取配置 | |
| 无需抓取的悬停/选择 | |
| 微调可交互对象行为 | 目标对象 + 仅需修改的字段 |
| 列出场景中所有交互器 | 无 |
| 列出场景中所有可交互对象 | 无 |
Locomotion and XR UI
移动系统与XR UI
| Skill | Use | Key parameters |
|---|---|---|
| Add teleport provider to XR Origin | none |
| Mark a surface as teleportable | |
| Create fixed teleport destination | |
| Add stick locomotion | |
| Add snap or smooth turn | |
| Convert Canvas for XR interaction | |
| 技能 | 用途 | 关键参数 |
|---|---|---|
| 为XR Origin添加传送提供者 | 无 |
| 将表面标记为可传送区域 | |
| 创建固定传送目标点 | |
| 添加摇杆移动 | |
| 添加快速转向或平滑转向 | |
| 转换Canvas以支持XR交互 | |
Feedback and Filtering
反馈与过滤
| Skill | Use | Key parameters |
|---|---|---|
| Set hover/select vibration | |
| Wire interaction callback to target method | |
| Set InteractionLayerMask | |
| 技能 | 用途 | 关键参数 |
|---|---|---|
| 设置悬停/选择时的振动反馈 | |
| 将交互回调绑定到目标方法 | |
| 设置InteractionLayerMask | |
Quick Start
快速开始
python
import unity_skills as u
u.call_skill("xr_check_setup")
u.call_skill("xr_setup_rig", name="XR Origin")
u.call_skill("xr_add_ray_interactor", name="Right Controller")
u.call_skill("xr_add_direct_interactor", name="Left Controller")
u.call_skill("xr_setup_teleportation")
u.call_skill("xr_setup_turn_provider", turnType="Snap", turnAmount=45)
u.call_skill("xr_add_grab_interactable", name="MyCube", movementType="VelocityTracking")python
import unity_skills as u
u.call_skill("xr_check_setup")
u.call_skill("xr_setup_rig", name="XR Origin")
u.call_skill("xr_add_ray_interactor", name="Right Controller")
u.call_skill("xr_add_direct_interactor", name="Left Controller")
u.call_skill("xr_setup_teleportation")
u.call_skill("xr_setup_turn_provider", turnType="Snap", turnAmount=45)
u.call_skill("xr_add_grab_interactable", name="MyCube", movementType="VelocityTracking")Workflow Summary
工作流总结
Rig Setup
Rig搭建
- Run .
xr_check_setup - Create the rig with .
xr_setup_rig - Ensure XR UI input exists with .
xr_setup_event_system - Add at least one interactor per controller.
- 运行。
xr_check_setup - 使用创建Rig。
xr_setup_rig - 通过确保XR UI输入系统存在。
xr_setup_event_system - 为每个控制器添加至少一个交互器。
Grab Setup
抓取功能搭建
- Direct hand grab: +
xr_add_direct_interactorxr_add_grab_interactable - Distance grab: +
xr_add_ray_interactorxr_add_grab_interactable - Socket placement: + grabbable object
xr_add_socket_interactor
movementType- : best general-purpose physical grab
VelocityTracking - : use for handles/tools that should not get stuck
Kinematic - : best for precise remote grab
Instantaneous
- 手部直接抓取:+
xr_add_direct_interactorxr_add_grab_interactable - 远程抓取:+
xr_add_ray_interactorxr_add_grab_interactable - 插槽放置:+ 可抓取对象
xr_add_socket_interactor
movementType- :最佳通用物理抓取方式
VelocityTracking - :适用于不应被卡住的手柄/工具
Kinematic - :最适合精准远程抓取
Instantaneous
Locomotion Setup
移动系统搭建
- Teleport: +
xr_setup_teleportation+xr_add_ray_interactor/xr_add_teleport_areaxr_add_teleport_anchor - Continuous locomotion:
xr_setup_continuous_move - Turn:
xr_setup_turn_provider
Comfort default: snap turn + moderate move speed ().
~2.0 m/s- 传送:+
xr_setup_teleportation+xr_add_ray_interactor/xr_add_teleport_areaxr_add_teleport_anchor - 连续移动:
xr_setup_continuous_move - 转向:
xr_setup_turn_provider
舒适默认设置:快速转向 + 中等移动速度()。
~2.0 m/sXR UI
XR UI搭建
- Convert Canvas with
xr_setup_ui_canvas - Ensure
xr_setup_event_system - Add a ray interactor on the controller that should click UI
- 使用转换Canvas
xr_setup_ui_canvas - 确保已设置
xr_setup_event_system - 在用于点击UI的控制器上添加射线交互器
Collider Configuration Matrix
碰撞器配置矩阵
This is the most important XR anti-hallucination table in the repo.
| Component | Collider required | | Recommended collider | Reason |
|---|---|---|---|---|
| Yes | True | SphereCollider ( | Overlap detection |
| No | - | None | Uses raycasts |
| Yes | True | SphereCollider ( | Snap zone |
| Yes | False | BoxCollider or convex MeshCollider | Physics + ray target |
| Yes | False | BoxCollider | Selection detection |
| Yes | False | MeshCollider or BoxCollider | Surface raycast target |
| Yes | False | Thin BoxCollider | Point raycast target |
Critical rules:
- needs a
XRGrabInteractable.Rigidbody - A grabbable collider must not be trigger.
- A direct interactor collider must be trigger.
- Dynamic mesh colliders must be convex.
- Socket colliders should be trigger-only overlap zones.
这是本仓库中最重要的XR错误认知规避表格。
| 组件 | 是否需要碰撞器 | | 推荐碰撞器 | 原因 |
|---|---|---|---|---|
| 是 | True | SphereCollider( | 重叠检测 |
| 否 | - | 无 | 使用射线检测 |
| 是 | True | SphereCollider( | 吸附区域 |
| 是 | False | BoxCollider或凸面体MeshCollider | 物理交互 + 射线目标 |
| 是 | False | BoxCollider | 选择检测 |
| 是 | False | MeshCollider或BoxCollider | 表面射线检测目标 |
| 是 | False | 薄BoxCollider | 点射线检测目标 |
关键规则:
- 需要添加
XRGrabInteractable组件。Rigidbody - 可抓取对象的碰撞器不能设置为触发器。
- 直接交互器的碰撞器必须设置为触发器。
- 动态网格碰撞器必须设置为凸面体。
- 插槽碰撞器应设为仅触发的重叠区域。
Version Compatibility
版本兼容性
| Topic | XRI 2.x | XRI 3.x |
|---|---|---|
| Main namespace style | root namespace | split sub-namespaces |
| Rig type | | |
| Locomotion core | | |
| Controller type | | |
| Bridge behavior | Reflection helper falls back automatically | Reflection helper prefers 3.x first |
| 主题 | XRI 2.x | XRI 3.x |
|---|---|---|
| 主命名空间风格 | 根命名空间 | 拆分的子命名空间 |
| Rig类型 | | |
| 移动系统核心 | | |
| 控制器类型 | | |
| 桥接层行为 | 反射助手自动回退 | 反射助手优先使用3.x版本 |
Important Notes
重要说明
- Scenes should normally have exactly one .
XRInteractionManager - Most locomotion skills assume an already exists.
XROrigin - Package installation or reconfiguration can trigger Domain Reload. Wait before retrying XR calls.
- Use for interactor/interactable filtering.
InteractionLayerMask - For custom XR scripts, prefer XRI lifecycle hooks and events over polling when possible.
Update()
- 场景通常应仅包含一个。
XRInteractionManager - 大多数移动系统技能假设已存在。
XROrigin - 包安装或重新配置可能会触发域重载。重试XR调用前请等待。
- 使用进行交互器/可交互对象的过滤。
InteractionLayerMask - 编写自定义XR脚本时,尽可能优先使用XRI生命周期钩子和事件,而非轮询。
Update()
Minimal Example
最简示例
python
import unity_skills as u
u.call_skill("xr_setup_rig", name="XR Origin", cameraYOffset=1.36)
u.call_skill("xr_setup_event_system")
u.call_skill("xr_add_ray_interactor", name="Right Controller", maxDistance=30, lineType="StraightLine")
u.call_skill("xr_add_grab_interactable", name="Tool", movementType="VelocityTracking", throwOnDetach=True)
u.call_skill("xr_configure_haptics", name="Right Controller", selectIntensity=0.7, selectDuration=0.15)python
import unity_skills as u
u.call_skill("xr_setup_rig", name="XR Origin", cameraYOffset=1.36)
u.call_skill("xr_setup_event_system")
u.call_skill("xr_add_ray_interactor", name="Right Controller", maxDistance=30, lineType="StraightLine")
u.call_skill("xr_add_grab_interactable", name="Tool", movementType="VelocityTracking", throwOnDetach=True)
u.call_skill("xr_configure_haptics", name="Right Controller", selectIntensity=0.7, selectDuration=0.15)Exact Signatures
精确签名
Exact names, parameters, defaults, and returns are defined by or , not by this file.
Before configuring XR component properties in detail, load . XR property names are reflection-sensitive.
GET /skills/schemaunity_skills.get_skill_schema()API_REFERENCE.md精确的名称、参数、默认值和返回值由或定义,而非本文档。
在详细配置XR组件属性前,请加载文档。XR属性名称对反射敏感。
GET /skills/schemaunity_skills.get_skill_schema()API_REFERENCE.md