From 67bac3b50df9f244e789bb42457231fdae1f8193 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Thu, 17 Aug 2023 11:56:46 +0900 Subject: [PATCH] fix: excessive particle emitted on move ParticleSystem for local space simulation and emission over distance close #265 --- Scripts/UIParticleRenderer.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Scripts/UIParticleRenderer.cs b/Scripts/UIParticleRenderer.cs index 360aacb9..06f3c24d 100644 --- a/Scripts/UIParticleRenderer.cs +++ b/Scripts/UIParticleRenderer.cs @@ -580,6 +580,7 @@ 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; @@ -587,16 +588,20 @@ private void Simulate(Vector3 scale, bool paused) 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);