diff --git a/Source/Engine/Particles/ParticleEffect.cpp b/Source/Engine/Particles/ParticleEffect.cpp index 4b7923439..651ff719b 100644 --- a/Source/Engine/Particles/ParticleEffect.cpp +++ b/Source/Engine/Particles/ParticleEffect.cpp @@ -253,6 +253,11 @@ int32 ParticleEffect::GetParticlesCount() const return Instance.GetParticlesCount(); } +bool ParticleEffect::GetIsPlaying() const +{ + return _isPlaying; +} + void ParticleEffect::ResetSimulation() { Instance.ClearState(); @@ -275,6 +280,30 @@ void ParticleEffect::UpdateSimulation(bool singleFrame) Particles::UpdateEffect(this); } +void ParticleEffect::Play(bool reset) +{ + _play = true; + _isPlaying = true; + + if (reset) + ResetSimulation(); + else + UpdateSimulation(true); +} + +void ParticleEffect::Pause() +{ + _play = false; + _isPlaying = false; +} + +void ParticleEffect::Stop() +{ + _play = false; + _isPlaying = false; + ResetSimulation(); +} + void ParticleEffect::UpdateBounds() { BoundingBox bounds = BoundingBox::Empty; @@ -395,6 +424,9 @@ void ParticleEffect::SetParametersOverrides(const Array& valu void ParticleEffect::Update() { + if (!_play) + return; + // Skip if off-screen if (!UpdateWhenOffscreen && _lastMinDstSqr >= MAX_Real) return; @@ -417,7 +449,17 @@ void ParticleEffect::Update() void ParticleEffect::UpdateExecuteInEditor() { if (!Editor::IsPlayMode) + { + // Always Play in editor while not playing. + // Could be useful to have a GUI to change this state + if (!_play) + { + _play = true; + _isPlaying = true; + } + Update(); + } } #endif @@ -576,6 +618,7 @@ void ParticleEffect::Serialize(SerializeStream& stream, const void* otherObj) SERIALIZE(SimulationSpeed); SERIALIZE(UseTimeScale); SERIALIZE(IsLooping); + SERIALIZE(PlayOnStart); SERIALIZE(UpdateWhenOffscreen); SERIALIZE(DrawModes); SERIALIZE(SortOrder); @@ -675,6 +718,7 @@ void ParticleEffect::Deserialize(DeserializeStream& stream, ISerializeModifier* DESERIALIZE(SimulationSpeed); DESERIALIZE(UseTimeScale); DESERIALIZE(IsLooping); + DESERIALIZE(PlayOnStart); DESERIALIZE(UpdateWhenOffscreen); DESERIALIZE(DrawModes); DESERIALIZE(SortOrder); @@ -706,6 +750,9 @@ void ParticleEffect::OnEnable() GetScene()->Ticking.Update.AddTickExecuteInEditor(this); #endif + if (PlayOnStart) + Play(); + // Base Actor::OnEnable(); } diff --git a/Source/Engine/Particles/ParticleEffect.h b/Source/Engine/Particles/ParticleEffect.h index 3487a35f4..5a4bae771 100644 --- a/Source/Engine/Particles/ParticleEffect.h +++ b/Source/Engine/Particles/ParticleEffect.h @@ -184,6 +184,8 @@ private: uint32 _parametersVersion = 0; // Version number for _parameters to be in sync with Instance.ParametersVersion Array _parameters; // Cached for scripting API Array _parametersOverrides; // Cached parameter modifications to be applied to the parameters + bool _play = false; + bool _isPlaying = false; public: /// @@ -235,9 +237,15 @@ public: bool IsLooping = true; /// - /// If true, the particle simulation will be updated even when an actor cannot be seen by any camera. Otherwise, the simulation will stop running when the actor is off-screen. + /// Determines whether the particle effect should play on start. /// API_FIELD(Attributes="EditorDisplay(\"Particle Effect\"), DefaultValue(true), EditorOrder(60)") + bool PlayOnStart = true; + + /// + /// If true, the particle simulation will be updated even when an actor cannot be seen by any camera. Otherwise, the simulation will stop running when the actor is off-screen. + /// + API_FIELD(Attributes="EditorDisplay(\"Particle Effect\"), DefaultValue(true), EditorOrder(70)") bool UpdateWhenOffscreen = true; /// @@ -326,6 +334,11 @@ public: /// API_PROPERTY() int32 GetParticlesCount() const; + /// + /// Gets whether or not the particle effect is playing. + /// + API_PROPERTY(Attributes="NoSerialize, HideInEditor") bool GetIsPlaying() const; + /// /// Resets the particles simulation state (clears the instance state data but preserves the instance parameters values). /// @@ -337,6 +350,22 @@ public: /// True if update animation by a single frame only (time time since last engine update), otherwise will update simulation with delta time since last update. API_FUNCTION() void UpdateSimulation(bool singleFrame = false); + /// + /// Plays the simulation. + /// + /// /// If true, the simulation will be reset + API_FUNCTION() void Play(bool reset = true); + + /// + /// Pauses the simulation. + /// + API_FUNCTION() void Pause(); + + /// + /// Stops and resets the simulation. + /// + API_FUNCTION() void Stop(); + /// /// Updates the actor bounds. ///