diff options
author | Juan Linietsky <reduzio@gmail.com> | 2019-01-25 18:15:29 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2019-01-25 18:15:29 -0300 |
commit | b3335e943bbb321d4ea86cbf03ffc50032497aee (patch) | |
tree | 3caa640bb82165d0d0912836885dd892d56e4e01 | |
parent | b0758b2d73eb4cd90dbe0a99b82f6ebdb96b7774 (diff) |
Implement missing autorestart in oneshot node, closes #22238
-rw-r--r-- | editor/import_dock.cpp | 2 | ||||
-rw-r--r-- | scene/animation/animation_blend_tree.cpp | 24 | ||||
-rw-r--r-- | scene/animation/animation_blend_tree.h | 1 |
3 files changed, 25 insertions, 2 deletions
diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index 1b6246e086..40cf02ac9d 100644 --- a/editor/import_dock.cpp +++ b/editor/import_dock.cpp @@ -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(); } diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index a343a4f0ed..0daa574f72 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -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"; } //////////////////////////////////////////////// diff --git a/scene/animation/animation_blend_tree.h b/scene/animation/animation_blend_tree.h index e207713134..c16dcb1b8c 100644 --- a/scene/animation/animation_blend_tree.h +++ b/scene/animation/animation_blend_tree.h @@ -91,6 +91,7 @@ private: StringName prev_active; StringName time; StringName remaining; + StringName time_to_restart; protected: static void _bind_methods(); |