Implement missing autorestart in oneshot node, closes #22238

This commit is contained in:
Juan Linietsky 2019-01-25 18:15:29 -03:00
parent b0758b2d73
commit b3335e943b
3 changed files with 25 additions and 2 deletions

View file

@ -424,7 +424,7 @@ void ImportDock::_reimport_attempt() {
void ImportDock::_reimport_and_restart() {
EditorNode::get_singleton()->save_all_scenes();
EditorResourcePreview::get_singleton()->stop(); //dont try to re-create previews
EditorResourcePreview::get_singleton()->stop(); //dont try to re-create previews after import
_reimport();
EditorNode::get_singleton()->restart_editor();
}

View file

@ -141,10 +141,14 @@ void AnimationNodeOneShot::get_parameter_list(List<PropertyInfo> *r_list) const
r_list->push_back(PropertyInfo(Variant::BOOL, prev_active, PROPERTY_HINT_NONE, "", 0));
r_list->push_back(PropertyInfo(Variant::REAL, time, PROPERTY_HINT_NONE, "", 0));
r_list->push_back(PropertyInfo(Variant::REAL, remaining, PROPERTY_HINT_NONE, "", 0));
r_list->push_back(PropertyInfo(Variant::REAL, time_to_restart, PROPERTY_HINT_NONE, "", 0));
}
Variant AnimationNodeOneShot::get_parameter_default_value(const StringName &p_parameter) const {
if (p_parameter == active || p_parameter == prev_active) {
return false;
} else if (p_parameter == time_to_restart) {
return -1;
} else {
return 0.0;
}
@ -218,13 +222,26 @@ float AnimationNodeOneShot::process(float p_time, bool p_seek) {
bool prev_active = get_parameter(this->prev_active);
float time = get_parameter(this->time);
float remaining = get_parameter(this->remaining);
float time_to_restart = get_parameter(this->time_to_restart);
if (!active) {
//make it as if this node doesn't exist, pass input 0 by.
if (prev_active) {
set_parameter(this->prev_active, false);
}
return blend_input(0, p_time, p_seek, 1.0, FILTER_IGNORE, !sync);
if (time_to_restart >= 0.0 && !p_seek) {
time_to_restart -= p_time;
if (time_to_restart < 0) {
//restart
set_parameter(this->active, true);
active = true;
}
set_parameter(this->time_to_restart, time_to_restart);
}
if (!active) {
return blend_input(0, p_time, p_seek, 1.0, FILTER_IGNORE, !sync);
}
}
bool os_seek = p_seek;
@ -276,6 +293,10 @@ float AnimationNodeOneShot::process(float p_time, bool p_seek) {
if (remaining <= 0) {
set_parameter(this->active, false);
set_parameter(this->prev_active, false);
if (autorestart) {
float restart_sec = autorestart_delay + Math::randf() * autorestart_random_delay;
set_parameter(this->time_to_restart, restart_sec);
}
}
}
@ -350,6 +371,7 @@ AnimationNodeOneShot::AnimationNodeOneShot() {
prev_active = "prev_active";
time = "time";
remaining = "remaining";
time_to_restart = "time_to_restart";
}
////////////////////////////////////////////////

View file

@ -91,6 +91,7 @@ private:
StringName prev_active;
StringName time;
StringName remaining;
StringName time_to_restart;
protected:
static void _bind_methods();