Skip to content

Commit

Permalink
fix: excessive particle emitted on move ParticleSystem for local spac…
Browse files Browse the repository at this point in the history
…e simulation and emission over distance

close #265
  • Loading branch information
mob-sakai committed Aug 17, 2023
1 parent 458224e commit 67bac3b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Scripts/UIParticleRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,23 +580,28 @@ private void Simulate(Vector3 scale, bool paused)
*/

// get world position.
var isLocalSpace = _particleSystem.IsLocalSpace();
var psTransform = _particleSystem.transform;
var originWorldPosition = psTransform.position;
var originWorldRotation = psTransform.rotation;
var emission = _particleSystem.emission;
var rateOverDistance = emission.enabled
&& 0 < emission.rateOverDistance.constant
&& 0 < emission.rateOverDistanceMultiplier;
if (rateOverDistance)
if (rateOverDistance && !paused)
{
// (For rate-over-distance emission,) Move to previous scaled position, simulate (delta = 0).
var prevScaledPos = _prevPsPos.GetScaled(_prevScale.Inverse());
var prevScaledPos = isLocalSpace
? _prevPsPos
: _prevPsPos.GetScaled(_prevScale.Inverse());
psTransform.SetPositionAndRotation(prevScaledPos, originWorldRotation);
_particleSystem.Simulate(0, false, false, false);
}

// Move to scaled position, simulate, revert to origin position.
var scaledPos = originWorldPosition.GetScaled(scale.Inverse());
var scaledPos = isLocalSpace
? originWorldPosition
: originWorldPosition.GetScaled(scale.Inverse());
psTransform.SetPositionAndRotation(scaledPos, originWorldRotation);
_particleSystem.Simulate(deltaTime, false, false, false);
psTransform.SetPositionAndRotation(originWorldPosition, originWorldRotation);
Expand Down

0 comments on commit 67bac3b

Please sign in to comment.