Skip to content

Commit

Permalink
feat: add particle system getter and setter for attractor
Browse files Browse the repository at this point in the history
close #253
  • Loading branch information
AndreevWezom authored and mob-sakai committed Aug 15, 2023
1 parent a499f0c commit a4bcf93
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions Scripts/UIParticleAttractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,25 @@ public Movement movement
}
}

private UIParticle _uiParticle;

private void OnEnable()
public ParticleSystem particleSystem
{
if (m_ParticleSystem == null)
get
{
Debug.LogError("No particle system attached to particle attractor script", this);
enabled = false;
return;
return m_ParticleSystem;
}

_uiParticle = m_ParticleSystem.GetComponentInParent<UIParticle>();
if (_uiParticle && !_uiParticle.particles.Contains(m_ParticleSystem))
set
{
_uiParticle = null;
m_ParticleSystem = value;
if (!ApplyParticleSystem()) return;
enabled = true;
}
}

private UIParticle _uiParticle;

private void OnEnable()
{
if (!ApplyParticleSystem()) return;
UIParticleUpdater.Register(this);
}

Expand Down Expand Up @@ -200,5 +203,22 @@ private Vector3 GetAttractedPosition(Vector3 current, Vector3 target, float dura
return Vector3.MoveTowards(current, target, speed);
}

private bool ApplyParticleSystem()
{
if (m_ParticleSystem == null)
{
Debug.LogError("No particle system attached to particle attractor script", this);
enabled = false;
return false;
}

_uiParticle = m_ParticleSystem.GetComponentInParent<UIParticle>();
if (_uiParticle && !_uiParticle.particles.Contains(m_ParticleSystem))
{
_uiParticle = null;
}

return true;
}
}
}

0 comments on commit a4bcf93

Please sign in to comment.