Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose profile_changed signal to XRController3D #89219

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/classes/XRController3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,11 @@
Emitted when a thumbstick or thumbpad on this controller is moved.
</description>
</signal>
<signal name="profile_changed">
<param index="0" name="role" type="String" />
<description>
Emitted when the interaction profile on this controller is changed.
</description>
</signal>
</signals>
</class>
11 changes: 7 additions & 4 deletions scene/3d/xr_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ void XRController3D::_bind_methods() {
ADD_SIGNAL(MethodInfo("button_released", PropertyInfo(Variant::STRING, "name")));
ADD_SIGNAL(MethodInfo("input_float_changed", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::FLOAT, "value")));
ADD_SIGNAL(MethodInfo("input_vector2_changed", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::VECTOR2, "value")));
ADD_SIGNAL(MethodInfo("profile_changed", PropertyInfo(Variant::STRING, "role")));
};

void XRController3D::_bind_tracker() {
Expand All @@ -471,6 +472,7 @@ void XRController3D::_bind_tracker() {
tracker->connect("button_released", callable_mp(this, &XRController3D::_button_released));
tracker->connect("input_float_changed", callable_mp(this, &XRController3D::_input_float_changed));
tracker->connect("input_vector2_changed", callable_mp(this, &XRController3D::_input_vector2_changed));
tracker->connect("profile_changed", callable_mp(this, &XRController3D::_profile_changed));
}
}

Expand All @@ -481,31 +483,32 @@ void XRController3D::_unbind_tracker() {
tracker->disconnect("button_released", callable_mp(this, &XRController3D::_button_released));
tracker->disconnect("input_float_changed", callable_mp(this, &XRController3D::_input_float_changed));
tracker->disconnect("input_vector2_changed", callable_mp(this, &XRController3D::_input_vector2_changed));
tracker->disconnect("profile_changed", callable_mp(this, &XRController3D::_profile_changed));
}

XRNode3D::_unbind_tracker();
}

void XRController3D::_button_pressed(const String &p_name) {
// just pass it on...
emit_signal(SNAME("button_pressed"), p_name);
}

void XRController3D::_button_released(const String &p_name) {
// just pass it on...
emit_signal(SNAME("button_released"), p_name);
}

void XRController3D::_input_float_changed(const String &p_name, float p_value) {
// just pass it on...
emit_signal(SNAME("input_float_changed"), p_name, p_value);
}

void XRController3D::_input_vector2_changed(const String &p_name, Vector2 p_value) {
// just pass it on...
emit_signal(SNAME("input_vector2_changed"), p_name, p_value);
}

void XRController3D::_profile_changed(const String &p_role) {
emit_signal(SNAME("profile_changed"), p_role);
}

bool XRController3D::is_button_pressed(const StringName &p_name) const {
if (tracker.is_valid()) {
// Inputs should already be of the correct type, our XR runtime handles conversions between raw input and the desired type
Expand Down
1 change: 1 addition & 0 deletions scene/3d/xr_nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class XRController3D : public XRNode3D {
void _button_released(const String &p_name);
void _input_float_changed(const String &p_name, float p_value);
void _input_vector2_changed(const String &p_name, Vector2 p_value);
void _profile_changed(const String &p_role);

public:
bool is_button_pressed(const StringName &p_name) const;
Expand Down
Loading