Move Cameras into the new 3d world on override.

This commit is contained in:
Relintai 2022-08-30 00:06:56 +02:00
parent 4303dfb5c0
commit dd2fa3e6e3
3 changed files with 37 additions and 7 deletions

View File

@ -178,9 +178,10 @@ void World::set_override_world(World *p_world) {
return;
}
_on_before_world_override_changed();
World *old_world = get_override_world();
Ref<World3D> old_world_3d = find_world_3d();
_on_before_world_override_changed();
if (old_world) {
old_world->_remove_overridden_world(this);
@ -192,6 +193,20 @@ void World::set_override_world(World *p_world) {
_override_world->_add_overridden_world(this);
}
if (old_world_3d.is_valid()) {
Ref<World3D> new_world_3d = find_world_3d();
if (old_world_3d != new_world_3d) {
if (new_world_3d.is_valid()) {
old_world_3d->move_cameras_into(new_world_3d);
} else {
ERR_PRINT("!new_world_3d.is_valid()");
}
}
} else {
ERR_PRINT("!old_world_3d.is_valid()");
}
_on_after_world_override_changed();
}
void World::set_override_world_bind(Node *p_world) {
@ -325,14 +340,13 @@ void World::_notification(int p_what) {
}
} break;
case NOTIFICATION_EXIT_TREE: {
for (int i = 0; i < _overriding_worlds.size(); ++i) {
World *w = _overriding_worlds[i];
set_override_world(NULL);
while (_overriding_worlds.size() > 0) {
World *w = _overriding_worlds[0];
w->set_override_world(NULL);
}
_override_world = NULL;
} break;
}
}

View File

@ -314,6 +314,20 @@ void World3D::get_camera_list(List<Camera *> *r_cameras) {
}
}
void World3D::move_cameras_into(Ref<World3D> target) {
ERR_FAIL_COND(!target.is_valid());
List<Camera *> cameras;
get_camera_list(&cameras);
for (List<Camera *>::Element *E = cameras.front(); E; E = E->next()) {
Camera *cam = E->get();
_remove_camera(cam);
target->_register_camera(cam);
}
}
void World3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_space"), &World3D::get_space);
ClassDB::bind_method(D_METHOD("get_scenario"), &World3D::get_scenario);

View File

@ -83,6 +83,8 @@ public:
PhysicsDirectSpaceState *get_direct_space_state();
void move_cameras_into(Ref<World3D> target);
World3D();
~World3D();
};