Add SpawnParticles utility to Particle Effect
This commit is contained in:
@@ -505,7 +505,8 @@ void ParticleEmitterGraphCPUExecutor::Update(ParticleEmitter* emitter, ParticleE
|
||||
}
|
||||
|
||||
// Spawn particles
|
||||
int32 spawnCount = 0;
|
||||
int32 spawnCount = data.CustomSpawnCount;
|
||||
data.CustomSpawnCount = 0;
|
||||
if (canSpawn)
|
||||
{
|
||||
PROFILE_CPU_NAMED("Spawn");
|
||||
@@ -573,7 +574,8 @@ int32 ParticleEmitterGraphCPUExecutor::UpdateSpawn(ParticleEmitter* emitter, Par
|
||||
Init(emitter, effect, data, dt);
|
||||
|
||||
// Spawn particles
|
||||
int32 spawnCount = 0;
|
||||
int32 spawnCount = data.CustomSpawnCount;
|
||||
data.CustomSpawnCount = 0;
|
||||
for (int32 i = 0; i < _graph.SpawnModules.Count(); i++)
|
||||
{
|
||||
spawnCount += ProcessSpawnModule(i);
|
||||
|
||||
@@ -281,6 +281,34 @@ void ParticleEffect::UpdateSimulation(bool singleFrame)
|
||||
Particles::UpdateEffect(this);
|
||||
}
|
||||
|
||||
void ParticleEffect::SpawnParticles(int32 count, const StringView& emitterTrackName)
|
||||
{
|
||||
auto system = ParticleSystem.Get();
|
||||
if (!system)
|
||||
return;
|
||||
if (emitterTrackName.IsEmpty())
|
||||
{
|
||||
for (auto& e : Instance.Emitters)
|
||||
e.CustomSpawnCount += count;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int32 i = 0; i < system->Tracks.Count(); i++)
|
||||
{
|
||||
auto& track = system->Tracks[i];
|
||||
if (track.Type == ParticleSystem::Track::Types::Emitter && track.Name == emitterTrackName)
|
||||
{
|
||||
const int32 emitterIndex = track.AsEmitter.Index;
|
||||
if (Instance.Emitters.IsValidIndex(emitterIndex))
|
||||
{
|
||||
Instance.Emitters.Get()[emitterIndex].CustomSpawnCount += count;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleEffect::Play()
|
||||
{
|
||||
_isPlaying = true;
|
||||
|
||||
@@ -350,6 +350,13 @@ public:
|
||||
/// <param name="singleFrame">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.</param>
|
||||
API_FUNCTION() void UpdateSimulation(bool singleFrame = false);
|
||||
|
||||
/// <summary>
|
||||
/// Manually spawns additional particles into the simulation.
|
||||
/// </summary>
|
||||
/// <param name="count">Amount of particles to spawn.</param>
|
||||
/// <param name="emitterTrackName">Name of the emitter track to spawn particles in. Empty if spawn particles into all tracks.</param>
|
||||
API_FUNCTION() void SpawnParticles(int32 count, const StringView& emitterTrackName = String::Empty);
|
||||
|
||||
/// <summary>
|
||||
/// Plays the simulation.
|
||||
/// </summary>
|
||||
|
||||
@@ -26,6 +26,7 @@ void ParticleEmitterInstance::ClearState()
|
||||
Time = 0;
|
||||
SpawnModulesData.Clear();
|
||||
CustomData.Clear();
|
||||
CustomSpawnCount = 0;
|
||||
#if COMPILE_WITH_GPU_PARTICLES
|
||||
GPU.DeltaTime = 0.0f;
|
||||
GPU.SpawnCount = 0;
|
||||
|
||||
@@ -84,6 +84,11 @@ public:
|
||||
/// </summary>
|
||||
Array<byte> CustomData;
|
||||
|
||||
/// <summary>
|
||||
/// The external amount of the particles to spawn.
|
||||
/// </summary>
|
||||
int32 CustomSpawnCount = 0;
|
||||
|
||||
struct
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user