Skip to content

ParticleSystem Extensions

Andrzej Kebab edited this page Feb 4, 2024 · 4 revisions

UtilityLibrary.Unity.Runtime

This utility library, part of the ParticleSystemExtensions namespace, provides extension methods for Unity's ParticleSystem class, offering additional functionality for obtaining information about the particle system.

GetDuration

Gets the duration of the particle system. If allowLoop is set to false and the particle system is looping, it returns -1.

// Example usage
ParticleSystem myParticleSystem = /* Instantiate or reference a ParticleSystem */;
float duration = myParticleSystem.GetDuration();
Debug.Log($"Duration of the ParticleSystem: {duration} seconds");

Parameters:

  • particle (ParticleSystem): The particle system to get the duration from.
  • allowLoop (bool): Whether to allow looping. Default is false.

Returns:

  • float: The duration of the particle system. If allowLoop is false and the particle system is looping, returns -1.

SetActiveEmission

Enables or disables the emission of particles in a ParticleSystem.

ParticleSystem myParticleSystem = GetComponent<ParticleSystem>();
myParticleSystem.SetActiveEmission(true);

Parameters:

  • particleSystem: The ParticleSystem instance to enable or disable emission.
  • enabled: true to enable emission, false to disable.

This method is an extension for the Unity ParticleSystem class in the Unity.Runtime namespace. It allows you to easily enable or disable the emission of particles in a given ParticleSystem.

Example:

ParticleSystem myParticleSystem = GetComponent<ParticleSystem>();
myParticleSystem.SetActiveEmission(true);

Emission Rate

GetEmissionRate

Gets the constant maximum emission rate of particles in a ParticleSystem.

ParticleSystem myParticleSystem = GetComponent<ParticleSystem>();
float currentEmissionRate = myParticleSystem.GetEmissionRate();

Parameters:

  • particleSystem: The ParticleSystem instance to get the emission rate from.

Returns:

  • float: The constant maximum emission rate of particles.

SetEmissionRate

Sets the constant maximum emission rate of particles in a ParticleSystem.

ParticleSystem myParticleSystem = GetComponent<ParticleSystem>();
myParticleSystem.SetEmissionRate(20.0f);

Parameters:

  • particleSystem: The ParticleSystem instance to set the emission rate.
  • emissionRate: The new constant maximum emission rate of particles.

Clone this wiki locally