1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-02 16:48:55 +00:00

Check if OpenXR is enabled with feature tags of export preset

This commit is contained in:
David Snopek
2025-11-25 14:18:14 -06:00
parent 9dd6c4dbac
commit e0668de3de
2 changed files with 22 additions and 14 deletions

View File

@@ -31,6 +31,7 @@
#include "openxr_editor_plugin.h"
#include "../action_map/openxr_action_map.h"
#include "../openxr_api.h"
#include "editor/editor_node.h"
#include "editor/gui/editor_bottom_panel.h"
@@ -47,9 +48,12 @@ bool OpenXRExportPlugin::supports_platform(const Ref<EditorExportPlatform> &p_ex
}
bool OpenXRExportPlugin::is_openxr_mode() const {
// Check if OpenXR is enabled using `EditorExportPlatform::get_project_settings()` because that'll
// take into account the feature tags on the specific export preset that is being exported.
bool openxr_enabled = (bool)get_export_platform()->get_project_setting(get_export_preset(), "xr/openxr/enabled");
int xr_mode_index = get_option("xr_features/xr_mode");
return xr_mode_index == XR_MODE_OPENXR;
return openxr_enabled && xr_mode_index == XR_MODE_OPENXR;
}
String OpenXRExportPlugin::_get_export_option_warning(const Ref<EditorExportPlatform> &p_export_platform, const String &p_option_name) const {
@@ -150,7 +154,7 @@ String OpenXRExportPlugin::get_android_manifest_activity_element_contents(const
// OpenXREditorPlugin
void OpenXREditorPlugin::edit(Object *p_node) {
if (Object::cast_to<OpenXRActionMap>(p_node)) {
if (action_map_editor && Object::cast_to<OpenXRActionMap>(p_node)) {
String path = Object::cast_to<OpenXRActionMap>(p_node)->get_path();
if (path.is_resource_file()) {
action_map_editor->open_action_map(path);
@@ -159,23 +163,29 @@ void OpenXREditorPlugin::edit(Object *p_node) {
}
bool OpenXREditorPlugin::handles(Object *p_node) const {
return (Object::cast_to<OpenXRActionMap>(p_node) != nullptr);
if (action_map_editor) {
return (Object::cast_to<OpenXRActionMap>(p_node) != nullptr);
}
return false;
}
void OpenXREditorPlugin::make_visible(bool p_visible) {
}
OpenXREditorPlugin::OpenXREditorPlugin() {
action_map_editor = memnew(OpenXRActionMapEditor);
EditorNode::get_bottom_panel()->add_item(TTRC("OpenXR Action Map"), action_map_editor, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_openxr_action_map_bottom_panel", TTRC("Toggle OpenXR Action Map Bottom Panel")));
// Only add our OpenXR action map editor if OpenXR is enabled for the whole project.
if (OpenXRAPI::openxr_is_enabled(false)) {
action_map_editor = memnew(OpenXRActionMapEditor);
EditorNode::get_bottom_panel()->add_item(TTRC("OpenXR Action Map"), action_map_editor, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_openxr_action_map_bottom_panel", TTRC("Toggle OpenXR Action Map Bottom Panel")));
binding_modifier_inspector_plugin = Ref<EditorInspectorPluginBindingModifier>(memnew(EditorInspectorPluginBindingModifier));
EditorInspector::add_inspector_plugin(binding_modifier_inspector_plugin);
binding_modifier_inspector_plugin = Ref<EditorInspectorPluginBindingModifier>(memnew(EditorInspectorPluginBindingModifier));
EditorInspector::add_inspector_plugin(binding_modifier_inspector_plugin);
#ifndef ANDROID_ENABLED
select_runtime = memnew(OpenXRSelectRuntime);
add_control_to_container(CONTAINER_TOOLBAR, select_runtime);
select_runtime = memnew(OpenXRSelectRuntime);
add_control_to_container(CONTAINER_TOOLBAR, select_runtime);
#endif
}
}
void OpenXREditorPlugin::_notification(int p_what) {

View File

@@ -109,17 +109,15 @@ static Ref<OpenXRInterface> openxr_interface;
#ifdef TOOLS_ENABLED
static void _editor_init() {
if (OpenXRAPI::openxr_is_enabled(false)) {
// Only add our OpenXR action map editor if OpenXR is enabled for our project
if (openxr_interaction_profile_metadata == nullptr) {
// If we didn't initialize our actionmap metadata at startup, we initialize it now.
openxr_interaction_profile_metadata = memnew(OpenXRInteractionProfileMetadata);
ERR_FAIL_NULL(openxr_interaction_profile_metadata);
}
OpenXREditorPlugin *openxr_plugin = memnew(OpenXREditorPlugin());
EditorNode::get_singleton()->add_editor_plugin(openxr_plugin);
}
OpenXREditorPlugin *openxr_plugin = memnew(OpenXREditorPlugin());
EditorNode::get_singleton()->add_editor_plugin(openxr_plugin);
}
#endif