feat: reset previous position on start play for world space simulation

close #303
pull/336/head
mob-sakai 2024-06-18 20:10:33 +09:00
parent cc3e95d8c7
commit 3619b4ff94
1 changed files with 5 additions and 2 deletions

View File

@ -39,6 +39,7 @@ namespace Coffee.UIExtensions
private float _prevCanvasScale;
private Vector3 _prevPsPos;
private Vector3 _prevScale;
private bool _isPrevStored;
private Vector2Int _prevScreenSize;
private bool _prewarm;
private ParticleSystemRenderer _renderer;
@ -146,6 +147,7 @@ namespace Coffee.UIExtensions
ModifiedMaterial.Remove(_modifiedMaterial);
_modifiedMaterial = null;
_currentMaterialForRendering = null;
_isPrevStored = false;
}
public static UIParticleRenderer AddRenderer(UIParticle parent, int index)
@ -581,7 +583,7 @@ namespace Coffee.UIExtensions
var isWorldSpace = _particleSystem.IsWorldSpace();
var canvasScale = _parent.canvas ? _parent.canvas.scaleFactor : 1f;
var resolutionChanged = _prevScreenSize != screenSize || _prevCanvasScale != canvasScale;
if (resolutionChanged && isWorldSpace)
if (resolutionChanged && isWorldSpace && _isPrevStored)
{
// Update particle array size and get particles.
var size = _particleSystem.particleCount;
@ -607,6 +609,7 @@ namespace Coffee.UIExtensions
_delay = true;
_prevScale = scale;
_prevPsPos = psPos;
_isPrevStored = true;
}
_prevCanvasScale = canvas ? canvas.scaleFactor : 1f;
@ -640,7 +643,7 @@ namespace Coffee.UIExtensions
var rateOverDistance = emission.enabled
&& 0 < emission.rateOverDistance.constant
&& 0 < emission.rateOverDistanceMultiplier;
if (rateOverDistance && !paused)
if (rateOverDistance && !paused && _isPrevStored)
{
// (For rate-over-distance emission,) Move to previous scaled position, simulate (delta = 0).
var prevScaledPos = isLocalSpace