fix: the ParticleSystem's localPosition drifts at certain scales due to floating-point precision issues

close #299, close #312
pull/318/head
mob-sakai 2024-05-24 17:36:35 +09:00
parent 19989cf18c
commit e924eb4596
1 changed files with 4 additions and 1 deletions

View File

@ -632,6 +632,8 @@ namespace Coffee.UIExtensions
// get world position. // get world position.
var isLocalSpace = _particleSystem.IsLocalSpace(); var isLocalSpace = _particleSystem.IsLocalSpace();
var psTransform = _particleSystem.transform; var psTransform = _particleSystem.transform;
var originLocalPosition = psTransform.localPosition;
var originLocalRotation = psTransform.localRotation;
var originWorldPosition = psTransform.position; var originWorldPosition = psTransform.position;
var originWorldRotation = psTransform.rotation; var originWorldRotation = psTransform.rotation;
var emission = _particleSystem.emission; var emission = _particleSystem.emission;
@ -654,7 +656,8 @@ namespace Coffee.UIExtensions
: originWorldPosition.GetScaled(scale.Inverse()); : originWorldPosition.GetScaled(scale.Inverse());
psTransform.SetPositionAndRotation(scaledPos, originWorldRotation); psTransform.SetPositionAndRotation(scaledPos, originWorldRotation);
_particleSystem.Simulate(deltaTime, false, false, false); _particleSystem.Simulate(deltaTime, false, false, false);
psTransform.SetPositionAndRotation(originWorldPosition, originWorldRotation); psTransform.localPosition = originLocalPosition;
psTransform.localRotation = originLocalRotation;
} }
#if UNITY_EDITOR #if UNITY_EDITOR