# 凝视射线

## **简介**

| **凝视射线**交互（Gaze-based Interaction 或 Eye Tracking Interaction）是一种用户界面交互方式，它允许用户通过移动视线来选择和与虚拟环境中的对象进行交互。这种交互方式模仿了人们在现实世界中通过视线移动来关注和选择物体的自然行为。 |
| ------------------------------------------------------------------------------------------------------------------------------------------- |

在X3设备中，凝视射线交互，有两种形式

* 1、移动射线，注视若干秒，进行选择操作
* 2、移动射线，点击镜腿，进行选择操作

<figure><img src="/files/YSImi8JHkz6QT1Le72sY" alt=""><figcaption></figcaption></figure>

<mark style="color:$primary;">移动射线，注视若干秒，进行选择操作</mark>

<figure><img src="/files/OtlVtwn0l6fQABSUfVPF" alt=""><figcaption></figcaption></figure>

<mark style="color:$primary;">移动射线，点击镜腿，进行选择操作</mark>

## **API介绍**

<table><thead><tr><th>调用方法</th><th>使用说明</th><th>示例代码</th></tr></thead><tbody><tr><td>开启/关闭 （默认开启） GazeLaserBeam.SetDisplayActive</td><td><p><strong>参数与返回值细节：</strong>参数是否显示，true 显示，false 隐藏，和没有返回 GazeLaserBeam 挂载 XRPlugin 预制体 的 LaserBeam上</p><p><strong>异常场景说明</strong>： 无</p><p><strong>调用时机建议</strong>：根据需要设置。</p></td><td><p></p><pre class="language-c#"><code class="lang-c#">GazeLaserBeam.SetDisplayActive(true)；
GazeLaserBeam.SetDisplayActive(false)
</code></pre></td></tr><tr><td>C#<br>GazeLaserBeam.SetDisplayActive(true)；<br>GazeLaserBeam.SetDisplayActive(false)</td><td></td><td></td></tr><tr><td>进度条外圈半径 GazeLaserBeam.m_ProgressInnerDiameterOffset 在界面根据需要设置</td><td><p><strong>参数与返回值细节：</strong>是属性参数，根据需要设置值大小，在 GazeLaserBeam 挂载 界面设置，如上图</p><p><strong>异常场景说明：</strong> 无</p><p><strong>调用时机建议：</strong>根据需要设置。</p></td><td>无<img src="/files/5e69c5ab6c03ae90401e78d04564c6ca6e9f1734" alt=""></td></tr><tr><td>进度条完成的速度 GazeLaserBeam.m_ProgressSpeed 在界面根据需要设置</td><td><p><strong>参数与返回值细节：</strong>是属性参数，根据需要设置值大小，在 GazeLaserBeam 挂载 界面设置，如上图</p><p><strong>异常场景说明：</strong> 无</p><p><strong>调用时机建议：</strong>根据需要设置。</p></td><td>无<img src="/files/5e69c5ab6c03ae90401e78d04564c6ca6e9f1734" alt=""></td></tr><tr><td>进度条完成的速度 GazeLaserBeam.m_ProgressSpeed 在界面根据需要设置</td><td><p><strong>参数与返回值细节：</strong>是属性参数，根据需要设置值大小，在 GazeLaserBeam 挂载 界面设置，如上图</p><p><strong>异常场景说明：</strong> 无</p><p><strong>调用时机建议：</strong>根据需要设置。</p></td><td>无<img src="/files/5e69c5ab6c03ae90401e78d04564c6ca6e9f1734" alt=""></td></tr></tbody></table>

## **演示 Sample 路径**

HelloRayNeo/Scenes/Interactive/BaseInteraction.unity

HelloRayNeo/Scenes/Interactive/GazeActive.unity

![](/files/3f3fb716a37eaedaaa9edfbe2cf872a50bcfa78b)

## **Sample 实现简单说明**

### **移动射线，注视若干秒选择**

1、创建场景，场景中添加预制体 XR Plugin Gaze

![](/files/ce095d3e8be6d3241d036ae1b9c331f52f970c82)

XR Plugin Progress 其实就是 XR Plugin Gaze，这里只是稍稍改动了名称

2、Canvas 下添加测试组件，这里是 Slider

![](/files/a4aff86b7339730794c8ab12fbab38b721479bc1)

3、其中 canvas 中的 Raycaster 是特定组件 XRGraphicRaycaster

![](/files/324235e6ad1375c29657d91dd4d56908548720e5)

4、打包运行，效果如上

![](/files/e85fac3cc09e68635cc6f77399151904e9654e29)

5、其中，关键的凝视交互选择脚本可参见 Gaze Laser Beam

![](/files/5e69c5ab6c03ae90401e78d04564c6ca6e9f1734)

### **移动射线，点击镜腿选择**

1、创建场景，场景中添加预制体 XR Plugin

![](/files/0980c6d580ceb320acb85d5b08678194764fcefb)

2、Canvas 下添加测试组件

![](/files/70c82954c445a0fc70fc86b3d22a3cb49d087754)

3、其中 canvas 中的 Raycaster 是特定组件 XRGraphicRaycaster

![](/files/688288cba81021232c693ffa3bef424226c31008)

4、打包运行，效果如上

![](/files/9efe20481a3a8433a1decec004f104391c04f87b)

5、其中，关键的凝视交互选择脚本可参见 Laser Beam

![](/files/6433b31c7a17d1bd04326534e9805fe6d8b998f5)

| ProgressOuterDiameterOffset | 进度条外圈半径   |
| --------------------------- | --------- |
| ProgressInnerDiameterOffset | 进度条内圈半径   |
| ProgressSpeed               | 进度条完成的速度. |

修改颜色及内外圈的尺寸:修改该材质球

![](/files/205bc6b3fea8e26e2d4cd7b44bc79188b5fbf7c8)

| Color | 进度条颜色 |
| ----- | ----- |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rayneo.gitbook.io/rayneo-devdoc/x-xi-lie/unity-kai-fa/ar-neng-li-api/ning-shi-she-xian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
