# Android和Unity通讯

#### Android 发消息给 Unity

**在 Android 代码中,调用如下接口**

```reasonml
AirApi.ins().onCommandRespToUnity(int eventType, String params);
```

\_注:已经有部分 int 的数值被注册,已被注册数值如下,不要发送对应的数值.详细可以查阅类:AdapterMsgDispatchType,数值建议从 1000 开始

| Class:AdapterMsgDispatchType |     |
| ---------------------------- | --- |
| HomePage                     | 100 |
| FovChanged                   | 101 |
| TopBar                       | 102 |
| GLASS                        | 103 |

<br>

**在 Unity 代码中,调用如下接口注册回调:**

```reasonml
NativeModule.Instance.RegesitNativeMsgDispatchListener(int eventType,Action<string[]> callBack);
```

*注* *a.需要在界面销毁时调用反注册消息.不然会造成泄漏*

```reasonml
NativeModule.Instance.RmNativeMsgDispatchListener(int eventType);
```

*b.一个 eventType 只能注册一个回调.如果多次注册将会被覆盖.*

**Unity 发消息给 Android**

暂无,需要自定义

**SDK 中的事件解析**<br>

| Android 枚举 AdapterMsgDispatchType | C#枚举 MsgDispatchType | typeId | 值 string\[]                               | 描述          |
| --------------------------------- | -------------------- | ------ | ----------------------------------------- | ----------- |
| HomePage                          | LauncherEvent        | 100    | RayType : string\[0]                      | home 按钮触摸事件 |
| Fov\_Changed                      | FovChanged           | 101    |                                           |             |
| TopBar                            | TopBar               | 102    | string:string\[0]="TOP\_BAR\_BACK\_CLICK" | 顶部返回按钮点击    |
| GLASS                             | GLASS                | 103    | int= 1:眼镜插入/2:眼镜拔出                        |             |

<br>


---

# 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/air-xi-lie/unity-kai-fa/api/android-he-unity-tong-xun.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.
