|
| 1 | +Hybrid Apps |
| 2 | +=========== |
| 3 | + |
| 4 | +.. note:: |
| 5 | + |
| 6 | + Check out the `Hybrid App Sample Project <https://github.com/GodotVR/godot_openxr_vendors/tree/master/samples/hybrid-app-sample>`_ |
| 7 | + for a working demo of hybird app functionality. |
| 8 | + |
| 9 | +Hybrid apps are applications capable of swapping between an immersive 3D mode and a 2D panel mode at runtime. |
| 10 | + |
| 11 | +Project Settings |
| 12 | +---------------- |
| 13 | + |
| 14 | +To make a hybrid app, the feature must be enabled in your project settings. The setting can be found in **Project Settings** under the **OpenXR** section. |
| 15 | +The **Hybrid App** setting should be visible if **Advanced Settings** are enabled. |
| 16 | + |
| 17 | +.. image:: img/hybrid_apps/hybrid_apps_project_setting.png |
| 18 | + |
| 19 | +By default, hybrid app functionality is disabled. Selecting either of the other options will enable hybrid app features and determine the app's starting mode. |
| 20 | + |
| 21 | +Switching Modes |
| 22 | +--------------- |
| 23 | + |
| 24 | +To switch between immersive and panel app modes in your hybrid app, use the :ref:`switch_mode <class_openxrhybridapp_method_switch_mode>` function. |
| 25 | +Switching modes restarts the application, so if you want it to start from where the user left off, you will need to use the second argument |
| 26 | +to pass data to the new mode as a ``String``, which can be accessed via the :ref:`get_launch_data <class_openxrhybridapp_method_get_launch_data>` function. |
| 27 | + |
| 28 | +Storing the data you'd like to share in a `Dictionary <https://docs.godotengine.org/en/stable/classes/class_dictionary.html>`_ |
| 29 | +and converting it to/from `JSON <https://docs.godotengine.org/en/stable/classes/class_json.html>`_ is one way you might utilize this feature. |
| 30 | +Here's what it might look like if your app is switching from immersive to panel mode and you have a ``current_score`` value you'd like to pass along: |
| 31 | + |
| 32 | +.. code-block:: gdscript |
| 33 | +
|
| 34 | + var current_score = 100 # Game state we want to keep in the new mode. |
| 35 | +
|
| 36 | + var my_dictionary = {} |
| 37 | + my_dictionary["current_score"] = current_score |
| 38 | +
|
| 39 | + var my_string = JSON.stringify(my_dictionary) |
| 40 | + OpenXRHybridApp.switch_mode(OpenXRHybridApp.HYBRID_MODE_PANEL, my_string) |
| 41 | +
|
| 42 | +Then, in your newly launched panel application, you could access ``current_score`` like so: |
| 43 | + |
| 44 | +.. code-block:: gdscript |
| 45 | +
|
| 46 | + var my_string = OpenXRHybridApp.get_launch_data() |
| 47 | + var my_dictionary = JSON.parse_string(my_string) |
| 48 | + var current_score = my_dictionary.get("current_score", 0) # Value we wanted to share |
0 commit comments