fix: excessive particle emitted on move ParticleSystem for local space simulation and emission over distance

close #265
pull/289/head
mob-sakai 2023-08-17 11:56:46 +09:00
parent c2119c171a
commit 2fe0bde422
1 changed files with 8 additions and 3 deletions

View File

@ -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);