Add finished signal to CPUParticles
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include "scene/3d/gpu_particles_3d.h"
|
||||
#include "scene/main/viewport.h"
|
||||
#include "scene/resources/particle_process_material.h"
|
||||
#include "scene/scene_string_names.h"
|
||||
|
||||
AABB CPUParticles3D::get_aabb() const {
|
||||
return AABB();
|
||||
@@ -46,6 +47,7 @@ void CPUParticles3D::set_emitting(bool p_emitting) {
|
||||
|
||||
emitting = p_emitting;
|
||||
if (emitting) {
|
||||
active = true;
|
||||
set_process_internal(true);
|
||||
|
||||
// first update before rendering to avoid one frame delay after emitting starts
|
||||
@@ -220,7 +222,6 @@ PackedStringArray CPUParticles3D::get_configuration_warnings() const {
|
||||
|
||||
void CPUParticles3D::restart() {
|
||||
time = 0;
|
||||
inactive_time = 0;
|
||||
frame_remainder = 0;
|
||||
cycle = 0;
|
||||
emitting = false;
|
||||
@@ -575,21 +576,15 @@ void CPUParticles3D::_update_internal() {
|
||||
}
|
||||
|
||||
double delta = get_process_delta_time();
|
||||
if (emitting) {
|
||||
inactive_time = 0;
|
||||
} else {
|
||||
inactive_time += delta;
|
||||
if (inactive_time > lifetime * 1.2) {
|
||||
set_process_internal(false);
|
||||
_set_redraw(false);
|
||||
if (!active && !emitting) {
|
||||
set_process_internal(false);
|
||||
_set_redraw(false);
|
||||
|
||||
//reset variables
|
||||
time = 0;
|
||||
inactive_time = 0;
|
||||
frame_remainder = 0;
|
||||
cycle = 0;
|
||||
return;
|
||||
}
|
||||
//reset variables
|
||||
time = 0;
|
||||
frame_remainder = 0;
|
||||
cycle = 0;
|
||||
return;
|
||||
}
|
||||
_set_redraw(true);
|
||||
|
||||
@@ -670,6 +665,7 @@ void CPUParticles3D::_particles_process(double p_delta) {
|
||||
|
||||
double system_phase = time / lifetime;
|
||||
|
||||
bool should_be_active = false;
|
||||
for (int i = 0; i < pcount; i++) {
|
||||
Particle &p = parray[i];
|
||||
|
||||
@@ -1136,6 +1132,12 @@ void CPUParticles3D::_particles_process(double p_delta) {
|
||||
}
|
||||
|
||||
p.transform.origin += p.velocity * local_delta;
|
||||
|
||||
should_be_active = true;
|
||||
}
|
||||
if (!Math::is_equal_approx(time, 0.0) && active && !should_be_active) {
|
||||
active = false;
|
||||
emit_signal(SceneStringNames::get_singleton()->finished);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1543,6 +1545,8 @@ void CPUParticles3D::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("convert_from_particles", "particles"), &CPUParticles3D::convert_from_particles);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("finished"));
|
||||
|
||||
ADD_GROUP("Emission Shape", "emission_");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "emission_shape", PROPERTY_HINT_ENUM, "Point,Sphere,Sphere Surface,Box,Points,Directed Points,Ring", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_emission_shape", "get_emission_shape");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_sphere_radius", PROPERTY_HINT_RANGE, "0.01,128,0.01"), "set_emission_sphere_radius", "get_emission_sphere_radius");
|
||||
|
||||
Reference in New Issue
Block a user