Pārlūkot izejas kodu

Made ParticleEmitter::ApplyEffect() public, as it's necessary if changing certain properties of the effect programmatically. Also mark network update if the emitter's effect is changed to none.

Lasse Öörni 11 gadi atpakaļ
vecāks
revīzija
c3fc39132b

+ 16 - 17
Source/Engine/Graphics/ParticleEmitter.cpp

@@ -257,10 +257,9 @@ void ParticleEmitter::SetEffect(ParticleEffect* effect)
 
     effect_ = effect;
 
-    if (!effect_)
-        return;
-
-    SubscribeToEvent(effect, E_RELOADFINISHED, HANDLER(ParticleEmitter, HandleEffectReloadFinished));
+    if (effect_)
+        SubscribeToEvent(effect_, E_RELOADFINISHED, HANDLER(ParticleEmitter, HandleEffectReloadFinished));
+    
     ApplyEffect();
     MarkNetworkUpdate();
 }
@@ -306,6 +305,19 @@ void ParticleEmitter::Reset()
     SetEmitting(true);
 }
 
+void ParticleEmitter::ApplyEffect()
+{
+    if (!effect_)
+        return;
+    
+    SetMaterial(effect_->GetMaterial());
+    SetNumParticles(effect_->GetNumParticles());
+    SetRelative(effect_->IsRelative());
+    SetScaled(effect_->IsScaled());
+    SetSorted(effect_->IsSorted());
+    SetAnimationLodBias(effect_->GetAnimationLodBias());
+}
+
 void ParticleEmitter::SetEffectAttr(ResourceRef value)
 {
     ResourceCache* cache = GetSubsystem<ResourceCache>();
@@ -469,17 +481,4 @@ void ParticleEmitter::HandleEffectReloadFinished(StringHash eventType, VariantMa
     ApplyEffect();
 }
 
-void ParticleEmitter::ApplyEffect()
-{
-    if (!effect_)
-        return;
-    
-    SetMaterial(effect_->GetMaterial());
-    SetNumParticles(effect_->GetNumParticles());
-    SetRelative(effect_->IsRelative());
-    SetScaled(effect_->IsScaled());
-    SetSorted(effect_->IsSorted());
-    SetAnimationLodBias(effect_->GetAnimationLodBias());
-}
-
 }

+ 3 - 3
Source/Engine/Graphics/ParticleEmitter.h

@@ -80,6 +80,8 @@ public:
     void RemoveAllParticles();
     /// Reset the particle emitter completely. Removes current particles, sets emitting state on, and resets the emission timer.
     void Reset();
+    /// Apply not continuously updated values such as the material, the number of particles and sorting mode from the particle effect. Call this if you change the effect programmatically.
+    void ApplyEffect();
 
     /// Return particle effect.
     ParticleEffect* GetEffect() const { return effect_; }
@@ -111,9 +113,7 @@ private:
     void HandleScenePostUpdate(StringHash eventType, VariantMap& eventData);
     /// Handle live reload of the particle effect.
     void HandleEffectReloadFinished(StringHash eventType, VariantMap& eventData);
-    /// Apply one-time values such as the material from the particle effect.
-    void ApplyEffect();
-    
+
     /// Particle effect.
     SharedPtr<ParticleEffect> effect_;
     /// Particles.

+ 1 - 0
Source/Engine/LuaScript/pkgs/Graphics/ParticleEmitter.pkg

@@ -8,6 +8,7 @@ class ParticleEmitter : public BillboardSet
     void ResetEmissionTimer();
     void RemoveAllParticles();
     void Reset();
+    void ApplyEffect();
 
     ParticleEffect* GetEffect() const { return effect_; }
     unsigned GetNumParticles() const { return particles_.Size(); }

+ 1 - 0
Source/Engine/Script/GraphicsAPI.cpp

@@ -1145,6 +1145,7 @@ static void RegisterParticleEmitter(asIScriptEngine* engine)
     engine->RegisterObjectMethod("ParticleEmitter", "void ResetEmissionTimer()", asMETHOD(ParticleEmitter, ResetEmissionTimer), asCALL_THISCALL);
     engine->RegisterObjectMethod("ParticleEmitter", "void RemoveAllParticles()", asMETHOD(ParticleEmitter, RemoveAllParticles), asCALL_THISCALL);
     engine->RegisterObjectMethod("ParticleEmitter", "void Reset()", asMETHOD(ParticleEmitter, Reset), asCALL_THISCALL);
+    engine->RegisterObjectMethod("ParticleEmitter", "void ApplyEffect()", asMETHOD(ParticleEmitter, ApplyEffect), asCALL_THISCALL);
 }
 
 static void RegisterCustomGeometry(asIScriptEngine* engine)