> For the complete documentation index, see [llms.txt](https://vc-docs.gitbook.io/engine/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vc-docs.gitbook.io/engine/home/doxygen_synced/classes/class_platform_detection.md).

# PlatformDetection

**Usage:** `api.PlatformDetection.GetCurrentPlatform()`

Run script callbacks when the user switches between VR and desktop ("KM" = keyboard/mouse).

## Public Types

|            | Name                                                                                                                                                                                                                                                             |
| ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| enum class | <p><a href="https://git.unimetaverse.net/vc-core-engine/doxygen/-/tree/main/Classes/Classes/class_platform_detection.md#enum-addtypes"><strong>AddTypes</strong></a> { TOVR, TONORMAL, FROMVR, FROMNORMAL}<br>The four possible switches you can listen for.</p> |

## Public Functions

|        | Name                                                                                                                                                                                                                                                                                                                                                                                                               |
| ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| void   | <p><a href="https://git.unimetaverse.net/vc-core-engine/doxygen/-/tree/main/Classes/Classes/class_platform_detection.md#function-addlistenerswitchto"><strong>AddListenerSwitchTo</strong></a>(WebXRState state, Action< JsValue, JsValue > callback, JsValue refObj, JsValue jsValue)<br>Runs your callback when the user switches into the given platform. Only VR and desktop (NORMAL) are supported.</p>       |
| void   | <p><a href="https://git.unimetaverse.net/vc-core-engine/doxygen/-/tree/main/Classes/Classes/class_platform_detection.md#function-addlistenerswitchfrom"><strong>AddListenerSwitchFrom</strong></a>(WebXRState state, Action< JsValue, JsValue > callback, JsValue refObj, JsValue jsValue)<br>Runs your callback when the user switches out of the given platform. Only VR and desktop (NORMAL) are supported.</p> |
| string | <p><a href="https://git.unimetaverse.net/vc-core-engine/doxygen/-/tree/main/Classes/Classes/class_platform_detection.md#function-getcurrentplatform"><strong>GetCurrentPlatform</strong></a>()<br>Returns the active platform: "mobile" on mobile, "VR" in WebXR VR state, otherwise "KM" (desktop).</p>                                                                                                           |

## Public Attributes

|                                             | Name                                                                                                                                                                                                                                                                           |
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Dictionary< AddTypes, List< UnityAction > > | <p><a href="https://git.unimetaverse.net/vc-core-engine/doxygen/-/tree/main/Classes/Classes/class_platform_detection.md#variable-scriptcallbacks"><strong>scriptCallbacks</strong></a><br>The callbacks you have registered, so they can be removed when the script stops.</p> |

## Public Types Documentation

### enum AddTypes

| Enumerator | Value | Description |
| ---------- | ----- | ----------- |
| TOVR       |       |             |
| TONORMAL   |       |             |
| FROMVR     |       |             |
| FROMNORMAL |       |             |

The four possible switches you can listen for.

## Public Functions Documentation

### function AddListenerSwitchTo

```csharp
static void AddListenerSwitchTo(
    WebXRState state,
    Action< JsValue, JsValue > callback,
    JsValue refObj,
    JsValue jsValue
)
```

Runs your callback when the user switches into the given platform. Only VR and desktop (NORMAL) are supported.

**Parameters**:

* **state** The platform being switched into (VR or NORMAL).
* **callback** Runs on the switch. Receives *refObj* and *jsValue*.
* **refObj** A value passed straight back to your callback (e.g. your own object).
* **jsValue** A second value passed straight back to your callback.

### function AddListenerSwitchFrom

```csharp
static void AddListenerSwitchFrom(
    WebXRState state,
    Action< JsValue, JsValue > callback,
    JsValue refObj,
    JsValue jsValue
)
```

Runs your callback when the user switches out of the given platform. Only VR and desktop (NORMAL) are supported.

**Parameters**:

* **state** The platform being switched away from (VR or NORMAL).
* **callback** Runs on the switch. Receives *refObj* and *jsValue*.
* **refObj** A value passed straight back to your callback (e.g. your own object).
* **jsValue** A second value passed straight back to your callback.

### function GetCurrentPlatform

```csharp
static string GetCurrentPlatform()
```

Returns the active platform: "mobile" on mobile, "VR" in WebXR VR state, otherwise "KM" (desktop).

**Return**: Platform identifier string.

## Public Attributes Documentation

### variable scriptCallbacks

```csharp
static Dictionary< AddTypes, List< UnityAction > > scriptCallbacks;
```

The callbacks you have registered, so they can be removed when the script stops.

***

Updated on 2026-07-22 at 12:00:00 +0800
