void VisibilityEnabler::_notification(int p_what){ if (p_what==NOTIFICATION_ENTER_TREE) { if (get_tree()->is_editor_hint()) return; Node *from = this; //find where current scene starts while(from->get_parent() && from->get_filename()==String()) from=from->get_parent(); _find_nodes(from); } if (p_what==NOTIFICATION_EXIT_TREE) { if (get_tree()->is_editor_hint()) return; for (Map<Node*,Variant>::Element *E=nodes.front();E;E=E->next()) { if (!visible) _change_node_state(E->key(),true); E->key()->disconnect(SceneStringNames::get_singleton()->exit_tree,this,"_node_removed"); } nodes.clear(); } }
void VisibilityEnabler2D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { if (Engine::get_singleton()->is_editor_hint()) return; Node *from = this; //find where current scene starts while (from->get_parent() && from->get_filename() == String()) from = from->get_parent(); _find_nodes(from); if (enabler[ENABLER_PARENT_PHYSICS_PROCESS] && get_parent()) get_parent()->set_physics_process(false); if (enabler[ENABLER_PARENT_PROCESS] && get_parent()) get_parent()->set_process(false); } if (p_what == NOTIFICATION_EXIT_TREE) { if (Engine::get_singleton()->is_editor_hint()) return; for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) { if (!visible) _change_node_state(E->key(), true); E->key()->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, "_node_removed"); } nodes.clear(); } }
void VisibilityEnabler2D::_find_nodes(Node *p_node) { bool add = false; Variant meta; if (enabler[ENABLER_FREEZE_BODIES]) { RigidBody2D *rb2d = Object::cast_to<RigidBody2D>(p_node); if (rb2d && ((rb2d->get_mode() == RigidBody2D::MODE_CHARACTER || rb2d->get_mode() == RigidBody2D::MODE_RIGID))) { add = true; meta = rb2d->get_mode(); } } if (enabler[ENABLER_PAUSE_ANIMATIONS]) { AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_node); if (ap) { add = true; } } if (enabler[ENABLER_PAUSE_ANIMATED_SPRITES]) { AnimatedSprite *as = Object::cast_to<AnimatedSprite>(p_node); if (as) { add = true; } } if (enabler[ENABLER_PAUSE_PARTICLES]) { Particles2D *ps = Object::cast_to<Particles2D>(p_node); if (ps) { add = true; } } if (add) { p_node->connect(SceneStringNames::get_singleton()->tree_exiting, this, "_node_removed", varray(p_node), CONNECT_ONESHOT); nodes[p_node] = meta; _change_node_state(p_node, false); } for (int i = 0; i < p_node->get_child_count(); i++) { Node *c = p_node->get_child(i); if (c->get_filename() != String()) continue; //skip, instance _find_nodes(c); } }
void VisibilityEnabler::_find_nodes(Node* p_node) { bool add=false; Variant meta; if (enabler[ENABLER_FREEZE_BODIES]) { RigidBody *rb = p_node->cast_to<RigidBody>(); if (rb && ((rb->get_mode()==RigidBody::MODE_CHARACTER || (rb->get_mode()==RigidBody::MODE_RIGID && !rb->is_able_to_sleep())))) { add=true; meta=rb->get_mode(); } } if (enabler[ENABLER_PAUSE_ANIMATIONS]) { AnimationPlayer *ap = p_node->cast_to<AnimationPlayer>(); if (ap) { add=true; } } if (add) { p_node->connect(SceneStringNames::get_singleton()->exit_tree,this,"_node_removed",varray(p_node),CONNECT_ONESHOT); nodes[p_node]=meta; _change_node_state(p_node,false); } for(int i=0;i<p_node->get_child_count();i++) { Node *c = p_node->get_child(i); if (c->get_filename()!=String()) continue; //skip, instance _find_nodes(c); } }