Skip to main content

Custom Methods For XR Experience

As we know, XRMOD engine is divided into a launcher and a content package(XR-Experience).

So XR-Experience script cannot directly call third-party methods or developer-defined script methods. Because the methods has no ahead of time (AOT) code was generated. For example, if you have embedded uniwebview in your application, you will not be able to call the appropriate method in the XRMOD Experience code to launch the browser. However, we also provide a way to do this.

Custom Method


using System;
using UnityEngine;
using System.Collections;
using com.Phantoms.ARMODAPI.Runtime;
using com.Phantoms.ActionNotification.Runtime;
using UnityEngine.Assertions;

namespace APITest.Runtime
public class APITestMainEntry
internal static API ARMODAPI = new API(nameof(APITest));

public async void OnLoad()
// we can not directly call this method.

Custom Bridge

In here we will using XRMOD Action Notification package to create a bridge.


  1. Add com.Phantoms.ActionNotification.Runtime to your ssembly definitions

    Add Reference
    Add References

    When you use Assembly definitions - ASMDEF must add the references for it.

  2. Register the action in your code. Calling ActionNotificationCenter.DefaultCenter.AddObserver to create an action

    • Your script must be persistent. You can add DontDestroyOnLoad attrbute for your class.
    • AddObserver the first parameter is the response Action, the second parameter is the key of the Action, the key must be globally unique.
    namespace Runtime.UI
    using UnityEngine;
    using Runtime.Core;
    using Runtime.Utils;
    using Runtime.Models;
    using Runtime.Config;
    using SDKEntry.Runtime;
    using System.Threading.Tasks;
    using com.phantoms.models.Runtime;
    using UnityEngine.SceneManagement;
    using com.Phantoms.ActionNotification.Runtime;

    public class PcxmPage : UIBase
    public void OnExitClicked()
    var tmp_SDKEntryPoint = UnityEngine.Object.FindObjectOfType<SDKEntryPoint>();

    private void OnEnable()
    ActionNotificationCenter.DefaultCenter.AddObserver(OpenH5Page, "OpenH5");

    // Custom Action for XR-Experience to open webpage using Uniwebview
    private void OpenH5Page(BaseNotificationData _data)
    var tmp_data = JsonUtility.FromJson<H5BridgeData>(_data.BaseData);
  3. XRMOD XR-Experience scripting trigger the bridge. When we call PostNotification must passing a BaseNotificationData. Similarly PostNotification also has two parameters, the first parameter is the key, that is, the action id to be executed; the second parameter is the data transmitted to the action.

    ActionNotificationCenter.DefaultCenter.PostNotification("OpenH5", new BaseNotificationData()
    BaseData = "{\"title\":\"PostNotification\", \"link\":\"\"}"

    All actions that have been registered to the ActionNotificationCenter will be released after the XRMOD module is closed(Calling Dispose).


Although we cannot call third-party or user-defined methods directly in XR-Experience scripts, we can do so through ActionNotificationCenter.