8 private bool m_MarkedForDeletion;
9 bool m_ForceOrientationRelativeToWorld =
false;
13 float m_MaxOriInterval;
14 ref
Timer m_RandomizeOri;
19 private vector m_GlobalPosPreviousFrame;
21 static private const int MAX_EMITORS = 30;
41 DestroyParticleEffect();
45 CreateParticleEffect();
62 private void CreateParticleEffect()
88 float lifetime_min = 0;
89 float lifetime_random = 0;
90 float lifetime_return = 0;
91 float effect_time = 0;
92 string emitors_array[MAX_EMITORS];
96 for (
int i = 0; i < emitors; i++)
102 if ( lifetime_min + lifetime_random + effect_time > lifetime_return )
104 lifetime_return = lifetime_min + lifetime_random + effect_time;
109 return lifetime_return;
121 private void DestroyParticleEffect()
138 void SetParameter(
int emitter,
int parameter,
float value)
148 void GetParameter(
int emitter,
int parameter, out
float value)
178 string emitors_array[MAX_EMITORS];
182 for (
int i = 0; i < emitors; i++)
197 void ScaleParticleParamFromOriginal(
int parameter_id,
float coef )
201 string emitors_array[MAX_EMITORS];
205 for (
int i = 0; i < emitors; i++)
215 void ScaleParticleParam(
int parameter_id,
float coef )
219 string emitors_array[MAX_EMITORS];
223 for (
int i = 0; i < emitors; i++)
233 void IncrementParticleParamFromOriginal(
int parameter_id,
float value )
237 string emitors_array[MAX_EMITORS];
241 for (
int i = 0; i < emitors; i++)
251 void IncrementParticleParam(
int parameter_id,
float value )
255 string emitors_array[MAX_EMITORS];
259 for (
int i = 0; i < emitors; i++)
269 void SetParticleParam(
int parameter_id,
float value )
278 void OnCheckAutoDelete()
282 if (!m_MarkedForDeletion)
296 m_MarkedForDeletion =
true;
303 if ( m_MarkedForDeletion )
307 GetGame().ObjectDelete(
this );
313 override void EOnFrame(
IEntity other,
float timeSlice)
315 super.EOnFrame(other, timeSlice);
352 private void OnToDelete()
370 void SetWiggle(
float random_angle,
float random_interval)
372 if ( !random_angle == 0 || !random_interval == 0)
374 m_MaxOriWiggle = random_angle;
375 m_MaxOriInterval = random_interval;
380 if ( !m_RandomizeOri.IsRunning() )
382 m_RandomizeOri.Run(
Math.RandomFloat(0, m_MaxOriInterval) ,
this,
"RandomizeOrientation", NULL,
false);
385 else if (m_RandomizeOri)
387 m_RandomizeOri.Stop();
388 delete m_RandomizeOri;
399 void RandomizeOrientation()
403 if ( !m_RandomizeOri.IsRunning() )
405 m_RandomizeOri.Run(
Math.RandomFloat(0, m_MaxOriInterval) ,
this,
"RandomizeOrientation", NULL,
false);
411 float r1 =
Math.RandomFloat(0, m_MaxOriWiggle*2) - m_MaxOriWiggle;
412 float r2 =
Math.RandomFloat(0, m_MaxOriWiggle*2) - m_MaxOriWiggle;
413 float r3 =
Math.RandomFloat(0, m_MaxOriWiggle*2) - m_MaxOriWiggle;
416 AddAsChild( old_parent, m_DefaultPos, new_ori );
435 Error(
"ERROR when creating a particle! Parameter parent_obj is NULL!");
437 vector global_pos = parent_obj.GetPosition();
439 p.AddAsChild(parent_obj, local_pos, local_ori, force_world_rotation);
440 p.m_DefaultOri = local_ori;
464 p.SetOrientation(global_ori);
465 p.m_ForceOrientationRelativeToWorld = force_world_rotation;
470 Error(
"A particle was spawned on server-side! Particles can be spawned on client-side only!");
562 parent.RemoveChild(
this);
575 void AddAsChild(
Object parent,
vector local_pos =
"0 0 0",
vector local_ori =
"0 0 0",
bool force_rotation_to_world =
false)
577 if (parent && !parent.ToDelete())
580 SetOrientation(local_ori);
582 m_DefaultPos = local_pos;
583 m_ForceOrientationRelativeToWorld = force_rotation_to_world;
588 parent.AddChild(
this, -1,
false);
Legacy way of using particles in the game.
bool m_IsRepeat
Whether this particle repeats.
static Particle Create(int particle_id, Object parent_obj, vector local_pos="0 0 0", vector local_ori="0 0 0")
Legacy function for backwards compatibility.
float GetMaxLifetime()
Returns the approx. max lifetime.
static Particle PlayOnObject(int particle_id, Object parent_obj, vector local_pos="0 0 0", vector local_ori="0 0 0", bool force_world_rotation=false)
Creates a particle emitter, attaches it on the given object and activates it.
Object m_ParticleEffect
The child object which contains the actual particle.
static Particle CreateInWorld(int particle_id, vector global_pos, vector global_ori="0 0 0", bool force_world_rotation=false)
Creates a particle emitter on the given position.
int GetParticleCount()
Returns the total count of active particles in all emitors.
static Particle PlayInWorld(int particle_id, vector global_pos)
Creates a particle emitter on the given position and activates it.
void SetSource(int particle_id)
Sets particle id.
override void PlayParticle(int particle_id=-1)
Method to tell the particle to start playing.
static Particle CreateOnObject(int particle_id, Object parent_obj, vector local_pos="0 0 0", vector local_ori="0 0 0", bool force_world_rotation=false)
Creates a particle emitter and attaches it on the given object.
float m_Lifetime
Approx. remaining lifetime of particle.
Object m_ParentObject
Parent Object the Particle is child of.
int m_ParticleID
ID from ParticleList if assigned.
bool IsRepeat()
Returns whether there is a repeating particle.
void UpdateState()
Creates/Destroys ParticleEffect child according to current state.
void Stop()
Legacy function for backwards compatibility with 1.14 and below.
Object GetDirectParticleEffect()
Returns direct particle effect entity which is usually handled by this class 'Particle' if there is o...
proto void SetParticleParm(notnull IEntity ent, int emitor, EmitorParam parameter, void value)
proto void GetParticleParmOriginal(notnull IEntity ent, int emitor, EmitorParam parameter, out void value)
proto int GetParticleEmitors(notnull IEntity ent, out string emitors[], int max)
proto void GetParticleParm(notnull IEntity ent, int emitor, EmitorParam parameter, out void value)