mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Port robust signal (dis)connection to ShapeCast2D
Ported from ShapeCast3D.
(cherry picked from commit 5bed055cdd)
This commit is contained in:
parent
58d8368481
commit
9573574788
3 changed files with 13 additions and 8 deletions
|
|
@ -151,11 +151,18 @@ bool ShapeCast2D::is_enabled() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShapeCast2D::set_shape(const Ref<Shape2D> &p_shape) {
|
void ShapeCast2D::set_shape(const Ref<Shape2D> &p_shape) {
|
||||||
|
if (p_shape == shape) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (shape.is_valid()) {
|
||||||
|
shape->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &ShapeCast2D::_shape_changed));
|
||||||
|
}
|
||||||
shape = p_shape;
|
shape = p_shape;
|
||||||
if (p_shape.is_valid()) {
|
if (shape.is_valid()) {
|
||||||
shape->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &ShapeCast2D::_redraw_shape));
|
shape->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &ShapeCast2D::_shape_changed));
|
||||||
shape_rid = shape->get_rid();
|
shape_rid = shape->get_rid();
|
||||||
}
|
}
|
||||||
|
|
||||||
update_configuration_warnings();
|
update_configuration_warnings();
|
||||||
queue_redraw();
|
queue_redraw();
|
||||||
}
|
}
|
||||||
|
|
@ -186,7 +193,7 @@ bool ShapeCast2D::get_exclude_parent_body() const {
|
||||||
return exclude_parent_body;
|
return exclude_parent_body;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShapeCast2D::_redraw_shape() {
|
void ShapeCast2D::_shape_changed() {
|
||||||
queue_redraw();
|
queue_redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ class ShapeCast2D : public Node2D {
|
||||||
real_t collision_unsafe_fraction = 1.0;
|
real_t collision_unsafe_fraction = 1.0;
|
||||||
|
|
||||||
Array _get_collision_result() const;
|
Array _get_collision_result() const;
|
||||||
void _redraw_shape();
|
void _shape_changed();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
|
|
||||||
|
|
@ -331,16 +331,14 @@ void ShapeCast3D::set_shape(const Ref<Shape3D> &p_shape) {
|
||||||
if (p_shape == shape) {
|
if (p_shape == shape) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!shape.is_null()) {
|
if (shape.is_valid()) {
|
||||||
shape->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &ShapeCast3D::_shape_changed));
|
shape->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &ShapeCast3D::_shape_changed));
|
||||||
shape->unregister_owner(this);
|
shape->unregister_owner(this);
|
||||||
}
|
}
|
||||||
shape = p_shape;
|
shape = p_shape;
|
||||||
if (!shape.is_null()) {
|
if (shape.is_valid()) {
|
||||||
shape->register_owner(this);
|
shape->register_owner(this);
|
||||||
shape->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &ShapeCast3D::_shape_changed));
|
shape->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &ShapeCast3D::_shape_changed));
|
||||||
}
|
|
||||||
if (p_shape.is_valid()) {
|
|
||||||
shape_rid = shape->get_rid();
|
shape_rid = shape->get_rid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue