mirror of
https://github.com/godotengine/godot
synced 2024-09-16 02:27:37 +00:00
Implement missing autorestart in oneshot node, closes #22238
This commit is contained in:
parent
b0758b2d73
commit
b3335e943b
|
@ -424,7 +424,7 @@ void ImportDock::_reimport_attempt() {
|
||||||
void ImportDock::_reimport_and_restart() {
|
void ImportDock::_reimport_and_restart() {
|
||||||
|
|
||||||
EditorNode::get_singleton()->save_all_scenes();
|
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();
|
_reimport();
|
||||||
EditorNode::get_singleton()->restart_editor();
|
EditorNode::get_singleton()->restart_editor();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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::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, time, PROPERTY_HINT_NONE, "", 0));
|
||||||
r_list->push_back(PropertyInfo(Variant::REAL, remaining, 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 {
|
Variant AnimationNodeOneShot::get_parameter_default_value(const StringName &p_parameter) const {
|
||||||
if (p_parameter == active || p_parameter == prev_active) {
|
if (p_parameter == active || p_parameter == prev_active) {
|
||||||
return false;
|
return false;
|
||||||
|
} else if (p_parameter == time_to_restart) {
|
||||||
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
@ -218,13 +222,26 @@ float AnimationNodeOneShot::process(float p_time, bool p_seek) {
|
||||||
bool prev_active = get_parameter(this->prev_active);
|
bool prev_active = get_parameter(this->prev_active);
|
||||||
float time = get_parameter(this->time);
|
float time = get_parameter(this->time);
|
||||||
float remaining = get_parameter(this->remaining);
|
float remaining = get_parameter(this->remaining);
|
||||||
|
float time_to_restart = get_parameter(this->time_to_restart);
|
||||||
|
|
||||||
if (!active) {
|
if (!active) {
|
||||||
//make it as if this node doesn't exist, pass input 0 by.
|
//make it as if this node doesn't exist, pass input 0 by.
|
||||||
if (prev_active) {
|
if (prev_active) {
|
||||||
set_parameter(this->prev_active, false);
|
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;
|
bool os_seek = p_seek;
|
||||||
|
@ -276,6 +293,10 @@ float AnimationNodeOneShot::process(float p_time, bool p_seek) {
|
||||||
if (remaining <= 0) {
|
if (remaining <= 0) {
|
||||||
set_parameter(this->active, false);
|
set_parameter(this->active, false);
|
||||||
set_parameter(this->prev_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";
|
prev_active = "prev_active";
|
||||||
time = "time";
|
time = "time";
|
||||||
remaining = "remaining";
|
remaining = "remaining";
|
||||||
|
time_to_restart = "time_to_restart";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
|
@ -91,6 +91,7 @@ private:
|
||||||
StringName prev_active;
|
StringName prev_active;
|
||||||
StringName time;
|
StringName time;
|
||||||
StringName remaining;
|
StringName remaining;
|
||||||
|
StringName time_to_restart;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
Loading…
Reference in a new issue