Skip to content

Commit

Permalink
fix: UIParticleAttractor attracts the particles at wrong position whe…
Browse files Browse the repository at this point in the history
…n in RelativeMode

close #262
  • Loading branch information
mob-sakai committed Aug 15, 2023
1 parent 65770ca commit 174af4b
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions Scripts/UIParticleAttractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,29 +169,32 @@ private Vector3 GetDestinationPosition()
var psPos = m_ParticleSystem.transform.position;
var attractorPos = transform.position;
var dstPos = attractorPos;
if (m_ParticleSystem.main.simulationSpace == ParticleSystemSimulationSpace.Local)
var isLocalSpace = m_ParticleSystem.main.simulationSpace == ParticleSystemSimulationSpace.Local;

if (isLocalSpace)
{
dstPos = m_ParticleSystem.transform.InverseTransformPoint(dstPos);
if (isUI)
{
dstPos = dstPos.GetScaled(_uiParticle.transform.localScale, _uiParticle.scale3D.Inverse());
}
}
else

if (isUI)
{
#if UNITY_EDITOR
if (!Application.isPlaying && isUI)
dstPos = dstPos.GetScaled(_uiParticle.transform.localScale, _uiParticle.scale3D.Inverse());

// Relative mode
if (!_uiParticle.absoluteMode)
{
var diff = dstPos - psPos;
diff = diff.GetScaled(_uiParticle.transform.localScale, _uiParticle.scale3D.Inverse());
return psPos + diff;
var diff = _uiParticle.transform.position - psPos;
diff.Scale(_uiParticle.scale3D - _uiParticle.transform.localScale);
diff.Scale(_uiParticle.scale3D.Inverse());
dstPos += diff;
}
#endif
if (isUI)

#if UNITY_EDITOR
if (!Application.isPlaying && !isLocalSpace)
{
dstPos.Scale(_uiParticle.transform.localScale);
dstPos.Scale(_uiParticle.scale3D.Inverse());
dstPos += psPos - psPos.GetScaled(_uiParticle.transform.localScale, _uiParticle.scale3D.Inverse());
}
#endif
}
return dstPos;
}
Expand Down

0 comments on commit 174af4b

Please sign in to comment.