From 2fe0bde422f9769dfedaf6b053ea07f773646679 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 3c260a2..043cee5 100644 --- a/Scripts/UIParticleRenderer.cs +++ b/Scripts/UIParticleRenderer.cs @@ -583,6 +583,7 @@ namespace Coffee.UIExtensions */ // get world position. + var isLocalSpace = _particleSystem.IsLocalSpace(); var psTransform = _particleSystem.transform; var originWorldPosition = psTransform.position; var originWorldRotation = psTransform.rotation; @@ -590,16 +591,20 @@ namespace Coffee.UIExtensions 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);